From f928612d03ef45c10f2f878b2a80b2e9923d338c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Mon, 14 Oct 2024 14:59:23 +0200 Subject: [PATCH] Improve speed of national table when no filters --- .../details/tables/national-highseas/hooks.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/containers/map/content/details/tables/national-highseas/hooks.tsx b/frontend/src/containers/map/content/details/tables/national-highseas/hooks.tsx index 22513a87..ea42c422 100644 --- a/frontend/src/containers/map/content/details/tables/national-highseas/hooks.tsx +++ b/frontend/src/containers/map/content/details/tables/national-highseas/hooks.tsx @@ -584,6 +584,14 @@ export const useData = ( [environment, filters, locationCode] ); + const isFiltering = useMemo( + () => + Object.values(filters) + .filter(Boolean) + .some((value) => value.length > 0), + [filters] + ); + const processData = useCallback( (data: PaListResponse) => { return [ @@ -707,7 +715,9 @@ export const useData = ( 'pagination[pageSize]': pagination.pageSize, 'pagination[page]': pagination.pageIndex + 1, sort: querySort, - 'keep-if-children-match': true, + // This parameter makes sure Strapi retains the parent for which children match the filters + // but make the request slower, so it is only added when necessary + ...(isFiltering ? { 'keep-if-children-match': true } : {}), }, { query: {