Skip to content

Commit

Permalink
ERM-3220 Update pagination mechanisms for MCLs to work without stats
Browse files Browse the repository at this point in the history
* rename hook
* set defaukt page
  • Loading branch information
CalamityC committed May 13, 2024
1 parent 550eb93 commit 48d4dbc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -49,4 +55,4 @@ const useFetchWithNoStats = ({
});
};

export default useFetchWithNoStats;
export default useFetchCurrentAndNext;

0 comments on commit 48d4dbc

Please sign in to comment.