From 5cffb10e08d27e7cf73edb277ee071531e6ddf04 Mon Sep 17 00:00:00 2001 From: Lagicrus Date: Mon, 5 Jul 2021 13:42:51 +0100 Subject: [PATCH] Fixed: If no categories are passed in, flag up a unknown error (#311) * If no categories are passed in, flag up a unknown error * Pass back in default props to deal with undefined issues --- frontend/src/Search/Table/CategoryLabel.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/frontend/src/Search/Table/CategoryLabel.js b/frontend/src/Search/Table/CategoryLabel.js index 92e7f4e95..80ca3a61d 100644 --- a/frontend/src/Search/Table/CategoryLabel.js +++ b/frontend/src/Search/Table/CategoryLabel.js @@ -1,10 +1,22 @@ 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 = [] }) { +function CategoryLabel({ categories }) { const sortedCategories = categories.filter((cat) => cat.name !== undefined).sort((c) => c.id); + if (categories?.length === 0) { + return ( + Unknown} + tooltip="Please report this issue to the GitHub as this shouldn't be happening" + position={tooltipPositions.LEFT} + /> + ); + } + return ( { @@ -20,8 +32,12 @@ function CategoryLabel({ categories = [] }) { ); } +CategoryLabel.defaultProps = { + categories: [] +}; + CategoryLabel.propTypes = { - categories: PropTypes.arrayOf(PropTypes.object) + categories: PropTypes.arrayOf(PropTypes.object).isRequired }; export default CategoryLabel;