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

Add the ability to cancel / delete a task before it has been picked up by an agent #381

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
80 changes: 80 additions & 0 deletions MythicReactUI/src/components/MythicComponents/TaskDeleteDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, {useState} from 'react';
import Button from '@mui/material/Button';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
import MythicTextField from '../../MythicComponents/MythicTextField';
import {useQuery, gql, useMutation} from '@apollo/client';
import LinearProgress from '@mui/material/LinearProgress';

const deleteTaskByPkMutation = gql`
mutation deleteTask($task_id: Int!) {
delete_task_by_pk(id: $task_id) {
id
}
}
`;


const getStatusQuery= gql`
query getStatusQuery ($task_id: Int!) {
task_by_pk(id: $task_id) {
status
commentOperator {
username
}
id
}
}
`;

export function TaskDeleteDialog(props) {
const [status, setStatus] = useState("");
const { loading, error } = useQuery(getStatusQuery, {
variables: {task_id: props.task_id},
onCompleted: data => {
//setStatus(data.task_by_pk.status)
setStatus("Warning: This will delete Task!");
},
fetchPolicy: "network-only"
});

const [deleteTask] = useMutation(deleteTaskByPkMutation,{
variables: {task_id: props.task_id}

});

if (loading) {
return <LinearProgress />;
}
if (error) {
console.error(error);
return <div>Error!</div>;
}
const onCommitSubmit = () => {
deleteTask({variables: {task_id: props.task_id}});
props.onClose();
}
const onChange = (name, value, error) => {
setStatus(value);
}

return (
<React.Fragment>
<DialogTitle id="form-dialog-title">Cancel Task</DialogTitle>
<DialogContent dividers={true}>
Are you sure?
<MythicTextField autoFocus onEnter={onCommitSubmit} onChange={onChange} value={status} />
</DialogContent>
<DialogActions>
<Button onClick={props.onClose} variant="contained" color="primary">
Cancel
</Button>
<Button onClick={onCommitSubmit} variant="contained" color="success">
Confirm
</Button>
</DialogActions>
</React.Fragment>
);
}

Loading