From 48d4dbca6946214314e067b252041350ccd1f8be Mon Sep 17 00:00:00 2001 From: Claudia Malzer Date: Mon, 13 May 2024 16:35:57 +0200 Subject: [PATCH] ERM-3220 Update pagination mechanisms for MCLs to work without stats * rename hook * set defaukt page --- lib/hooks/index.js | 2 +- ...thNoStats.js => useFetchCurrentAndNext.js} | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) rename lib/hooks/{useFetchWithNoStats.js => useFetchCurrentAndNext.js} (66%) diff --git a/lib/hooks/index.js b/lib/hooks/index.js index 2795a6d2..8a18117f 100644 --- a/lib/hooks/index.js +++ b/lib/hooks/index.js @@ -11,7 +11,7 @@ export { default as useInterfaceCredentials } from './useInterfaceCredentials'; export { default as useSingleFetchInterfaceCredentials } from './useSingleFetchInterfaceCredentials'; export { default as useChunkedCQLFetch } from './useChunkedCQLFetch'; export { default as useChunkedUsers } from './useChunkedUsers'; -export { default as useFetchWithNoStats } from './useFetchWithNoStats'; +export { default as useFetchCurrentAndNext } from './useFetchCurrentAndNext'; export { default as useParallelBatchFetch } from './useParallelBatchFetch'; export { default as usePrevNextPagination } from './usePrevNextPagination'; export { default as usePrevious } from './usePrevious'; diff --git a/lib/hooks/useFetchWithNoStats.js b/lib/hooks/useFetchCurrentAndNext.js similarity index 66% rename from lib/hooks/useFetchWithNoStats.js rename to lib/hooks/useFetchCurrentAndNext.js index 90c2278a..5e6ac913 100644 --- a/lib/hooks/useFetchWithNoStats.js +++ b/lib/hooks/useFetchCurrentAndNext.js @@ -3,20 +3,26 @@ import { useQueries } from 'react-query'; import { useOkapiKy } from '@folio/stripes/core'; import { generateKiwtQueryParams } from '@k-int/stripes-kint-components'; -const useFetchWithNoStats = ({ - id, // for future use / local zustand store - params, // Need an initial value for page as to not cause issues when generating params +const defaultParams = { page: 1 }; + +const useFetchCurrentAndNext = ({ + // id, // for future use / local zustand store + params = {}, path = '', keyArray = [], } = {}) => { const ky = useOkapiKy(); const queryArray = []; + + // Apply defaultParams ensuring that 'page' is defaulted properly + const effectiveParams = useMemo(() => ({ ...defaultParams, ...params }), [params]); + const currentPageParams = useMemo(() => ( generateKiwtQueryParams( - { ...params, stats: false }, + { ...effectiveParams }, {} ) - ), [params]); + ), [effectiveParams]); queryArray.push({ queryKey: [ path, @@ -28,10 +34,10 @@ const useFetchWithNoStats = ({ const nextPageParams = useMemo(() => ( generateKiwtQueryParams( - { ...params, page: params.page + 1, stats: false }, + { ...effectiveParams, page: effectiveParams.page + 1 }, {} ) - ), [params]); + ), [effectiveParams]); queryArray.push({ queryKey: [ path, @@ -49,4 +55,4 @@ const useFetchWithNoStats = ({ }); }; -export default useFetchWithNoStats; +export default useFetchCurrentAndNext;