From 55f9180cb8e67c2cdc134808db338622daa277aa Mon Sep 17 00:00:00 2001 From: daniele-mng Date: Wed, 20 Nov 2024 11:09:45 +0100 Subject: [PATCH] Remove: revert "fix: filtering error on first render for create display" This reverts commit 304fa57adcf2f156cbeee475871b58083ec24e3e. --- src/web/hooks/__tests__/usePageFilter.jsx | 8 ++--- src/web/hooks/usePageFilter.js | 39 +++++++---------------- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/web/hooks/__tests__/usePageFilter.jsx b/src/web/hooks/__tests__/usePageFilter.jsx index 58c380d783..3f817ec015 100644 --- a/src/web/hooks/__tests__/usePageFilter.jsx +++ b/src/web/hooks/__tests__/usePageFilter.jsx @@ -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'); diff --git a/src/web/hooks/usePageFilter.js b/src/web/hooks/usePageFilter.js index c04f870c0c..f38fd2d689 100644 --- a/src/web/hooks/usePageFilter.js +++ b/src/web/hooks/usePageFilter.js @@ -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'; @@ -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'); @@ -92,8 +90,6 @@ const usePageFilter = ( : undefined, ); - const [initialFilterSet, setInitialFilterSet] = useState(false); - useEffect(() => { if ( !isDefined(defaultSettingFilter) && @@ -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) ||