Skip to content

Commit 5e60a65

Browse files
authored
Merge pull request #5 from merenbach/support-force-delete
Support cascading delete
2 parents 4330130 + 92125c5 commit 5e60a65

File tree

4 files changed

+52
-34
lines changed

4 files changed

+52
-34
lines changed

src/app/applications/components/application-details/application-details.tsx

+5-14
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class ApplicationDetails extends React.Component<RouteComponentProps<{ na
130130
}, {
131131
className: 'icon fa fa-times-circle',
132132
title: 'Delete',
133-
action: () => this.deleteApplication(true),
133+
action: () => this.deleteApplication(),
134134
}],
135135
} }}>
136136
{this.state.application && <ApplicationStatusPanel application={this.state.application}
@@ -322,19 +322,10 @@ export class ApplicationDetails extends React.Component<RouteComponentProps<{ na
322322
}
323323
}
324324

325-
private async deleteApplication(force: boolean) {
326-
const confirmed = await this.appContext.apis.popup.confirm('Delete application', `Are your sure you want to delete application '${this.props.match.params.name}'?`);
327-
if (confirmed) {
328-
try {
329-
await services.applications.delete(this.props.match.params.name, force);
330-
this.appContext.apis.navigation.goto('/applications');
331-
} catch (e) {
332-
this.appContext.apis.notifications.show({
333-
content: <ErrorNotification title='Unable to delete application' e={e}/>,
334-
type: NotificationType.Error,
335-
});
336-
}
337-
}
325+
private async deleteApplication() {
326+
AppUtils.deleteApplication(this.props.match.params.name, this.appContext, () => {
327+
this.appContext.apis.navigation.goto('/applications');
328+
});
338329
}
339330

340331
private getResourceLabels(resource: appModels.ResourceNode | appModels.ResourceState): string[] {

src/app/applications/components/applications-list/applications-list.tsx

+8-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { AppContext } from '../../../shared/context';
1010
import * as models from '../../../shared/models';
1111
import { services } from '../../../shared/services';
1212
import { ApplicationCreationWizardContainer, NewAppParams, WizardStepState } from '../application-creation-wizard/application-creation-wizard';
13-
import { ComparisonStatusIcon, HealthStatusIcon } from '../utils';
13+
import * as AppUtils from '../utils';
1414

1515
require('./applications-list.scss');
1616

@@ -132,13 +132,13 @@ export class ApplicationsList extends React.Component<Props, State> {
132132
<div className='row'>
133133
<div className='columns small-3'>Status:</div>
134134
<div className='columns small-9'>
135-
<ComparisonStatusIcon status={app.status.comparisonResult.status}/> {app.status.comparisonResult.status}
135+
<AppUtils.ComparisonStatusIcon status={app.status.comparisonResult.status}/> {app.status.comparisonResult.status}
136136
</div>
137137
</div>
138138
<div className='row'>
139139
<div className='columns small-3'>Health:</div>
140140
<div className='columns small-9'>
141-
<HealthStatusIcon state={app.status.health}/> {app.status.health.status}
141+
<AppUtils.HealthStatusIcon state={app.status.health}/> {app.status.health.status}
142142
</div>
143143
</div>
144144
<div className='row'>
@@ -167,7 +167,7 @@ export class ApplicationsList extends React.Component<Props, State> {
167167
<button className='argo-button argo-button--base-o'>Actions <i className='fa fa-caret-down'/></button>
168168
} items={[
169169
{ title: 'Sync', action: () => this.syncApplication(app.metadata.name, 'HEAD') },
170-
{ title: 'Delete', action: () => this.deleteApplication(app.metadata.name, false) },
170+
{ title: 'Delete', action: () => this.deleteApplication(app.metadata.name) },
171171
]} />
172172
</div>
173173
</div>
@@ -263,18 +263,9 @@ export class ApplicationsList extends React.Component<Props, State> {
263263
}
264264
}
265265

266-
private async deleteApplication(appName: string, force: boolean) {
267-
const confirmed = await this.appContext.apis.popup.confirm('Delete application', `Are your sure you want to delete application '${appName}'?`);
268-
if (confirmed) {
269-
try {
270-
await services.applications.delete(appName, force);
271-
this.appContext.router.history.push('/applications');
272-
} catch (e) {
273-
this.appContext.apis.notifications.show({
274-
content: <ErrorNotification title='Unable to delete application' e={e}/>,
275-
type: NotificationType.Error,
276-
});
277-
}
278-
}
266+
private async deleteApplication(appName: string) {
267+
AppUtils.deleteApplication(appName, this.appContext, () => {
268+
this.appContext.router.history.push('/applications');
269+
});
279270
}
280271
}

src/app/applications/components/utils.tsx

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
import * as React from 'react';
22

3-
import { ARGO_FAILED_COLOR, ARGO_RUNNING_COLOR, ARGO_SUCCESS_COLOR } from '../../shared/components';
3+
import { Checkbox, NotificationType } from 'argo-ui';
4+
import { ARGO_FAILED_COLOR, ARGO_RUNNING_COLOR, ARGO_SUCCESS_COLOR, ErrorNotification } from '../../shared/components';
5+
import { AppContext } from '../../shared/context';
46
import * as appModels from '../../shared/models';
7+
import { services } from '../../shared/services';
8+
9+
export async function deleteApplication(appName: string, context: AppContext, success: () => void) {
10+
let cascade = false;
11+
const confirmationForm = class extends React.Component<{}, { cascade: boolean } > {
12+
constructor(props: any) {
13+
super(props);
14+
this.state = {cascade: false};
15+
}
16+
public render() {
17+
return (
18+
<div>
19+
<p>Are you sure you want to delete the application "{appName}"?</p>
20+
<p><Checkbox checked={this.state.cascade} onChange={(val) => this.setState({ cascade: val })} /> Cascade</p>
21+
</div>
22+
)
23+
}
24+
componentWillUnmount() {
25+
cascade = this.state.cascade;
26+
}
27+
};
28+
const confirmed = await context.apis.popup.confirm('Delete application', confirmationForm);
29+
if (confirmed) {
30+
try {
31+
await services.applications.delete(appName, cascade);
32+
success();
33+
} catch (e) {
34+
this.appContext.apis.notifications.show({
35+
content: <ErrorNotification title='Unable to delete application' e={e}/>,
36+
type: NotificationType.Error,
37+
});
38+
}
39+
}
40+
}
541

642
export const ComparisonStatusIcon = ({status}: { status: appModels.ComparisonStatus }) => {
743
let className = '';

src/app/shared/services/applications-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export class ApplicationsService {
2121
}).then((res) => this.parseAppFields(res.body));
2222
}
2323

24-
public delete(name: string, force: boolean): Promise<boolean> {
25-
return requests.delete(`/applications/${name}?force=${force}`).send({}).then(() => true);
24+
public delete(name: string, cascade: boolean): Promise<boolean> {
25+
return requests.delete(`/applications/${name}`).query({cascade}).send({}).then(() => true);
2626
}
2727

2828
public watch(query?: {name: string}): Observable<models.ApplicationWatchEvent> {

0 commit comments

Comments
 (0)