diff --git a/src/PresentationalComponents/DeleteCancelTaskModal/DeleteCancelTaskModal.js b/src/PresentationalComponents/DeleteCancelTaskModal/DeleteCancelTaskModal.js index 45322bba..77aa8a87 100644 --- a/src/PresentationalComponents/DeleteCancelTaskModal/DeleteCancelTaskModal.js +++ b/src/PresentationalComponents/DeleteCancelTaskModal/DeleteCancelTaskModal.js @@ -2,23 +2,26 @@ import React from 'react'; import { Button, Modal } from '@patternfly/react-core'; import propTypes from 'prop-types'; import { - //CANCEL_TASK_BODY, - //CANCEL_TASK_ERROR, + CANCEL_NON_SATELLITE_TASK_BODY, + CANCEL_TASK_BODY, + CANCEL_TASK_ERROR, DELETE_TASK_BODY, DELETE_TASK_ERROR, + EXISTING_RESULTS_STRING, } from '../../constants'; -import { /*cancelExecutedTask,*/ deleteExecutedTask } from '../../../api'; +import { cancelExecutedTask, deleteExecutedTask } from '../../../api'; import { dispatchNotification } from '../../Utilities/Dispatcher'; import { isError } from '../../SmartComponents/completedTaskDetailsHelpers'; const DeleteCancelTaskModal = ({ id, + isOnlySatelliteConnected, isOpen, - //setIsCancel, + setIsCancel, setIsDelete, setModalOpened, startTime, - //status, + status, title, }) => { const createNotification = (message) => { @@ -42,7 +45,7 @@ const DeleteCancelTaskModal = ({ }; const renderButtons = () => { - return [ + let actions = [ , - , - ]; - } else if (status === 'Running') { + if (status === 'Running') { actions = [ diff --git a/src/SmartComponents/CompletedTasksTable/CompletedTasksTable.js b/src/SmartComponents/CompletedTasksTable/CompletedTasksTable.js index b7d589cf..f4ca39b8 100644 --- a/src/SmartComponents/CompletedTasksTable/CompletedTasksTable.js +++ b/src/SmartComponents/CompletedTasksTable/CompletedTasksTable.js @@ -23,6 +23,7 @@ import { fetchTaskJobs, getSelectedSystems, isError, + onlySatelliteConnected, } from '../completedTaskDetailsHelpers'; import RunTaskModal from '../RunTaskModal/RunTaskModal'; @@ -43,6 +44,8 @@ const CompletedTasksTable = () => { const [taskDetails, setTaskDetails] = useState({}); const [runTaskModalOpened, setRunTaskModalOpened] = useState(false); const [selectedSystems, setSelectedSystems] = useState([]); + const [isOnlySatelliteConnected, setIsOnlySatelliteConnected] = + useState(false); const fetchTaskDetails = async (id) => { setTaskError(); @@ -55,6 +58,8 @@ const CompletedTasksTable = () => { setTaskError ); + setIsOnlySatelliteConnected(onlySatelliteConnected(fetchedTaskJobs)); + if (fetchedTaskJobs.length) { setSelectedSystems(getSelectedSystems(fetchedTaskJobs)); await setCompletedTaskDetails(fetchedTaskDetails); @@ -131,6 +136,7 @@ const CompletedTasksTable = () => { /> { onClick(fetchTaskDetails, task.task.title.props.id), }, { - title: 'Delete', - isDisabled: row.task.title.props.status !== 'Completed', - /*row.task.title.props.status === 'Completed' || + title: + row.task.title.props.status === 'Completed' || row.task.title.props.status === 'Cancelled' ? 'Delete' - : 'Cancel',*/ + : 'Cancel', onClick: (_event, _index, task) => { onClick(handleTask, task.task.title.props); }, diff --git a/src/SmartComponents/completedTaskDetailsHelpers.js b/src/SmartComponents/completedTaskDetailsHelpers.js index 79bb1e95..996a4784 100644 --- a/src/SmartComponents/completedTaskDetailsHelpers.js +++ b/src/SmartComponents/completedTaskDetailsHelpers.js @@ -46,3 +46,7 @@ export const fetchTaskJobs = async (taskDetails, setError) => { return taskJobs.data; } }; + +export const onlySatelliteConnected = (jobs) => { + return !jobs.some((job) => job.connection_type !== 'satellite'); +}; diff --git a/src/constants.js b/src/constants.js index 7201f620..ab539d36 100644 --- a/src/constants.js +++ b/src/constants.js @@ -312,8 +312,22 @@ export const DELETE_TASK_ERROR = (title) => { return `Error: Task "${title}" could not be deleted`; }; +export const EXISTING_RESULTS_STRING = () => { + return 'Any existing results will be available.'; +}; + export const CANCEL_TASK_BODY = (startTime, title) => { - return `Cancelling the ${startTime} run of "${title}" will stop any analysis in progress. Any existing results will be available.`; + return `Cancelling the ${moment + .utc(startTime) + .format( + 'MMM DD YYYY' + )} run of "${title}" will stop any analysis in progress.`; +}; + +export const CANCEL_NON_SATELLITE_TASK_BODY = (startTime, title) => { + return CANCEL_TASK_BODY(startTime, title).concat( + ' Tasks running on systems connected with rhc cannot be cancelled.' + ); }; export const CANCEL_TASK_ERROR = (title) => {