Skip to content

Commit

Permalink
Merge pull request #898 from pradnya-orchestral/Delete_Action/Workflow
Browse files Browse the repository at this point in the history
Delete action/workflow
  • Loading branch information
m4dcoder committed Aug 18, 2021
2 parents 79c7eba + 7f5b77c commit 9c578e2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
14 changes: 12 additions & 2 deletions apps/st2-actions/actions-details.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class ActionsDetails extends React.Component {
static propTypes = {
handleNavigate: PropTypes.func.isRequired,
handleRun: PropTypes.func.isRequired,
handleDelete: PropTypes.func.isRequired,

id: PropTypes.string,
section: PropTypes.string,
Expand Down Expand Up @@ -127,8 +128,6 @@ export default class ActionsDetails extends React.Component {
}
}



componentDidUpdate(prevProps) {
const { id } = this.props;
if (id && id !== prevProps.id) {
Expand Down Expand Up @@ -242,6 +241,15 @@ export default class ActionsDetails extends React.Component {
return this.props.handleRun(...args);
}

handleDelete (ref) {
const { id } = this.props;

if (!window.confirm(`You are about to delete the action "${id}". This operation is irreversible. Are you sure?`)) {
return undefined;
}
return this.props.handleDelete(id);
}

render() {
const { section, action, executions, entrypoint } = this.props;
if (!action) {
Expand Down Expand Up @@ -281,6 +289,8 @@ export default class ActionsDetails extends React.Component {
/>
<Button flat value="Preview" onClick={() => this.handleToggleRunPreview()} />
<DetailsToolbarSeparator />
<Button className="st2-forms__button st2-details__toolbar-button" value="Delete" onClick={() => this.handleDelete()} />

{ action.runner_type === 'mistral-v2' || action.runner_type === 'orquesta' ? (
<Link
target="_blank"
Expand Down
30 changes: 26 additions & 4 deletions apps/st2-actions/actions-panel.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import './style.css';
return { collapsed, ...props };
}, (dispatch, props) => {
const { uid } = props;

return {
onToggle: () => store.dispatch(flexActions.toggle(uid)),
};
Expand Down Expand Up @@ -116,7 +115,6 @@ export default class ActionsPanel extends React.Component {
.then(() => {
const { id } = this.urlParams;
const { groups } = this.props;

if (id && groups && !groups.some(({ actions }) => actions.some(({ ref }) => ref === id))) {
this.navigate({ id: false });
}
Expand All @@ -128,8 +126,7 @@ export default class ActionsPanel extends React.Component {
const {
ref = get('groups[0].actions[0].ref', this.props),
section = 'general',
} = this.props.match.params;

} = this.props.match.params;
return {
id: ref,
section,
Expand Down Expand Up @@ -211,6 +208,30 @@ export default class ActionsPanel extends React.Component {
});
}

handleDelete (ref) {
return store.dispatch({
type: 'DELETE_ACTION',
ref,
promise: api.request({
method: 'delete',
path: `/actions/${ref}`,
})
.then((res) => {
notification.success(`Action "${ref}" has been deleted successfully.`);
this.navigate({ id: null });
store.dispatch(flexActions.toggleAll());
return res;
})
.catch((err) => {
notification.error(`Unable to delete action "${ref}".`, {
err,

});
throw err;
}),
});
}

render() {
const { groups, filter, collapsed } = this.props;
const { id, section } = this.urlParams;
Expand Down Expand Up @@ -282,6 +303,7 @@ export default class ActionsPanel extends React.Component {
ref={(ref) => this._details = ref}
handleNavigate={(...args) => this.navigate(...args)}
handleRun={(...args) => this.handleRun(...args)}
handleDelete={(...arg) => this.handleDelete(...arg)}

id={id}
section={section}
Expand Down
26 changes: 26 additions & 0 deletions apps/st2-actions/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ const actionReducer = (state = {}, input) => {
};
}

case 'DELETE_ACTION': {
const { ref } = input;



switch(input.status) {
case 'success':
actions = [ ...actions ]
.filter(action => action.ref !== ref)
;
groups = makeGroups( actions, filter);

break;
case 'error':
break;
default:
break;
}

return {
...state,
actions,
groups,
};
}

case 'SET_FILTER': {
filter = input.filter;
groups = makeGroups(actions, filter);
Expand Down

0 comments on commit 9c578e2

Please sign in to comment.