Skip to content

Commit

Permalink
Remove: "fix: filtering error on first render for create display"
Browse files Browse the repository at this point in the history
This reverts commit 304fa57.
  • Loading branch information
daniele-mng committed Nov 20, 2024
1 parent 72f6060 commit 135ae3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 33 deletions.
8 changes: 3 additions & 5 deletions src/web/hooks/__tests__/usePageFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ describe('usePageFilter tests', () => {
}),
);

const expectedFilter = Filter.fromString('location=query rows=42');

await waitFor(() => {
expect(result.current[0].toString()).toEqual(expectedFilter.toString());
});
expect(result.current[0]).toEqual(
Filter.fromString('location=query rows=42'),
);
});
test('should prefer pageFilter over defaultSettingFilter', async () => {
const pFilter = Filter.fromString('page=filter');
Expand Down
39 changes: 11 additions & 28 deletions src/web/hooks/usePageFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import {useCallback, useEffect, useState, useRef} from 'react';
import {useCallback, useEffect, useState} from 'react';

import {useSearchParams} from 'react-router-dom';

Expand Down Expand Up @@ -79,9 +79,7 @@ const usePageFilter = (
);

// use null as value for not set at all
const returnedFilterRef = useRef(null);

let returnedFilter = returnedFilterRef.current;
let returnedFilter;
// only use searchParams directly if locationQueryFilterString is undefined
const locationQueryFilterString =
initialLocationQueryFilterString || searchParams.get('filter');
Expand All @@ -92,8 +90,6 @@ const usePageFilter = (
: undefined,
);

const [initialFilterSet, setInitialFilterSet] = useState(false);

useEffect(() => {
if (
!isDefined(defaultSettingFilter) &&
Expand Down Expand Up @@ -124,43 +120,30 @@ const usePageFilter = (
setLocationQueryFilter(undefined);
}, []); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (!initialFilterSet && isDefined(rowsPerPage)) {
setInitialFilterSet(true);
if (!returnedFilterRef.current.has('rows')) {
returnedFilterRef.current = returnedFilterRef.current.set(
'rows',
rowsPerPage,
);
}
}
}, [initialFilterSet, rowsPerPage]);

if (hasValue(locationQueryFilter)) {
if (!locationQueryFilter.has('rows') && isDefined(rowsPerPage)) {
locationQueryFilter.set('rows', rowsPerPage);
}
returnedFilterRef.current = locationQueryFilter;
returnedFilter = locationQueryFilter;
} else if (isDefined(pageFilter)) {
returnedFilterRef.current = pageFilter;
returnedFilter = pageFilter;
} else if (
isDefined(defaultSettingFilter) &&
!isDefined(defaultSettingsFilterError) &&
defaultSettingFilter !== null
) {
returnedFilterRef.current = defaultSettingFilter;
returnedFilter = defaultSettingFilter;
} else if (isDefined(fallbackFilter)) {
returnedFilterRef.current = fallbackFilter;
returnedFilter = fallbackFilter;
} else {
returnedFilterRef.current = DEFAULT_FALLBACK_FILTER;
returnedFilter = DEFAULT_FALLBACK_FILTER;
}

returnedFilter = returnedFilterRef.current;

if (!isDefined(rowsPerPage) && isDefined(rowsPerPageError)) {
rowsPerPage = DEFAULT_ROWS_PER_PAGE;
}

if (!returnedFilter.has('rows') && isDefined(rowsPerPage)) {
returnedFilter = returnedFilter.set('rows', rowsPerPage);
}

const finishedLoading =
isDefined(returnedFilter) &&
(isDefined(defaultSettingFilter) ||
Expand Down

0 comments on commit 135ae3e

Please sign in to comment.