Skip to content

Commit

Permalink
Add possibility to add and remove multiple categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilamb committed Apr 30, 2024
1 parent cdf19f7 commit 4d21afc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 1 addition & 4 deletions frontend/src/components/common/CRDCategoriesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TextField from '@mui/material/TextField';
import React from 'react';
import { useDispatch } from 'react-redux';
import CRD from '../../lib/k8s/crd';
import { removeCategoryFilter,setCategoryFilter } from '../../redux/filterSlice'; // Import the action to set the category filter
import { removeCategoryFilter, setCategoryFilter } from '../../redux/filterSlice'; // Import the action to set the category filter
import { useTypedSelector } from '../../redux/reducers/reducers'; // Import the hook to access the Redux store's state

// Define CRDCategoriesList component
Expand Down Expand Up @@ -57,9 +57,6 @@ export function CRDCategoriesList() {
options={categories}
isOptionEqualToValue={(option, value) => value.includes(option)}
getOptionLabel={option => option.toString()}
/*
isOptionEqualToValue={filter.categories.some(shit => filteredCategories.includes(shit))}
*/
renderOption={(props, option, { selected }) => (
<li {...props}>
<Checkbox checked={selected} />
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/components/common/SectionFilterHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import SectionHeader, { SectionHeaderProps } from './SectionHeader';

export interface SectionFilterHeaderProps extends SectionHeaderProps {
noNamespaceFilter?: boolean;
noCategoriesFilter?: boolean;
noSearch?: boolean;
preRenderFromFilterActions?: React.ReactNode[];
}

export default function SectionFilterHeader(props: SectionFilterHeaderProps) {
const {
noNamespaceFilter = false,
noCategoriesFilter = true,
noSearch = false,
actions: propsActions = [],
preRenderFromFilterActions,
Expand All @@ -35,6 +37,7 @@ export default function SectionFilterHeader(props: SectionFilterHeaderProps) {
const location = useLocation();
const history = useHistory();
const hasNamespaceFilters = !noNamespaceFilter && filter.namespaces.size > 0;
const hasCategoriesFilters = !noCategoriesFilter && filter.categories.length > 0;
const hasSearch = !noSearch && !!filter.search;
const { t } = useTranslation();

Expand All @@ -48,7 +51,7 @@ export default function SectionFilterHeader(props: SectionFilterHeaderProps) {
// To solve this, we keep track of whether the filter has been shown by the user, in which case we
// don't hide it even when the search is empty.
const [showFilters, setShowFilters] = React.useState<{ show: boolean; userTriggered: boolean }>({
show: hasNamespaceFilters || hasSearch,
show: hasNamespaceFilters || hasSearch || hasCategoriesFilters,
userTriggered: false,
});

Expand Down Expand Up @@ -130,9 +133,12 @@ export default function SectionFilterHeader(props: SectionFilterHeaderProps) {
<NamespacesAutocomplete />
</Grid>
)}
<Grid item>
<CRDCategoriesList />
</Grid>
{!noCategoriesFilter && (
<Grid item>
<CRDCategoriesList />
</Grid>
)}

<Grid item>
<TextField
id="standard-search"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/crd/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default function CustomResourceDefinitionList() {
<ResourceListView
title={t('glossary|Custom Resources')}
headerProps={{
noNamespaceFilter: false,
noNamespaceFilter: true,
noCategoriesFilter: false,
}}
resourceClass={CRD}
columns={[
Expand Down

0 comments on commit 4d21afc

Please sign in to comment.