forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster-workflow-template-details.tsx
147 lines (134 loc) · 5.65 KB
/
cluster-workflow-template-details.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import {NotificationType, Page} from 'argo-ui';
import {SlidingPanel} from 'argo-ui/src/index';
import * as React from 'react';
import {RouteComponentProps} from 'react-router';
import * as models from '../../../../models';
import {uiUrl} from '../../../shared/base';
import {BasePage} from '../../../shared/components/base-page';
import {Loading} from '../../../shared/components/loading';
import {ResourceSubmit} from '../../../shared/components/resource-submit';
import {Consumer} from '../../../shared/context';
import {services} from '../../../shared/services';
import {ClusterWorkflowTemplateSummaryPanel} from '../cluster-workflow-template-summary-panel';
require('../../../workflows/components/workflow-details/workflow-details.scss');
interface State {
template?: models.ClusterWorkflowTemplate;
error?: Error;
}
export class ClusterWorkflowTemplateDetails extends BasePage<RouteComponentProps<any>, State> {
private get name() {
return this.props.match.params.name;
}
private get sidePanel() {
return this.queryParam('sidePanel');
}
private set sidePanel(sidePanel) {
this.setQueryParams({sidePanel});
}
constructor(props: RouteComponentProps<any>, context: any) {
super(props, context);
this.state = {};
}
public componentDidMount(): void {
services.clusterWorkflowTemplate
.get(this.name)
.then(template => {
this.setState({template});
})
.catch(error => this.setState({error}));
}
public render() {
if (this.state.error !== undefined) {
throw this.state.error;
}
return (
<Consumer>
{ctx => (
<Page
title='Cluster Workflow Template Details'
toolbar={{
actionMenu: {
items: [
{
title: 'Submit',
iconClassName: 'fa fa-plus',
action: () => (this.sidePanel = 'new')
},
{
title: 'Delete',
iconClassName: 'fa fa-trash',
action: () => this.deleteClusterWorkflowTemplate()
}
]
},
breadcrumbs: [
{
title: 'Cluster Workflow Template',
path: uiUrl('cluster-workflow-templates')
},
{title: this.name}
]
}}>
<div className='argo-container'>
<div className='workflow-details__content'>{this.renderClusterWorkflowTemplate()}</div>
</div>
{this.state.template && (
<SlidingPanel isShown={this.sidePanel !== null} onClose={() => (this.sidePanel = null)}>
<ResourceSubmit<models.Workflow>
resourceName={'Workflow'}
defaultResource={this.getWorkflow(this.state.template)}
onSubmit={wfValue => {
return services.workflows
.create(wfValue, wfValue.metadata.namespace)
.then(workflow => ctx.navigation.goto(uiUrl(`workflows/${workflow.metadata.namespace}/${workflow.metadata.name}`)));
}}
/>
</SlidingPanel>
)}
</Page>
)}
</Consumer>
);
}
private renderClusterWorkflowTemplate() {
if (!this.state.template) {
return <Loading />;
}
return <ClusterWorkflowTemplateSummaryPanel template={this.state.template} onChange={template => this.setState({template})} onError={error => this.setState({error})} />;
}
private deleteClusterWorkflowTemplate() {
if (!confirm('Are you sure you want to delete this cluster workflow template?\nThere is no undo.')) {
return;
}
services.clusterWorkflowTemplate
.delete(this.name)
.catch(e => {
this.appContext.apis.notifications.show({
content: 'Failed to delete cluster workflow template ' + e,
type: NotificationType.Error
});
})
.then(() => {
document.location.href = uiUrl('cluster-workflow-templates');
});
}
private getWorkflow(template: models.ClusterWorkflowTemplate): models.Workflow {
return {
metadata: {
generateName: template.metadata.name + '-',
namespace: '<enter the namespace>'
},
spec: {
entrypoint: template.spec.templates[0].name,
templates: template.spec.templates.map(t => ({
name: t.name,
templateRef: {
name: template.metadata.name,
template: t.name,
clusterscope: true,
}
}))
}
};
}
}