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 15, 2024
1 parent 3f65144 commit eef6939
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 22 deletions.
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
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
33 changes: 17 additions & 16 deletions src/Utilities/hooks/useOnSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,35 @@ 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.flatMap(({ data, ids }) =>
data ?
data.flatMap(({ id }) => id)
: 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 items = shouldUseOnlyIDs ? ids : data;
const items = rows;

items.forEach((item) => {
const id = shouldUseOnlyIDs ? item : item.id;

//expanded rows does not have ID and should be disabled for selection
if (!(isObject(item) && item.isExpandedRow)) {
toSelect.push(
{
id: transformKey ? transformKey(item) : id,
selected: constructFilename ? constructFilename(item) : id
id: transformKey ? transformKey(item) : item,
selected: constructFilename ? constructFilename(item) : item
}
);
}
Expand Down Expand Up @@ -86,7 +88,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 eef6939

Please sign in to comment.