diff --git a/src/Components/SmartComponents/SystemsPage/SystemsPage.js b/src/Components/SmartComponents/SystemsPage/SystemsPage.js index e5009b44b..bdf224072 100644 --- a/src/Components/SmartComponents/SystemsPage/SystemsPage.js +++ b/src/Components/SmartComponents/SystemsPage/SystemsPage.js @@ -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); diff --git a/src/Components/SmartComponents/SystemsPage/SystemsTableToolbar.js b/src/Components/SmartComponents/SystemsPage/SystemsTableToolbar.js index e1b825614..cc30fb87c 100644 --- a/src/Components/SmartComponents/SystemsPage/SystemsTableToolbar.js +++ b/src/Components/SmartComponents/SystemsPage/SystemsTableToolbar.js @@ -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 } } ]; diff --git a/src/Helpers/CVEHelper.js b/src/Helpers/CVEHelper.js index d4e775cee..c38fbc5a8 100644 --- a/src/Helpers/CVEHelper.js +++ b/src/Helpers/CVEHelper.js @@ -205,7 +205,7 @@ export const systemTableRowActions = (rowData, optOutFunc) => [ : ), onClick: (event, rowId, rowData) => { - optOutFunc(rowData.id, rowData.display_name, !rowData.opt_out); + optOutFunc({ [rowData.id]: true }, rowData.display_name, !rowData.opt_out); } } ]; diff --git a/src/Helpers/CVEHelper.test.js b/src/Helpers/CVEHelper.test.js index f0d383c1e..db4e7cc8d 100644 --- a/src/Helpers/CVEHelper.test.js +++ b/src/Helpers/CVEHelper.test.js @@ -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); }) }); diff --git a/src/Helpers/Hooks.js b/src/Helpers/Hooks.js index 7658efef9..e1d070236 100644 --- a/src/Helpers/Hooks.js +++ b/src/Helpers/Hooks.js @@ -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(); @@ -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({