forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archived-workflow-list.tsx
340 lines (312 loc) · 14.1 KB
/
archived-workflow-list.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import {Page} from 'argo-ui';
import * as React from 'react';
import {Link, RouteComponentProps} from 'react-router-dom';
import * as models from '../../../../models';
import {Workflow} from '../../../../models';
import {uiUrl} from '../../../shared/base';
import {BasePage} from '../../../shared/components/base-page';
import {ErrorNotice} from '../../../shared/components/error-notice';
import {Loading} from '../../../shared/components/loading';
import {PaginationPanel} from '../../../shared/components/pagination-panel';
import {PhaseIcon} from '../../../shared/components/phase-icon';
import {Timestamp} from '../../../shared/components/timestamp';
import {ZeroState} from '../../../shared/components/zero-state';
import {formatDuration, wfDuration} from '../../../shared/duration';
import {Pagination, parseLimit} from '../../../shared/pagination';
import {ScopedLocalStorage} from '../../../shared/scoped-local-storage';
import {services} from '../../../shared/services';
import {Utils} from '../../../shared/utils';
import {ArchivedWorkflowFilters} from '../archived-workflow-filters/archived-workflow-filters';
interface State {
pagination: Pagination;
namespace: string;
name: string;
namePrefix: string;
selectedPhases: string[];
selectedLabels: string[];
minStartedAt?: Date;
maxStartedAt?: Date;
workflows?: Workflow[];
error?: Error;
deep: boolean;
}
const defaultPaginationLimit = 10;
export class ArchivedWorkflowList extends BasePage<RouteComponentProps<any>, State> {
private storage: ScopedLocalStorage;
constructor(props: RouteComponentProps<any>, context: any) {
super(props, context);
this.storage = new ScopedLocalStorage('ArchiveListOptions');
const savedOptions = this.storage.getItem('options', {
pagination: {limit: defaultPaginationLimit},
selectedPhases: [],
selectedLabels: []
} as State);
const phaseQueryParam = this.queryParams('phase');
const labelQueryParam = this.queryParams('label');
this.state = {
pagination: {offset: this.queryParam('offset'), limit: parseLimit(this.queryParam('limit')) || savedOptions.pagination.limit},
namespace: Utils.getNamespace(this.props.match.params.namespace) || '',
name: this.queryParams('name').toString() || '',
namePrefix: this.queryParams('namePrefix').toString() || '',
selectedPhases: phaseQueryParam.length > 0 ? phaseQueryParam : savedOptions.selectedPhases,
selectedLabels: labelQueryParam.length > 0 ? labelQueryParam : savedOptions.selectedLabels,
minStartedAt: this.parseTime(this.queryParam('minStartedAt')) || this.lastMonth(),
maxStartedAt: this.parseTime(this.queryParam('maxStartedAt')) || this.nextDay(),
deep: this.queryParam('deep') === 'true'
};
}
public componentDidMount(): void {
this.fetchArchivedWorkflows(
this.state.namespace,
this.state.name,
this.state.namePrefix,
this.state.selectedPhases,
this.state.selectedLabels,
this.state.minStartedAt,
this.state.maxStartedAt,
this.state.pagination
);
services.info.collectEvent('openedArchivedWorkflowList').then();
}
public componentDidUpdate(): void {
if (this.state.deep === true && this.state.workflows && this.state.workflows.length === 1) {
const workflow = this.state.workflows[0];
const url = '/archived-workflows/' + workflow.metadata.namespace + '/' + (workflow.metadata.uid || '');
this.props.history.push(url);
}
}
public render() {
return (
<Page
title='Archived Workflows'
toolbar={{
breadcrumbs: [
{title: 'Archived Workflows', path: uiUrl('archived-workflows')},
{title: this.state.namespace, path: uiUrl('archived-workflows/' + this.state.namespace)}
]
}}>
<div className='row'>
<div className='columns small-12 xlarge-2'>
<div>
<ArchivedWorkflowFilters
workflows={this.state.workflows || []}
namespace={this.state.namespace}
name={this.state.name}
namePrefix={this.state.namePrefix}
phaseItems={Object.values([models.NODE_PHASE.SUCCEEDED, models.NODE_PHASE.FAILED, models.NODE_PHASE.ERROR])}
selectedPhases={this.state.selectedPhases}
selectedLabels={this.state.selectedLabels}
minStartedAt={this.state.minStartedAt}
maxStartedAt={this.state.maxStartedAt}
onChange={(namespace, name, namePrefix, selectedPhases, selectedLabels, minStartedAt, maxStartedAt) =>
this.changeFilters(namespace, name, namePrefix, selectedPhases, selectedLabels, minStartedAt, maxStartedAt, {
limit: this.state.pagination.limit
})
}
/>
</div>
</div>
<div className='columns small-12 xlarge-10'>{this.renderWorkflows()}</div>
</div>
</Page>
);
}
private lastMonth() {
const dt = new Date();
dt.setMonth(dt.getMonth() - 1);
dt.setHours(0, 0, 0, 0);
return dt;
}
private nextDay() {
const dt = new Date();
dt.setDate(dt.getDate() + 1);
dt.setHours(0, 0, 0, 0);
return dt;
}
private parseTime(dateStr: string) {
if (dateStr != null) {
return new Date(dateStr);
}
}
private changeFilters(
namespace: string,
name: string,
namePrefix: string,
selectedPhases: string[],
selectedLabels: string[],
minStartedAt: Date,
maxStartedAt: Date,
pagination: Pagination
) {
this.fetchArchivedWorkflows(namespace, name, namePrefix, selectedPhases, selectedLabels, minStartedAt, maxStartedAt, pagination);
}
private get filterParams() {
const params = new URLSearchParams();
if (this.state.selectedPhases) {
this.state.selectedPhases.forEach(phase => {
params.append('phase', phase);
});
}
if (this.state.selectedLabels) {
this.state.selectedLabels.forEach(label => {
params.append('label', label);
});
}
if (this.state.name) {
params.append('name', this.state.name);
}
if (this.state.namePrefix) {
params.append('namePrefix', this.state.namePrefix);
}
params.append('minStartedAt', this.state.minStartedAt.toISOString());
params.append('maxStartedAt', this.state.maxStartedAt.toISOString());
if (this.state.pagination.offset) {
params.append('offset', this.state.pagination.offset);
}
if (this.state.pagination.limit !== null && this.state.pagination.limit !== defaultPaginationLimit) {
params.append('limit', this.state.pagination.limit.toString());
}
return params;
}
private filterStateObject(state: State, whitelistedStates: string[], blacklistedStates: string[]) {
const filteredState: State = {} as State;
if (whitelistedStates.includes('pagination') || !blacklistedStates.includes('pagination')) {
filteredState.pagination = state.pagination;
}
if (whitelistedStates.includes('namespace') || !blacklistedStates.includes('namespace')) {
filteredState.namespace = state.namespace;
}
if (whitelistedStates.includes('name') || !blacklistedStates.includes('name')) {
filteredState.name = state.name;
}
if (whitelistedStates.includes('namePrefix') || !blacklistedStates.includes('namePrefix')) {
filteredState.namePrefix = state.namePrefix;
}
if (whitelistedStates.includes('selectedPhases') || !blacklistedStates.includes('selectedPhases')) {
filteredState.selectedPhases = state.selectedPhases;
}
if (whitelistedStates.includes('selectedLabels') || !blacklistedStates.includes('selectedLabels')) {
filteredState.selectedLabels = state.selectedLabels;
}
if (whitelistedStates.includes('minStartedAt') || !blacklistedStates.includes('minStartedAt')) {
filteredState.minStartedAt = state.minStartedAt;
}
if (whitelistedStates.includes('maxStartedAt') || !blacklistedStates.includes('maxStartedAt')) {
filteredState.maxStartedAt = state.maxStartedAt;
}
if (whitelistedStates.includes('error') || !blacklistedStates.includes('error')) {
filteredState.error = state.error;
}
if (whitelistedStates.includes('deep') || !blacklistedStates.includes('deep')) {
filteredState.deep = state.deep;
}
return filteredState;
}
private saveHistory() {
this.storage.setItem('options', this.filterStateObject(this.state, [], ['workflows']), {} as State);
const newNamespace = Utils.managedNamespace ? '' : this.state.namespace;
this.url = uiUrl('archived-workflows' + (newNamespace ? '/' + newNamespace : '') + '?' + this.filterParams.toString());
Utils.currentNamespace = this.state.namespace;
}
private fetchArchivedWorkflows(
namespace: string,
name: string,
namePrefix: string,
selectedPhases: string[],
selectedLabels: string[],
minStartedAt: Date,
maxStartedAt: Date,
pagination: Pagination
): void {
services.archivedWorkflows
.list(namespace, name, namePrefix, selectedPhases, selectedLabels, minStartedAt, maxStartedAt, pagination)
.then(list => {
this.setState(
{
error: null,
namespace,
name,
namePrefix,
workflows: list.items || [],
selectedPhases,
selectedLabels,
minStartedAt,
maxStartedAt,
pagination: {
limit: pagination.limit,
offset: pagination.offset,
nextOffset: list.metadata.continue
}
},
this.saveHistory
);
})
.catch(error => this.setState({error}));
}
private renderWorkflows() {
if (this.state.error) {
return <ErrorNotice error={this.state.error} />;
}
if (!this.state.workflows) {
return <Loading />;
}
const learnMore = <a href='https://argoproj.github.io/argo-workflows/workflow-archive/'>Learn more</a>;
if (this.state.workflows.length === 0) {
return (
<ZeroState title='No archived workflows'>
<p>To add entries to the archive you must enable archiving in configuration. Records are created in the archive on workflow completion.</p>
<p>{learnMore}.</p>
</ZeroState>
);
}
return (
<>
<div className='argo-table-list'>
<div className='row argo-table-list__head'>
<div className='columns small-1' />
<div className='columns small-3'>NAME</div>
<div className='columns small-2'>NAMESPACE</div>
<div className='columns small-2'>STARTED</div>
<div className='columns small-2'>FINISHED</div>
<div className='columns small-2'>DURATION</div>
</div>
{this.state.workflows.map(w => (
<Link className='row argo-table-list__row' key={`${w.metadata.uid}`} to={uiUrl(`archived-workflows/${w.metadata.namespace}/${w.metadata.uid}`)}>
<div className='columns small-1'>
<PhaseIcon value={w.status.phase} />
</div>
<div className='columns small-3'>{w.metadata.name}</div>
<div className='columns small-2'>{w.metadata.namespace}</div>
<div className='columns small-2'>
<Timestamp date={w.status.startedAt} />
</div>
<div className='columns small-2'>
<Timestamp date={w.status.finishedAt} />
</div>
<div className='columns small-2'>{formatDuration(wfDuration(w.status))}</div>
</Link>
))}
</div>
<PaginationPanel
onChange={pagination =>
this.changeFilters(
this.state.namespace,
this.state.name,
this.state.namePrefix,
this.state.selectedPhases,
this.state.selectedLabels,
this.state.minStartedAt,
this.state.maxStartedAt,
pagination
)
}
pagination={this.state.pagination}
numRecords={(this.state.workflows || []).length}
/>
<p>
<i className='fa fa-info-circle' /> Records are created in the archive when a workflow completes. {learnMore}.
</p>
</>
);
}
}