Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT - [ADVISOR-2670] Add cancel task #52

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -42,7 +45,7 @@ const DeleteCancelTaskModal = ({
};

const renderButtons = () => {
return [
let actions = [
<Button
aria-label="delete-task-button"
key="delete-task-button"
Expand All @@ -64,30 +67,8 @@ const DeleteCancelTaskModal = ({
Cancel
</Button>,
];
/*let actions;

if (status === 'Completed') {
actions = [
<Button
key="delete-task-button"
ouiaId="delete-task-modal-button"
variant="danger"
onClick={() =>
handleTask(deleteExecutedTask, DELETE_TASK_ERROR, setIsDelete)
}
>
Delete task
</Button>,
<Button
key="cancel"
ouiaId="cancel-delete-modal-button"
variant="link"
onClick={() => setModalOpened(false)}
>
Cancel
</Button>,
];
} else if (status === 'Running') {
if (status === 'Running') {
actions = [
<Button
key="cancel-task-button"
Expand Down Expand Up @@ -120,30 +101,44 @@ const DeleteCancelTaskModal = ({
];
}

return actions;*/
return actions;
};

const renderCancelBody = () => {
return (
<div>
<span>
{isOnlySatelliteConnected
? CANCEL_TASK_BODY(startTime, title)
: CANCEL_NON_SATELLITE_TASK_BODY(startTime, title)}
</span>
<br />
<br />
<span>{EXISTING_RESULTS_STRING()}</span>
</div>
);
};

return (
<Modal
aria-label="cancel-delete-task-modal"
//title={`${status === 'Completed' ? 'Delete' : 'Cancel'} this task?`}
title="Delete this task?"
title={`${status === 'Running' ? 'Cancel' : 'Delete'} this task?`}
titleIconVariant="warning"
isOpen={isOpen}
onClose={() => setModalOpened(false)}
width={'50%'}
actions={renderButtons()}
>
{/*status === 'Completed'
? DELETE_TASK_BODY(startTime, title)
: CANCEL_TASK_BODY(startTime, title)*/}
{DELETE_TASK_BODY(startTime, title)}
{status === 'Running'
? renderCancelBody()
: DELETE_TASK_BODY(startTime, title)}
</Modal>
);
};

DeleteCancelTaskModal.propTypes = {
id: propTypes.number,
isOnlySatelliteConnected: propTypes.bool,
isOpen: propTypes.bool,
setIsCancel: propTypes.func,
setIsDelete: propTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
getSelectedSystems,
fetchTask,
fetchTaskJobs,
onlySatelliteConnected,
} from '../completedTaskDetailsHelpers';

const CompletedTaskDetails = () => {
Expand Down Expand Up @@ -101,6 +102,7 @@ const CompletedTaskDetails = () => {
/>
<DeleteCancelTaskModal
id={completedTaskDetails.id}
isOnlySatelliteConnected={onlySatelliteConnected(completedTaskJobs)}
isOpen={isDeleteCancelModalOpened}
setIsCancel={setIsCancel}
setIsDelete={setIsDelete}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import {
const CompletedTaskDetailsKebab = ({ status, setModalOpened }) => {
const [isOpen, setIsOpen] = useState(false);
const createDropdownItems = () => {
//let type = status === 'Running' ? 'cancel' : 'delete';
let type = 'delete';
let type = status === 'Running' ? 'cancel' : 'delete';
return [
<DropdownItem
aria-label={`${type}-task-kebab-button`}
key={`${type}-task`}
component="button"
data-ouia-component-id={`${type}-task-dropdown-item`}
onClick={() => setModalOpened(true)}
isDisabled={status !== 'Completed'}
>
{type[0].toUpperCase() + type.slice(1)}
</DropdownItem>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ exports[`AvailableTasks should render Delete disabled 1`] = `
role="menuitem"
>
<button
aria-disabled="true"
aria-label="delete-task-kebab-button"
class="pf-m-disabled pf-c-dropdown__menu-item"
data-ouia-component-id="delete-task-dropdown-item"
aria-disabled="false"
aria-label="cancel-task-kebab-button"
class="pf-c-dropdown__menu-item"
data-ouia-component-id="cancel-task-dropdown-item"
data-ouia-component-type="PF4/DropdownItem"
data-ouia-safe="true"
tabindex="-1"
type="button"
>
Delete
Cancel
</button>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
fetchTaskJobs,
getSelectedSystems,
isError,
onlySatelliteConnected,
} from '../completedTaskDetailsHelpers';
import RunTaskModal from '../RunTaskModal/RunTaskModal';

Expand All @@ -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();
Expand All @@ -55,6 +58,8 @@ const CompletedTasksTable = () => {
setTaskError
);

setIsOnlySatelliteConnected(onlySatelliteConnected(fetchedTaskJobs));

if (fetchedTaskJobs.length) {
setSelectedSystems(getSelectedSystems(fetchedTaskJobs));
await setCompletedTaskDetails(fetchedTaskDetails);
Expand Down Expand Up @@ -131,6 +136,7 @@ const CompletedTasksTable = () => {
/>
<DeleteCancelTaskModal
id={taskDetails.id}
isOnlySatelliteConnected={isOnlySatelliteConnected}
isOpen={isDeleteCancelModalOpened}
setIsCancel={setIsCancel}
setIsDelete={setIsDelete}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ const useActionResolver = (handleTask, fetchTaskDetails) => {
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);
},
Expand Down
4 changes: 4 additions & 0 deletions src/SmartComponents/completedTaskDetailsHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
16 changes: 15 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down