diff --git a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListTable.tsx b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListTable.tsx index 366acaffa969..1c941afa06c3 100644 --- a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListTable.tsx +++ b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListTable.tsx @@ -86,14 +86,15 @@ const FeatureToggleListTableComponent: VFC = () => { 'features-list-table', stateConfig, ); - - const filterState = { - project: tableState.project, - tag: tableState.tag, - state: tableState.state, - segment: tableState.segment, - createdAt: tableState.createdAt, - }; + const { + offset, + limit, + query, + favoritesFirst, + sortBy, + sortOrder, + ...filterState + } = tableState; const { features = [], @@ -130,10 +131,10 @@ const FeatureToggleListTableComponent: VFC = () => { columnHelper.accessor('favorite', { header: () => ( setTableState({ - favoritesFirst: !tableState.favoritesFirst, + favoritesFirst: !favoritesFirst, }) } /> @@ -211,7 +212,7 @@ const FeatureToggleListTableComponent: VFC = () => { cell: ({ getValue }) => , }), ], - [tableState.favoritesFirst], + [favoritesFirst], ); const data = useMemo( @@ -270,9 +271,7 @@ const FeatureToggleListTableComponent: VFC = () => { @@ -298,7 +297,7 @@ const FeatureToggleListTableComponent: VFC = () => { condition={isSmallScreen} show={ @@ -311,7 +310,7 @@ const FeatureToggleListTableComponent: VFC = () => { onChange={setTableState} state={filterState} /> - + { show={ ({ padding: theme.spacing(0, 2, 2) })}> 0} + condition={(query || '')?.length > 0} show={ No feature toggles found matching “ - {tableState.query} + {query} ” } diff --git a/frontend/src/component/filter/Filters/Filters.test.tsx b/frontend/src/component/filter/Filters/Filters.test.tsx index e2e1eff23b3e..7c8f8d4ff2f4 100644 --- a/frontend/src/component/filter/Filters/Filters.test.tsx +++ b/frontend/src/component/filter/Filters/Filters.test.tsx @@ -1,7 +1,7 @@ import { screen } from '@testing-library/react'; import { render } from 'utils/testRenderer'; import { FILTER_ITEM } from 'utils/testIds'; -import { Filters, IFilterItem } from './Filters'; +import { FilterItemParamHolder, Filters, IFilterItem } from './Filters'; test('shoulder render all available filters', async () => { const availableFilters: IFilterItem[] = [ @@ -126,3 +126,51 @@ test('should remove selected item from the add filter list', async () => { addFilterButton.click(); expect(screen.getByRole('menu').textContent).toBe('Tags'); }); + +test('should render filters in the order defined by the initial state', async () => { + const initialState: FilterItemParamHolder = { + filterB: { operator: '', values: [] }, + filterA: { operator: '', values: [] }, + filterC: { operator: '', values: [] }, + }; + + const availableFilters: IFilterItem[] = [ + { + label: 'FilterA', + icon: '', + options: [], + filterKey: 'filterA', + singularOperators: ['IRRELEVANT'], + pluralOperators: ['IRRELEVANT'], + }, + { + label: 'FilterB', + icon: '', + options: [], + filterKey: 'filterB', + singularOperators: ['IRRELEVANT'], + pluralOperators: ['IRRELEVANT'], + }, + { + label: 'FilterC', + icon: '', + options: [], + filterKey: 'filterC', + singularOperators: ['IRRELEVANT'], + pluralOperators: ['IRRELEVANT'], + }, + ]; + + render( + {}} + state={initialState} + />, + ); + + const filterItems = screen.getAllByTestId(FILTER_ITEM); + const filterTexts = filterItems.map((item) => item.textContent); + + expect(filterTexts).toEqual(['FilterB', 'FilterA', 'FilterC']); +}); diff --git a/frontend/src/component/filter/Filters/Filters.tsx b/frontend/src/component/filter/Filters/Filters.tsx index 249a8c763ce0..e02c85934b61 100644 --- a/frontend/src/component/filter/Filters/Filters.tsx +++ b/frontend/src/component/filter/Filters/Filters.tsx @@ -90,9 +90,16 @@ export const Filters: VFC = ({ }; useEffect(() => { - const newSelectedFilters = availableFilters + const newSelectedFilters = Object.keys(state) + .map((filterKey) => + availableFilters.find( + (filter) => filterKey === filter.filterKey, + ), + ) + .filter((filter): filter is IFilterItem => Boolean(filter)) .filter((field) => Boolean(state[field.filterKey])) - .map((field) => field.label); + .map((filter) => filter.label); + const allSelectedFilters = mergeArraysKeepingOrder( selectedFilters, newSelectedFilters, diff --git a/frontend/src/hooks/usePersistentTableState.test.tsx b/frontend/src/hooks/usePersistentTableState.test.tsx index 16aac060adf2..e53f2409e476 100644 --- a/frontend/src/hooks/usePersistentTableState.test.tsx +++ b/frontend/src/hooks/usePersistentTableState.test.tsx @@ -27,6 +27,9 @@ function TestComponent({ keyName, queryParamsDefinition }: TestComponentProps) { {tableState.query} + + {Object.keys(tableState).join(',')} +