Skip to content

Commit 9c578e2

Browse files
authored
Merge pull request #898 from pradnya-orchestral/Delete_Action/Workflow
Delete action/workflow
2 parents 79c7eba + 7f5b77c commit 9c578e2

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

apps/st2-actions/actions-details.component.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default class ActionsDetails extends React.Component {
5757
static propTypes = {
5858
handleNavigate: PropTypes.func.isRequired,
5959
handleRun: PropTypes.func.isRequired,
60+
handleDelete: PropTypes.func.isRequired,
6061

6162
id: PropTypes.string,
6263
section: PropTypes.string,
@@ -127,8 +128,6 @@ export default class ActionsDetails extends React.Component {
127128
}
128129
}
129130

130-
131-
132131
componentDidUpdate(prevProps) {
133132
const { id } = this.props;
134133
if (id && id !== prevProps.id) {
@@ -242,6 +241,15 @@ export default class ActionsDetails extends React.Component {
242241
return this.props.handleRun(...args);
243242
}
244243

244+
handleDelete (ref) {
245+
const { id } = this.props;
246+
247+
if (!window.confirm(`You are about to delete the action "${id}". This operation is irreversible. Are you sure?`)) {
248+
return undefined;
249+
}
250+
return this.props.handleDelete(id);
251+
}
252+
245253
render() {
246254
const { section, action, executions, entrypoint } = this.props;
247255
if (!action) {
@@ -281,6 +289,8 @@ export default class ActionsDetails extends React.Component {
281289
/>
282290
<Button flat value="Preview" onClick={() => this.handleToggleRunPreview()} />
283291
<DetailsToolbarSeparator />
292+
<Button className="st2-forms__button st2-details__toolbar-button" value="Delete" onClick={() => this.handleDelete()} />
293+
284294
{ action.runner_type === 'mistral-v2' || action.runner_type === 'orquesta' ? (
285295
<Link
286296
target="_blank"

apps/st2-actions/actions-panel.component.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import './style.css';
5555
return { collapsed, ...props };
5656
}, (dispatch, props) => {
5757
const { uid } = props;
58-
5958
return {
6059
onToggle: () => store.dispatch(flexActions.toggle(uid)),
6160
};
@@ -116,7 +115,6 @@ export default class ActionsPanel extends React.Component {
116115
.then(() => {
117116
const { id } = this.urlParams;
118117
const { groups } = this.props;
119-
120118
if (id && groups && !groups.some(({ actions }) => actions.some(({ ref }) => ref === id))) {
121119
this.navigate({ id: false });
122120
}
@@ -128,8 +126,7 @@ export default class ActionsPanel extends React.Component {
128126
const {
129127
ref = get('groups[0].actions[0].ref', this.props),
130128
section = 'general',
131-
} = this.props.match.params;
132-
129+
} = this.props.match.params;
133130
return {
134131
id: ref,
135132
section,
@@ -211,6 +208,30 @@ export default class ActionsPanel extends React.Component {
211208
});
212209
}
213210

211+
handleDelete (ref) {
212+
return store.dispatch({
213+
type: 'DELETE_ACTION',
214+
ref,
215+
promise: api.request({
216+
method: 'delete',
217+
path: `/actions/${ref}`,
218+
})
219+
.then((res) => {
220+
notification.success(`Action "${ref}" has been deleted successfully.`);
221+
this.navigate({ id: null });
222+
store.dispatch(flexActions.toggleAll());
223+
return res;
224+
})
225+
.catch((err) => {
226+
notification.error(`Unable to delete action "${ref}".`, {
227+
err,
228+
229+
});
230+
throw err;
231+
}),
232+
});
233+
}
234+
214235
render() {
215236
const { groups, filter, collapsed } = this.props;
216237
const { id, section } = this.urlParams;
@@ -282,6 +303,7 @@ export default class ActionsPanel extends React.Component {
282303
ref={(ref) => this._details = ref}
283304
handleNavigate={(...args) => this.navigate(...args)}
284305
handleRun={(...args) => this.handleRun(...args)}
306+
handleDelete={(...arg) => this.handleDelete(...arg)}
285307

286308
id={id}
287309
section={section}

apps/st2-actions/store.js

+26
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,32 @@ const actionReducer = (state = {}, input) => {
154154
};
155155
}
156156

157+
case 'DELETE_ACTION': {
158+
const { ref } = input;
159+
160+
161+
162+
switch(input.status) {
163+
case 'success':
164+
actions = [ ...actions ]
165+
.filter(action => action.ref !== ref)
166+
;
167+
groups = makeGroups( actions, filter);
168+
169+
break;
170+
case 'error':
171+
break;
172+
default:
173+
break;
174+
}
175+
176+
return {
177+
...state,
178+
actions,
179+
groups,
180+
};
181+
}
182+
157183
case 'SET_FILTER': {
158184
filter = input.filter;
159185
groups = makeGroups(actions, filter);

0 commit comments

Comments
 (0)