-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
cron-workflow-details.tsx
176 lines (167 loc) · 7.75 KB
/
cron-workflow-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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import {NotificationType, Page, SlidingPanel} from 'argo-ui';
import * as React from 'react';
import {useContext, useEffect, useState} from 'react';
import {RouteComponentProps} from 'react-router';
import {CronWorkflow} from '../../../../models';
import {uiUrl} from '../../../shared/base';
import {ErrorNotice} from '../../../shared/components/error-notice';
import {Loading} from '../../../shared/components/loading';
import {Context} from '../../../shared/context';
import {historyUrl} from '../../../shared/history';
import {services} from '../../../shared/services';
import {useQueryParams} from '../../../shared/use-query-params';
import {WidgetGallery} from '../../../widgets/widget-gallery';
import {CronWorkflowEditor} from '../cron-workflow-editor';
require('../../../workflows/components/workflow-details/workflow-details.scss');
export const CronWorkflowDetails = ({match, location, history}: RouteComponentProps<any>) => {
// boiler-plate
const {navigation, notifications, popup} = useContext(Context);
const queryParams = new URLSearchParams(location.search);
const [namespace] = useState(match.params.namespace);
const [name] = useState(match.params.name);
const [sidePanel, setSidePanel] = useState(queryParams.get('sidePanel'));
const [tab, setTab] = useState(queryParams.get('tab'));
const [cronWorkflow, setCronWorkflow] = useState<CronWorkflow>();
const [edited, setEdited] = useState(false);
const [error, setError] = useState<Error>();
useEffect(
useQueryParams(history, p => {
setSidePanel(p.get('sidePanel'));
setTab(p.get('tab'));
}),
[history]
);
useEffect(
() =>
history.push(
historyUrl('cron-workflows/{namespace}/{name}', {
namespace,
name,
sidePanel,
tab
})
),
[namespace, name, sidePanel, tab]
);
useEffect(() => {
services.cronWorkflows
.get(name, namespace)
.then(setCronWorkflow)
.then(() => setEdited(false))
.then(() => setError(null))
.catch(setError);
}, [namespace, name]);
useEffect(() => setEdited(true), [cronWorkflow]);
const suspendButton =
cronWorkflow && !cronWorkflow.spec.suspend
? {
title: 'Suspend',
iconClassName: 'fa fa-pause',
action: () =>
services.cronWorkflows
.suspend(name, namespace)
.then(setCronWorkflow)
.then(() => setEdited(false))
.then(() => setError(null))
.catch(setError),
disabled: !cronWorkflow || edited
}
: {
title: 'Resume',
iconClassName: 'fa fa-play',
action: () =>
services.cronWorkflows
.resume(name, namespace)
.then(setCronWorkflow)
.then(() => setEdited(false))
.then(() => setError(null))
.catch(setError),
disabled: !cronWorkflow || !cronWorkflow.spec.suspend || edited
};
return (
<Page
title='Cron Workflow Details'
toolbar={{
breadcrumbs: [
{title: 'Cron Workflows', path: uiUrl('cron-workflows')},
{title: namespace, path: uiUrl('cron-workflows/' + namespace)},
{title: name, path: uiUrl('cron-workflows/' + namespace + '/' + name)}
],
actionMenu: {
items: [
{
title: 'Submit',
iconClassName: 'fa fa-plus',
disabled: edited,
action: () =>
services.workflows
.submit('cronwf', name, namespace)
.then(wf => navigation.goto(uiUrl(`workflows/${wf.metadata.namespace}/${wf.metadata.name}`)))
.then(() => setError(null))
.catch(setError)
},
{
title: 'Update',
iconClassName: 'fa fa-save',
disabled: !edited,
action: () => {
// magic - we get the latest from the server and then apply the changes from the rendered version to this
return services.cronWorkflows
.get(name, namespace)
.then(latest =>
services.cronWorkflows.update(
{
...latest,
spec: cronWorkflow.spec,
metadata: {...cronWorkflow.metadata, resourceVersion: latest.metadata.resourceVersion}
},
cronWorkflow.metadata.name,
cronWorkflow.metadata.namespace
)
)
.then(setCronWorkflow)
.then(() => notifications.show({content: 'Updated', type: NotificationType.Success}))
.then(() => setError(null))
.then(() => setEdited(false))
.catch(setError);
}
},
suspendButton,
{
title: 'Delete',
iconClassName: 'fa fa-trash',
disabled: edited,
action: () => {
popup.confirm('confirm', 'Are you sure you want to delete this cron workflow?').then(yes => {
if (yes) {
services.cronWorkflows
.delete(name, namespace)
.then(() => navigation.goto(uiUrl('cron-workflows/' + namespace)))
.then(() => setError(null))
.catch(setError);
}
});
}
},
{
title: 'Share',
iconClassName: 'fa fa-share-alt',
action: () => setSidePanel('share')
}
]
}
}}>
<>
<ErrorNotice error={error} />
{!cronWorkflow ? (
<Loading />
) : (
<CronWorkflowEditor cronWorkflow={cronWorkflow} onChange={setCronWorkflow} onError={setError} selectedTabKey={tab} onTabSelected={setTab} />
)}
<SlidingPanel isShown={!!sidePanel} onClose={() => setSidePanel(null)}>
{sidePanel === 'share' && <WidgetGallery namespace={namespace} label={'workflows.argoproj.io/cron-workflow=' + name} />}
</SlidingPanel>
</>
</Page>
);
};