Skip to content

Commit

Permalink
fix: Fix passing systems into opt out function (RedHatInsights#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
leSamo committed Sep 2, 2021
1 parent 1ad1b08 commit 6641b97
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Components/SmartComponents/SystemsPage/SystemsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const SystemsPage = () => {
inventoryRef.current.onRefreshData(({ page: 1 }))
);

const doOptOut = useOptOutSystems({ selectedRows, selectedRowsCount, onRefreshInventory });
const doOptOut = useOptOutSystems(onRefreshInventory);
let columnCounter = useMemo(() => columnCounter ? columnCounter++ : 0, []);
const getEntities = useGetEntities(APIHelper.getSystems, setUrlParams);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ const SystemsTableToolbar = ({
'',
{
label: intl.formatMessage(messages.systemKebabExcludeAnalysis, { count: selectedRowsCount }),
onClick: () => doOptOut(null, selectedRowsRawData.length === 1 && selectedRowsRawData[0].display_name, true),
onClick: () => doOptOut(selectedRows, selectedRowsRawData?.[0].display_name, true),
props: { isDisabled: !selectedRowsCount || !kebabProps.selectedIncluded }
},
{
label: intl.formatMessage(messages.systemKebabIncludeAnalysis, { count: selectedRowsCount }),
onClick: () => doOptOut(null, selectedRowsRawData.length === 1 && selectedRowsRawData[0].display_name, false),
onClick: () => doOptOut(selectedRows, selectedRowsRawData?.[0].display_name, false, selectedRows),
props: { isDisabled: !selectedRowsCount || !kebabProps.selectedExcluded }
}
];
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/CVEHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const systemTableRowActions = (rowData, optOutFunc) => [
: <FormattedMessage {...messages.systemKebabExcludeAnalysis} values={{ count: 1 }} />
),
onClick: (event, rowId, rowData) => {
optOutFunc(rowData.id, rowData.display_name, !rowData.opt_out);
optOutFunc({ [rowData.id]: true }, rowData.display_name, !rowData.opt_out);
}
}
];
2 changes: 1 addition & 1 deletion src/Helpers/CVEHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,6 @@ describe('CVEHelper', () => {
const rawData = {id: 'testId', display_name: 'testName', opt_out: true};
const actions = systemTableRowActions(rawData, optOutFunc);
actions[0].onClick(null, null, rawData);
expect((optOutFunc)).toHaveBeenCalledWith('testId', 'testName', false);
expect((optOutFunc)).toHaveBeenCalledWith({ testId: true }, 'testName', false);
})
});
14 changes: 6 additions & 8 deletions src/Helpers/Hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ export const useGetEntities = (fetchApi, setUrlParams) => {
return getEntities;
};

export const useOptOutSystems = ({
selectedRows,
selectedRowsCount: count,
onRefreshInventory
}) => {
export const useOptOutSystems = onRefreshInventory => {
const [addSuccessNotification] = useNotification({ variant: 'success' });
const [addFailureNotification] = useNotification({ variant: 'danger', autoDismiss: false });
const dispatch = useDispatch();
Expand All @@ -81,12 +77,14 @@ export const useOptOutSystems = ({
/**
* Excludes/included provided system(s), if toggling one system systemId and systemName have to be set.
* If toggling multiple systems, these two params are ignored and system info will be extracted from selectedRows.
* @param {?string} systemId - id of a system if only a single system is toggled
* @param {object} affectedRows - object with keys representing ids of systems to opt out/in
* @param {?string} systemName - display name of a system if only a single system is toggled
* @param {bool} isIncluded - if true systems will be excluded, else included
*/
return (systemId, systemName, isIncluded) => {
dispatch(optOutSystemsAction(systemId ? [systemId] : Object.keys(selectedRows), isIncluded))
return (affectedRows, systemName, isIncluded) => {
const count = Object.keys(affectedRows).length;

dispatch(optOutSystemsAction(Object.keys(affectedRows), isIncluded))
.then(() => {
isIncluded ?
addSuccessNotification({
Expand Down

0 comments on commit 6641b97

Please sign in to comment.