Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Tailorings): RHINENG-14520 - Fix export for wizard #2314

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const withExport = ({
downloadItems(exportColumns, items, format);
onComplete?.(items);
} catch (error) {
console.error(error);
onError?.(error);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ const TailoringTab = ({
)
: undefined;

// TODO The wrapping of the fetches in an array is odd.
// Figure out why this is and how we can avoid it
const exporter = async () =>
(tailoring && policy
? await fetchBatchedTailoringRules()
: await fetchBatchedRules()
? [await fetchBatchedTailoringRules()]
: [await fetchBatchedRules()]
).flatMap((result) => result.data);

const itemIdsInTable = async () =>
Expand Down
13 changes: 9 additions & 4 deletions src/Utilities/hooks/useFetchTotalBatched.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ const useFetchTotalBatched = (fetchFn, options = {}) => {
const [totalResult, setTotalResult] = useState();

const fetch = useCallback(
async (params = {}) => {
async (fetchParams = {}) => {
const allParams = {
...params,
...fetchParams,
};

if (!loading.current) {
loading.current = true;
const firstPage = await fetchFn(0, batchSize, params);
const firstPage = await fetchFn(0, batchSize, allParams);
const total = firstPage?.meta?.total;

if (total > batchSize) {
Expand All @@ -30,7 +35,7 @@ const useFetchTotalBatched = (fetchFn, options = {}) => {
const page = pageIdx;
if (page >= 1) {
const offset = page * batchSize;
return await fetchFn(offset, batchSize, params);
return await fetchFn(offset, batchSize, allParams);
}
}
);
Expand Down Expand Up @@ -60,7 +65,7 @@ const useFetchTotalBatched = (fetchFn, options = {}) => {
}
}
},
[typeof fetchFn !== 'undefined', batchSize]
[typeof fetchFn !== 'undefined', batchSize, JSON.stringify(params)]
);

useDeepCompareEffectNoCheck(() => {
Expand Down