Skip to content

Commit

Permalink
feat(RHINENG): limit -1 is removed from table row selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mkholjuraev committed Feb 16, 2024
1 parent 3f65144 commit 92b1664
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion config/dev.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
3 changes: 2 additions & 1 deletion src/SmartComponents/Advisories/Advisories.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const Advisories = () => {
{
endpoint: ID_API_ENDPOINTS.advisories,
queryParams,
selectionDispatcher: selectAdvisoryRow
selectionDispatcher: selectAdvisoryRow,
totalItems: metadata?.total_items
}
);

Expand Down
3 changes: 2 additions & 1 deletion src/SmartComponents/AdvisorySystems/AdvisorySystems.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ const AdvisorySystems = ({ advisoryName }) => {
{
endpoint: ID_API_ENDPOINTS.advisorySystems(advisoryName),
queryParams,
selectionDispatcher: systemSelectAction
selectionDispatcher: systemSelectAction,
totalItems
}
);

Expand Down
3 changes: 2 additions & 1 deletion src/SmartComponents/PackageSystems/PackageSystems.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const PackageSystems = ({ packageName }) => {
queryParams,
selectionDispatcher: systemSelectAction,
constructFilename,
apiResponseTransformer: filterRemediatablePackageSystems
apiResponseTransformer: filterRemediatablePackageSystems,
totalItems
}
);

Expand Down
3 changes: 2 additions & 1 deletion src/SmartComponents/PatchSet/PatchSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ const PatchSet = () => {
{
endpoint: ID_API_ENDPOINTS.templates,
queryParams,
selectionDispatcher: selectPatchSetRow
selectionDispatcher: selectPatchSetRow,
totalItems: metadata.total_items
}
);

Expand Down
3 changes: 2 additions & 1 deletion src/SmartComponents/SystemPackages/SystemPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const SystemPackages = ({ handleNoSystemData, inventoryId, shouldRefresh }) => {
queryParams,
selectionDispatcher: selectSystemPackagesRow,
constructFilename,
transformKey
transformKey,
totalItems: metadata?.total_items
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/SmartComponents/Systems/SystemPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
});

Expand Down
2 changes: 1 addition & 1 deletion src/SmartComponents/Systems/SystemsListAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const useActivateRemediationModal = (setRemediationIssues, setRemediation
);

fetchBatched(
(__, pagination) => fetchApplicableSystemAdvisoriesApi({ ...filter, ...pagination }),
(filterWithPagination) => fetchApplicableSystemAdvisoriesApi(filterWithPagination),
filter,
totalCount
).then(response => {
Expand Down
6 changes: 5 additions & 1 deletion src/SmartComponents/Systems/SystemsMainContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ const SystemsMainContent = () => {
return (
<React.Fragment>
<SystemsStatusReport apply={apply} queryParams={queryParams} />
<PatchSetWrapper patchSetState={patchSetState} setPatchSetState={setPatchSetState} />
<PatchSetWrapper
patchSetState={patchSetState}
setPatchSetState={setPatchSetState}
totalItems={metadata?.total_items}
/>
{isRemediationOpen &&
<RemediationWizard
data={remediationIssues}
Expand Down
28 changes: 18 additions & 10 deletions src/Utilities/hooks/useOnSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,31 @@ const useFetchAllIDs = (
totalItems
) => {
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) => {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 92b1664

Please sign in to comment.