mirror of
https://github.com/ansible/awx.git
synced 2026-05-16 13:57:39 -02:30
Add cancel button to workflow job output (#12338)
Add cancel button to workflow job output See: https://github.com/ansible/awx/issues/10514
This commit is contained in:
@@ -8,12 +8,13 @@ import AlertModal from '../AlertModal';
|
|||||||
import ErrorDetail from '../ErrorDetail';
|
import ErrorDetail from '../ErrorDetail';
|
||||||
|
|
||||||
function JobCancelButton({
|
function JobCancelButton({
|
||||||
job = {},
|
|
||||||
errorTitle,
|
errorTitle,
|
||||||
title,
|
title,
|
||||||
showIconButton,
|
showIconButton,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
buttonText,
|
buttonText,
|
||||||
|
style = {},
|
||||||
|
job = {},
|
||||||
}) {
|
}) {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const { error: cancelError, request: cancelJob } = useRequest(
|
const { error: cancelError, request: cancelJob } = useRequest(
|
||||||
@@ -38,6 +39,7 @@ function JobCancelButton({
|
|||||||
ouiaId="cancel-job-button"
|
ouiaId="cancel-job-button"
|
||||||
onClick={() => setIsOpen(true)}
|
onClick={() => setIsOpen(true)}
|
||||||
variant="plain"
|
variant="plain"
|
||||||
|
style={style}
|
||||||
>
|
>
|
||||||
<MinusCircleIcon />
|
<MinusCircleIcon />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -48,6 +50,7 @@ function JobCancelButton({
|
|||||||
variant="secondary"
|
variant="secondary"
|
||||||
ouiaId="cancel-job-button"
|
ouiaId="cancel-job-button"
|
||||||
onClick={() => setIsOpen(true)}
|
onClick={() => setIsOpen(true)}
|
||||||
|
style={style}
|
||||||
>
|
>
|
||||||
{buttonText || t`Cancel Job`}
|
{buttonText || t`Cancel Job`}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
} from '@patternfly/react-icons';
|
} from '@patternfly/react-icons';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import StatusLabel from 'components/StatusLabel';
|
import StatusLabel from 'components/StatusLabel';
|
||||||
|
import JobCancelButton from 'components/JobCancelButton';
|
||||||
import {
|
import {
|
||||||
WorkflowDispatchContext,
|
WorkflowDispatchContext,
|
||||||
WorkflowStateContext,
|
WorkflowStateContext,
|
||||||
@@ -61,7 +62,6 @@ const ActionButton = styled(Button)`
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function WorkflowOutputToolbar({ job }) {
|
function WorkflowOutputToolbar({ job }) {
|
||||||
const dispatch = useContext(WorkflowDispatchContext);
|
const dispatch = useContext(WorkflowDispatchContext);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -80,6 +80,18 @@ function WorkflowOutputToolbar({ job }) {
|
|||||||
<StatusLabel status={job.status} />
|
<StatusLabel status={job.status} />
|
||||||
</ToolbarJob>
|
</ToolbarJob>
|
||||||
<ToolbarActions>
|
<ToolbarActions>
|
||||||
|
{['new', 'pending', 'waiting', 'running'].includes(job?.status) &&
|
||||||
|
job?.summary_fields?.user_capabilities?.start ? (
|
||||||
|
<JobCancelButton
|
||||||
|
style={{ margin: '0px 6px', padding: '6px 10px' }}
|
||||||
|
job={job}
|
||||||
|
errorTitle={t`Job Cancel Error`}
|
||||||
|
title={t`Cancel ${job.name}`}
|
||||||
|
errorMessage={t`Failed to cancel ${job.name}`}
|
||||||
|
showIconButton
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<ActionButton
|
<ActionButton
|
||||||
ouiaId="edit-workflow"
|
ouiaId="edit-workflow"
|
||||||
aria-label={t`Edit workflow`}
|
aria-label={t`Edit workflow`}
|
||||||
|
|||||||
@@ -10,7 +10,12 @@ let wrapper;
|
|||||||
const dispatch = jest.fn();
|
const dispatch = jest.fn();
|
||||||
const job = {
|
const job = {
|
||||||
id: 1,
|
id: 1,
|
||||||
status: 'successful',
|
status: 'running',
|
||||||
|
summary_fields: {
|
||||||
|
user_capabilities: {
|
||||||
|
start: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const workflowContext = {
|
const workflowContext = {
|
||||||
nodes: [],
|
nodes: [],
|
||||||
@@ -49,6 +54,7 @@ describe('WorkflowOutputToolbar', () => {
|
|||||||
shouldFind('Button#workflow-output-toggle-legend');
|
shouldFind('Button#workflow-output-toggle-legend');
|
||||||
shouldFind('Badge');
|
shouldFind('Badge');
|
||||||
shouldFind('Button#workflow-output-toggle-tools');
|
shouldFind('Button#workflow-output-toggle-tools');
|
||||||
|
shouldFind('JobCancelButton');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Shows correct number of nodes', () => {
|
test('Shows correct number of nodes', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user