mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-18 21:55:12 -04:00
5cffb10e08
* If no categories are passed in, flag up a unknown error * Pass back in default props to deal with undefined issues
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
import PropTypes from 'prop-types';
|
|
import React from 'react';
|
|
import Label from 'Components/Label';
|
|
import { kinds, tooltipPositions } from 'Helpers/Props';
|
|
import Tooltip from '../../Components/Tooltip/Tooltip';
|
|
|
|
function CategoryLabel({ categories }) {
|
|
const sortedCategories = categories.filter((cat) => cat.name !== undefined).sort((c) => c.id);
|
|
|
|
if (categories?.length === 0) {
|
|
return (
|
|
<Tooltip
|
|
anchor={<Label kind={kinds.DANGER}>Unknown</Label>}
|
|
tooltip="Please report this issue to the GitHub as this shouldn't be happening"
|
|
position={tooltipPositions.LEFT}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<span>
|
|
{
|
|
sortedCategories.map((category) => {
|
|
return (
|
|
<Label key={category.name}>
|
|
{category.name}
|
|
</Label>
|
|
);
|
|
})
|
|
}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
CategoryLabel.defaultProps = {
|
|
categories: []
|
|
};
|
|
|
|
CategoryLabel.propTypes = {
|
|
categories: PropTypes.arrayOf(PropTypes.object).isRequired
|
|
};
|
|
|
|
export default CategoryLabel;
|