Skip to content

Commit

Permalink
refactor: ds-390 remove pause, restart scans (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed May 2, 2024
1 parent 4c2224f commit 797f6b6
Show file tree
Hide file tree
Showing 15 changed files with 9 additions and 349 deletions.
2 changes: 0 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ REACT_APP_SCAN_JOBS_SERVICE_START_GET=/api/v1/scans/{0}/jobs/
REACT_APP_SCAN_JOBS_SERVICE=/api/v1/jobs/
REACT_APP_SCAN_JOBS_SERVICE_CONNECTION=/api/v1/jobs/{0}/connection/
REACT_APP_SCAN_JOBS_SERVICE_INSPECTION=/api/v1/jobs/{0}/inspection/
REACT_APP_SCAN_JOBS_SERVICE_PAUSE=/api/v1/jobs/{0}/pause/
REACT_APP_SCAN_JOBS_SERVICE_CANCEL=/api/v1/jobs/{0}/cancel/
REACT_APP_SCAN_JOBS_SERVICE_RESTART=/api/v1/jobs/{0}/restart/
REACT_APP_SCAN_JOBS_SERVICE_MERGE=/api/v1/jobs/merge/

REACT_APP_SOURCES_SERVICE=/api/v1/sources/
Expand Down
2 changes: 0 additions & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ REACT_APP_SCAN_JOBS_SERVICE_START_GET=/scans/{0}/jobs/
REACT_APP_SCAN_JOBS_SERVICE=/jobs/
REACT_APP_SCAN_JOBS_SERVICE_CONNECTION=/jobs/{0}/connection/
REACT_APP_SCAN_JOBS_SERVICE_INSPECTION=/jobs/{0}/inspection/
REACT_APP_SCAN_JOBS_SERVICE_PAUSE=/jobs/{0}/pause/
REACT_APP_SCAN_JOBS_SERVICE_CANCEL=/jobs/{0}/cancel/
REACT_APP_SCAN_JOBS_SERVICE_RESTART=/jobs/{0}/restart/
REACT_APP_SCAN_JOBS_SERVICE_MERGE=/jobs/merge/

REACT_APP_SOURCES_SERVICE=/sources/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ exports[`ScansContext should handle scan actions with multiple callbacks: callba
"onCancel": [Function],
"onDownload": [Function],
"onDownloadJob": [Function],
"onPause": [Function],
"onRestart": [Function],
"onStart": [Function],
}
`;
Expand Down
4 changes: 1 addition & 3 deletions src/components/scans/scans.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Scans = ({
const dispatch = useAliasDispatch();
const onDelete = useAliasOnDelete();
const onExpand = useAliasOnExpand();
const { onCancel, onDownload, onPause, onRestart, onStart } = useAliasOnScanAction();
const { onCancel, onDownload, onStart } = useAliasOnScanAction();
const onSelect = useAliasOnSelect();
const {
pending,
Expand Down Expand Up @@ -208,8 +208,6 @@ const Scans = ({
onDelete: () => onDelete(item),
onCancel: () => onCancel(item),
onDownload: () => onDownload(item),
onRestart: () => onRestart(item),
onPause: () => onPause(item),
onStart: () => onStart(item)
}),
isActionCell: true
Expand Down
36 changes: 1 addition & 35 deletions src/components/scans/scansContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ const useOnExpand = ({ useDispatch: useAliasDispatch = storeHooks.reactRedux.use
};

/**
* Report/scan actions cancel, pause, restart, start, and download.
* Report/scan actions cancel, start, and download.
*
* @param {object} options
* @param {Function} options.cancelScan
* @param {Function} options.getReportsDownload
* @param {Function} options.pauseScan
* @param {Function} options.restartScan
* @param {Function} options.startScan
* @param {Function} options.t
* @param {Function} options.useDispatch
Expand All @@ -163,8 +161,6 @@ const useOnExpand = ({ useDispatch: useAliasDispatch = storeHooks.reactRedux.use
const useOnScanAction = ({
cancelScan = reduxActions.scans.cancelScan,
getReportsDownload = reduxActions.reports.getReportsDownload,
pauseScan = reduxActions.scans.pauseScan,
restartScan = reduxActions.scans.restartScan,
startScan = reduxActions.scans.startScan,
t = translate,
useDispatch: useAliasDispatch = storeHooks.reactRedux.useDispatch,
Expand Down Expand Up @@ -257,34 +253,6 @@ const useOnScanAction = ({
[getReportsDownload, dispatch]
);

/**
* onPause for scanning
*
* @type {Function}
*/
const onPause = useCallback(
({ [apiTypes.API_RESPONSE_SCAN_MOST_RECENT]: mostRecent, [apiTypes.API_RESPONSE_SCAN_NAME]: name }) => {
const id = mostRecent[apiTypes.API_RESPONSE_SCAN_MOST_RECENT_ID];
pauseScan(id)(dispatch);
setUpdatedScan(() => ({ id, name, context: 'paused' }));
},
[pauseScan, dispatch]
);

/**
* onRestart for scanning
*
* @type {Function}
*/
const onRestart = useCallback(
({ [apiTypes.API_RESPONSE_SCAN_MOST_RECENT]: mostRecent, [apiTypes.API_RESPONSE_SCAN_NAME]: name }) => {
const id = mostRecent[apiTypes.API_RESPONSE_SCAN_MOST_RECENT_ID];
restartScan(id)(dispatch);
setUpdatedScan(() => ({ id, name, context: 'restart' }));
},
[restartScan, dispatch]
);

/**
* onStart for scanning
*
Expand All @@ -302,8 +270,6 @@ const useOnScanAction = ({
onCancel,
onDownload,
onDownloadJob,
onPause,
onRestart,
onStart
};
};
Expand Down
18 changes: 1 addition & 17 deletions src/components/scans/scansTableCells.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,6 @@ const scansCellContent = (
};

// FixMe: PF Overflow menu is attempting state updates on unmounted components
/**
* FixMe: Older issue associated with displaying both "pause" and "cancel" after a user restarts a scan.
* Basically, in testing you can't immediately pause a scan, or multiple scans, or the API throws an error.
* Because of this we only display the "cancel"/"stop" button. Or at least that's what the old code was
* doing, pre-refactor. Hitting refresh should display both buttons. If this gets fixed the condition to
* modify is associated with...
* mostRecentStatus === 'created' || mostRecentStatus === 'running'
*/
/**
* Action cell content
*
Expand All @@ -259,8 +251,6 @@ const scansCellContent = (
* @param {Function} params.onCancel
* @param {Function} params.onDownload
* @param {Function} params.onDelete
* @param {Function} params.onRestart
* @param {Function} params.onPause
* @param {Function} params.onStart
* @param {Function} params.t
* @returns {React.ReactNode}
Expand All @@ -271,8 +261,6 @@ const actionsCell = ({
item = {},
onCancel = helpers.noop,
onDownload = helpers.noop,
onRestart = helpers.noop,
onPause = helpers.noop,
onStart = helpers.noop,
onDelete = helpers.noop,
t = translate
Expand All @@ -299,9 +287,7 @@ const actionsCell = ({
return onDelete(item);
case 'created':
case 'running':
return onPause(item);
case 'paused':
return onRestart(item);
case 'pending':
return onCancel(item);
case 'completed':
Expand Down Expand Up @@ -343,9 +329,7 @@ const actionsCell = ({
const menuItems = [];

if (mostRecentStatus) {
if (mostRecentStatus === 'created' || mostRecentStatus === 'running') {
menuItems.push(menuItem(ContextIconActionVariant.running), menuItem(ContextIconActionVariant.pending));
} else {
if (mostRecentStatus !== 'created' && mostRecentStatus !== 'running') {
menuItems.push(menuItem(mostRecentStatus));
}
}
Expand Down
14 changes: 0 additions & 14 deletions src/redux/actions/__tests__/scansActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,13 @@ describe('ScansActions', () => {
expect(state.scans.action.lorem.fulfilled).toEqual(true);
});

it('Should return response content for pauseScan method', async () => {
const dispatcher = scansActions.pauseScan('lorem');

const { state } = await generateDispatch(dispatcher);
expect(state.scans.action.lorem.fulfilled).toEqual(true);
});

it('Should return response content for cancelScan method', async () => {
const dispatcher = scansActions.cancelScan('lorem');

const { state } = await generateDispatch(dispatcher);
expect(state.scans.action.lorem.fulfilled).toEqual(true);
});

it('Should return response content for restartScan method', async () => {
const dispatcher = scansActions.restartScan('lorem');

const { state } = await generateDispatch(dispatcher);
expect(state.scans.action.lorem.fulfilled).toEqual(true);
});

it('Should return response content for deleteScan method', async () => {
const dispatcher = scansActions.deleteScan();
const { value } = await generateDispatch(dispatcher);
Expand Down
22 changes: 2 additions & 20 deletions src/redux/actions/scansActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,13 @@ const startScan = id => dispatch =>
meta: { id }
});

const pauseScan = id => dispatch =>
dispatch({
type: scansTypes.PAUSE_SCAN,
payload: scansService.pauseScan(id),
meta: { id }
});

const cancelScan = id => dispatch =>
dispatch({
type: scansTypes.CANCEL_SCAN,
payload: scansService.cancelScan(id),
meta: { id }
});

const restartScan = id => dispatch =>
dispatch({
type: scansTypes.RESTART_SCAN,
payload: scansService.restartScan(id),
meta: { id }
});

const deleteScan = id => dispatch => {
const updatedIds = (Array.isArray(id) && id) || [id];

Expand All @@ -110,9 +96,7 @@ const scansActions = {
getConnectionScanResults,
getInspectionScanResults,
startScan,
pauseScan,
cancelScan,
restartScan
cancelScan
};

export {
Expand All @@ -127,7 +111,5 @@ export {
getConnectionScanResults,
getInspectionScanResults,
startScan,
pauseScan,
cancelScan,
restartScan
cancelScan
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ exports[`ReduxTypes should have specific type properties: all redux types 1`] =
"MERGE_SCAN_DIALOG_HIDE": "MERGE_SCAN_DIALOG_HIDE",
"MERGE_SCAN_DIALOG_SHOW": "MERGE_SCAN_DIALOG_SHOW",
"NOT_EXPANDED_SCAN": "NOT_EXPANDED_SCAN",
"PAUSE_SCAN": "PAUSE_SCAN",
"RESET_ACTIONS": "RESET_SCAN_ACTIONS",
"RESTART_SCAN": "RESTART_SCAN",
"SELECT_SCAN": "SELECT_SCAN",
"START_SCAN": "START_SCAN",
"UPDATE_SCANS": "UPDATE_SCANS",
Expand Down Expand Up @@ -175,9 +173,7 @@ exports[`ReduxTypes should have specific type properties: all redux types 1`] =
"MERGE_SCAN_DIALOG_HIDE": "MERGE_SCAN_DIALOG_HIDE",
"MERGE_SCAN_DIALOG_SHOW": "MERGE_SCAN_DIALOG_SHOW",
"NOT_EXPANDED_SCAN": "NOT_EXPANDED_SCAN",
"PAUSE_SCAN": "PAUSE_SCAN",
"RESET_ACTIONS": "RESET_SCAN_ACTIONS",
"RESTART_SCAN": "RESTART_SCAN",
"SELECT_SCAN": "SELECT_SCAN",
"START_SCAN": "START_SCAN",
"UPDATE_SCANS": "UPDATE_SCANS",
Expand Down Expand Up @@ -247,9 +243,7 @@ exports[`ReduxTypes should have specific type properties: all redux types 1`] =
"MERGE_SCAN_DIALOG_HIDE": "MERGE_SCAN_DIALOG_HIDE",
"MERGE_SCAN_DIALOG_SHOW": "MERGE_SCAN_DIALOG_SHOW",
"NOT_EXPANDED_SCAN": "NOT_EXPANDED_SCAN",
"PAUSE_SCAN": "PAUSE_SCAN",
"RESET_ACTIONS": "RESET_SCAN_ACTIONS",
"RESTART_SCAN": "RESTART_SCAN",
"SELECT_SCAN": "SELECT_SCAN",
"START_SCAN": "START_SCAN",
"UPDATE_SCANS": "UPDATE_SCANS",
Expand Down Expand Up @@ -349,9 +343,7 @@ exports[`ReduxTypes should have specific type properties: specific types 1`] = `
"MERGE_SCAN_DIALOG_HIDE": "MERGE_SCAN_DIALOG_HIDE",
"MERGE_SCAN_DIALOG_SHOW": "MERGE_SCAN_DIALOG_SHOW",
"NOT_EXPANDED_SCAN": "NOT_EXPANDED_SCAN",
"PAUSE_SCAN": "PAUSE_SCAN",
"RESET_ACTIONS": "RESET_SCAN_ACTIONS",
"RESTART_SCAN": "RESTART_SCAN",
"SELECT_SCAN": "SELECT_SCAN",
"START_SCAN": "START_SCAN",
"UPDATE_SCANS": "UPDATE_SCANS",
Expand Down
6 changes: 0 additions & 6 deletions src/redux/constants/scansConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const GET_SCAN_JOBS = 'GET_SCAN_JOBS';

const START_SCAN = 'START_SCAN';
const CANCEL_SCAN = 'CANCEL_SCAN';
const PAUSE_SCAN = 'PAUSE_SCAN';
const RESTART_SCAN = 'RESTART_SCAN';

const EDIT_SCAN_HIDE = 'EDIT_SCAN_HIDE';
const EDIT_SCAN_SHOW = 'EDIT_SCAN_SHOW';
Expand All @@ -38,8 +36,6 @@ const scansTypes = {
GET_SCAN_JOBS,
START_SCAN,
CANCEL_SCAN,
PAUSE_SCAN,
RESTART_SCAN,
EDIT_SCAN_HIDE,
EDIT_SCAN_SHOW,
MERGE_SCAN_DIALOG_HIDE,
Expand All @@ -65,8 +61,6 @@ export {
GET_SCAN_JOBS,
START_SCAN,
CANCEL_SCAN,
PAUSE_SCAN,
RESTART_SCAN,
EDIT_SCAN_HIDE,
EDIT_SCAN_SHOW,
MERGE_SCAN_DIALOG_HIDE,
Expand Down
Loading

0 comments on commit 797f6b6

Please sign in to comment.