Skip to content

Commit

Permalink
Merge pull request #1583 from nicolethoen/add_cancel_action
Browse files Browse the repository at this point in the history
Add Cancel Action to builds
  • Loading branch information
openshift-merge-robot authored May 17, 2019
2 parents 1f23f72 + 0f2b373 commit bce39ee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
30 changes: 26 additions & 4 deletions frontend/public/components/build.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as _ from 'lodash-es';
import { Icon } from 'patternfly-react';
import { Link } from 'react-router-dom';

import { K8sResourceKindReference, referenceFor, K8sResourceKind } from '../module/k8s';
import { K8sResourceKindReference, referenceFor, K8sResourceKind, k8sPatch, K8sKind } from '../module/k8s';
import { cloneBuild, formatBuildDuration, BuildPhase, getBuildNumber } from '../module/k8s/builds';
import { ColHead, DetailsPage, List, ListHeader, ListPage } from './factory';
import { errorModal } from './modals';
import { errorModal, confirmModal } from './modals';
import {
AsyncComponent,
BuildHooks,
Expand Down Expand Up @@ -37,7 +37,7 @@ const BuildsReference: K8sResourceKindReference = 'Build';

const { common, EditEnvironment } = Kebab.factory;

const cloneBuildAction: KebabAction = (kind, build) => ({
const CloneBuildAction: KebabAction = (kind: K8sKind, build: K8sResourceKind) => ({
label: 'Rebuild',
callback: () => cloneBuild(build).then(clone => {
history.push(resourceObjPath(clone, referenceFor(clone)));
Expand All @@ -55,8 +55,30 @@ const cloneBuildAction: KebabAction = (kind, build) => ({
},
});

const CancelAction: KebabAction = (kind: K8sKind, build: K8sResourceKind) => ({
label: 'Cancel Build',
hidden: build.status.phase !== 'Running' && build.status.phase !== 'Pending' && build.status.phase !== 'New',
callback: () => confirmModal({
title: 'Cancel build',
message: 'Are you sure you want to cancel this build?',
btnText: 'Yes, cancel',
cancelText: 'No, don\'t cancel',
executeFn: () => k8sPatch(kind,
build,
[{ op: 'add', path: '/status/cancelled', value: true }]),
}),
accessReview: {
group: kind.apiGroup,
resource: kind.path,
name: build.metadata.name,
namespace: build.metadata.namespace,
verb: 'patch',
},
});

const menuActions = [
cloneBuildAction,
CloneBuildAction,
CancelAction,
EditEnvironment,
...common,
];
Expand Down
6 changes: 4 additions & 2 deletions frontend/public/components/factory/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ export const ModalFooter: React.SFC<ModalFooterProps> = ({message, errorMessage,
</ButtonBar>;
};

export const ModalSubmitFooter: React.SFC<ModalSubmitFooterProps> = ({message, errorMessage, inProgress, cancel, submitText, submitDisabled, submitButtonClass='btn-primary'}) => {
export const ModalSubmitFooter: React.SFC<ModalSubmitFooterProps> = ({message, errorMessage, inProgress, cancel, submitText, cancelText, submitDisabled, submitButtonClass='btn-primary'}) => {
const onCancelClick = e => {
e.stopPropagation();
cancel(e);
};

return <ModalFooter inProgress={inProgress} errorMessage={errorMessage} message={message}>
<button type="button" onClick={onCancelClick} className="btn btn-default">Cancel</button>
<button type="button" onClick={onCancelClick} className="btn btn-default">{cancelText || 'Cancel'}</button>
<button type="submit" className={classNames('btn', submitButtonClass)} disabled={submitDisabled} id="confirm-action">{submitText}</button>
</ModalFooter>;
};

ModalSubmitFooter.propTypes = {
cancel: PropTypes.func.isRequired,
cancelText: PropTypes.node,
errorMessage: PropTypes.string.isRequired,
inProgress: PropTypes.bool.isRequired,
message: PropTypes.string,
Expand Down Expand Up @@ -108,6 +109,7 @@ export type ModalSubmitFooterProps = {
errorMessage?: string;
inProgress: boolean;
cancel: (e: Event) => void;
cancelText?: React.ReactNode;
submitText: React.ReactNode;
submitDisabled?: boolean;
submitButtonClass?: string;
Expand Down
3 changes: 2 additions & 1 deletion frontend/public/components/modals/confirm-modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class ConfirmModal extends PromiseComponent {
return <form onSubmit={this._submit} name="form" className="modal-content">
<ModalTitle>{this.props.title}</ModalTitle>
<ModalBody>{this.props.message}</ModalBody>
<ModalSubmitFooter errorMessage={this.state.errorMessage} inProgress={this.state.inProgress} submitText={this.props.btnText || 'Confirm'} cancel={this._cancel} />
<ModalSubmitFooter errorMessage={this.state.errorMessage} inProgress={this.state.inProgress} submitText={this.props.btnText || 'Confirm'} cancel={this._cancel} cancelText={this.props.cancelText || 'Cancel'} />
</form>;
}
}
ConfirmModal.propTypes = {
btnText: PropTypes.node,
cancel: PropTypes.func.isRequired,
cancelText: PropTypes.node,
close: PropTypes.func.isRequired,
executeFn: PropTypes.func.isRequired,
message: PropTypes.node,
Expand Down

0 comments on commit bce39ee

Please sign in to comment.