1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: state now persist to filters (#5559)

When navigating to features list, now it will respect the query params.
This commit is contained in:
Jaanus Sellin 2023-12-06 14:17:49 +02:00 committed by GitHub
parent d9648de08d
commit eda4186a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 14 deletions

View File

@ -88,12 +88,12 @@ describe('FilterItem Component', () => {
const operatorsElement = await screen.findByText('is any of');
operatorsElement.click();
const newOperator = await screen.findByText('is not any of');
const newOperator = await screen.findByText('is none of');
newOperator.click();
expect(recordedChanges).toEqual([
{ operator: 'IS_NOT_ANY_OF', values: ['1', '3'] },
{ operator: 'IS_NONE_OF', values: ['1', '3'] },
]);
});

View File

@ -47,15 +47,8 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
value: 'stale',
},
];
const defaultFilterItems: IFilterItem[] = [
{
label: 'State',
options: stateOptions,
filterKey: 'state',
},
];
const [availableFilters, setAvailableFilters] =
useState<IFilterItem[]>(defaultFilterItems);
const [availableFilters, setAvailableFilters] = useState<IFilterItem[]>([]);
const removeFilter = (label: string) => {
const filters = availableFilters.map((filter) =>
filter.label === label
@ -74,17 +67,24 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
value: project.id,
}));
const newFilterItems = [
...defaultFilterItems,
const newFilterItems: IFilterItem[] = [
{
label: 'State',
options: stateOptions,
filterKey: 'state',
enabled: Boolean(state.state),
},
{
label: 'Project',
options: projectsOptions,
filterKey: 'project',
enabled: Boolean(state.project),
} as const,
];
setAvailableFilters(newFilterItems);
}, [JSON.stringify(projects)]);
}, [JSON.stringify(projects), JSON.stringify(state)]);
return (
<StyledBox>
{availableFilters.map(