From 92b1664e4b341661ab4257aff09198812a1b1f00 Mon Sep 17 00:00:00 2001 From: Muslimjon Date: Thu, 15 Feb 2024 21:30:04 +0100 Subject: [PATCH] feat(RHINENG): limit -1 is removed from table row selection --- config/dev.webpack.config.js | 2 +- src/SmartComponents/Advisories/Advisories.js | 3 +- .../AdvisorySystems/AdvisorySystems.js | 3 +- .../PackageSystems/PackageSystems.js | 3 +- src/SmartComponents/PatchSet/PatchSet.js | 3 +- .../SystemPackages/SystemPackages.js | 3 +- .../Systems/SystemPage.test.js | 2 +- .../Systems/SystemsListAssets.js | 2 +- .../Systems/SystemsMainContent.js | 6 +++- src/Utilities/hooks/useOnSelect.js | 28 ++++++++++++------- 10 files changed, 36 insertions(+), 19 deletions(-) diff --git a/config/dev.webpack.config.js b/config/dev.webpack.config.js index 2b455152..2bcb07e2 100644 --- a/config/dev.webpack.config.js +++ b/config/dev.webpack.config.js @@ -7,7 +7,7 @@ const proxyConfiguration = { useProxy: process.env.PROXY === 'true', appUrl: process.env.BETA ? ['/beta/insights/patch', '/preview/insights/patch'] : ['/insights/patch'], deployment: process.env.BETA ? 'beta/apps' : 'apps', - env: process.env.BETA ? 'stage-beta' : 'stage-stable', + env: process.env.BETA ? 'prod-beta' : 'prod-stable', proxyVerbose: true, debug: true }; diff --git a/src/SmartComponents/Advisories/Advisories.js b/src/SmartComponents/Advisories/Advisories.js index 6d27e2de..6144d2fb 100644 --- a/src/SmartComponents/Advisories/Advisories.js +++ b/src/SmartComponents/Advisories/Advisories.js @@ -100,7 +100,8 @@ const Advisories = () => { { endpoint: ID_API_ENDPOINTS.advisories, queryParams, - selectionDispatcher: selectAdvisoryRow + selectionDispatcher: selectAdvisoryRow, + totalItems: metadata?.total_items } ); diff --git a/src/SmartComponents/AdvisorySystems/AdvisorySystems.js b/src/SmartComponents/AdvisorySystems/AdvisorySystems.js index 0052b406..95709551 100644 --- a/src/SmartComponents/AdvisorySystems/AdvisorySystems.js +++ b/src/SmartComponents/AdvisorySystems/AdvisorySystems.js @@ -102,7 +102,8 @@ const AdvisorySystems = ({ advisoryName }) => { { endpoint: ID_API_ENDPOINTS.advisorySystems(advisoryName), queryParams, - selectionDispatcher: systemSelectAction + selectionDispatcher: systemSelectAction, + totalItems } ); diff --git a/src/SmartComponents/PackageSystems/PackageSystems.js b/src/SmartComponents/PackageSystems/PackageSystems.js index 7c1a6b07..4ba3ac2b 100644 --- a/src/SmartComponents/PackageSystems/PackageSystems.js +++ b/src/SmartComponents/PackageSystems/PackageSystems.js @@ -100,7 +100,8 @@ const PackageSystems = ({ packageName }) => { queryParams, selectionDispatcher: systemSelectAction, constructFilename, - apiResponseTransformer: filterRemediatablePackageSystems + apiResponseTransformer: filterRemediatablePackageSystems, + totalItems } ); diff --git a/src/SmartComponents/PatchSet/PatchSet.js b/src/SmartComponents/PatchSet/PatchSet.js index d18ff445..2ce399f9 100644 --- a/src/SmartComponents/PatchSet/PatchSet.js +++ b/src/SmartComponents/PatchSet/PatchSet.js @@ -106,7 +106,8 @@ const PatchSet = () => { { endpoint: ID_API_ENDPOINTS.templates, queryParams, - selectionDispatcher: selectPatchSetRow + selectionDispatcher: selectPatchSetRow, + totalItems: metadata.total_items } ); diff --git a/src/SmartComponents/SystemPackages/SystemPackages.js b/src/SmartComponents/SystemPackages/SystemPackages.js index ef1f274d..511ffb7f 100644 --- a/src/SmartComponents/SystemPackages/SystemPackages.js +++ b/src/SmartComponents/SystemPackages/SystemPackages.js @@ -78,7 +78,8 @@ const SystemPackages = ({ handleNoSystemData, inventoryId, shouldRefresh }) => { queryParams, selectionDispatcher: selectSystemPackagesRow, constructFilename, - transformKey + transformKey, + totalItems: metadata?.total_items } ); diff --git a/src/SmartComponents/Systems/SystemPage.test.js b/src/SmartComponents/Systems/SystemPage.test.js index a8d17521..b350ba0e 100644 --- a/src/SmartComponents/Systems/SystemPage.test.js +++ b/src/SmartComponents/Systems/SystemPage.test.js @@ -271,7 +271,7 @@ describe('Systems.js', () => { bulkSelect.items[2].onClick(); - expect(fetchIDs).toHaveBeenCalledWith('/ids/systems', { limit: -1, offset: 0 }); + expect(fetchIDs).toHaveBeenCalledWith('/ids/systems', { limit: 100, offset: 0 }); expect(bulkSelect.items[2].title).toEqual('Select all (2)'); }); diff --git a/src/SmartComponents/Systems/SystemsListAssets.js b/src/SmartComponents/Systems/SystemsListAssets.js index cacb631c..413e9274 100644 --- a/src/SmartComponents/Systems/SystemsListAssets.js +++ b/src/SmartComponents/Systems/SystemsListAssets.js @@ -179,7 +179,7 @@ export const useActivateRemediationModal = (setRemediationIssues, setRemediation ); fetchBatched( - (__, pagination) => fetchApplicableSystemAdvisoriesApi({ ...filter, ...pagination }), + (filterWithPagination) => fetchApplicableSystemAdvisoriesApi(filterWithPagination), filter, totalCount ).then(response => { diff --git a/src/SmartComponents/Systems/SystemsMainContent.js b/src/SmartComponents/Systems/SystemsMainContent.js index 74214d1d..dac67ac8 100644 --- a/src/SmartComponents/Systems/SystemsMainContent.js +++ b/src/SmartComponents/Systems/SystemsMainContent.js @@ -58,7 +58,11 @@ const SystemsMainContent = () => { return ( - + {isRemediationOpen && { const { fetchBatched } = useFetchBatched(); - return useCallback((queryParams) => - fetchBatched( - (__, pagination) => fetchIDs(endpoint, { ...queryParams, ...pagination }), + return useCallback(async (queryParams) => { + const response = await fetchBatched( + (filter) => fetchIDs(endpoint, filter), + queryParams, totalItems, - queryParams - ) - .then(response => - apiResponseTransformer ? apiResponseTransformer(response) : response - ), + 100 + ); + + const aggregatedResponse = response.reduce((accumulator = {}, currentValue) => { + Object.keys(accumulator).forEach(key => { + accumulator[key] = accumulator[key].concat(currentValue[key]); + }); + + return accumulator; + }, { data: [], ids: [] }); + + return apiResponseTransformer ? apiResponseTransformer(aggregatedResponse) : aggregatedResponse; + }, [totalItems, endpoint]); }; const useCreateSelectedRow = (transformKey, constructFilename) => useCallback((rows, toSelect = []) => { const { ids, data } = rows; - const shouldUseOnlyIDs = Array.isArray(ids); + const shouldUseOnlyIDs = !data; const items = shouldUseOnlyIDs ? ids : data; items.forEach((item) => { @@ -86,7 +95,6 @@ const createSelectors = ( }; const selectAll = (fetchIDs, queryParams) => { - queryParams.offset = 0; return fetchIDs(queryParams).then(response => { if (Array.isArray(response.data)) { let rowsToSelect = response.data.filter(row => row.status !== 'Applicable');