forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archived-workflow-filters.tsx
207 lines (197 loc) · 9.12 KB
/
archived-workflow-filters.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
import * as React from 'react';
import DatePicker from 'react-datepicker';
import * as models from '../../../../models';
import {CheckboxFilter} from '../../../shared/components/checkbox-filter/checkbox-filter';
import {InputFilter} from '../../../shared/components/input-filter';
import {NamespaceFilter} from '../../../shared/components/namespace-filter';
import {TagsInput} from '../../../shared/components/tags-input/tags-input';
import {services} from '../../../shared/services';
import 'react-datepicker/dist/react-datepicker.css';
require('./archived-workflow-filters.scss');
interface ArchivedWorkflowFilterProps {
workflows: models.Workflow[];
namespace: string;
name: string;
namePrefix: string;
phaseItems: string[];
selectedPhases: string[];
selectedLabels: string[];
minStartedAt?: Date;
maxStartedAt?: Date;
onChange: (namespace: string, name: string, namePrefix: string, selectedPhases: string[], labels: string[], minStartedAt: Date, maxStartedAt: Date) => void;
}
interface State {
labels: string[];
}
export class ArchivedWorkflowFilters extends React.Component<ArchivedWorkflowFilterProps, State> {
constructor(props: ArchivedWorkflowFilterProps) {
super(props);
this.state = {
labels: []
};
}
public componentDidMount(): void {
this.fetchArchivedWorkflowsLabelKeys();
}
public render() {
return (
<div className='wf-filters-container'>
<div className='row'>
<div className='columns small-2 xlarge-12'>
<p className='wf-filters-container__title'>Namespace</p>
<NamespaceFilter
value={this.props.namespace}
onChange={ns => {
this.props.onChange(
ns,
this.props.name,
this.props.namePrefix,
this.props.selectedPhases,
this.props.selectedLabels,
this.props.minStartedAt,
this.props.maxStartedAt
);
}}
/>
</div>
<div className='columns small-2 xlarge-12'>
<p className='wf-filters-container__title'>Name</p>
<InputFilter
value={this.props.name}
name='wfname'
onChange={wfname => {
this.props.onChange(
this.props.namespace,
wfname,
this.props.namePrefix,
this.props.selectedPhases,
this.props.selectedLabels,
this.props.minStartedAt,
this.props.maxStartedAt
);
}}
/>
</div>
<div className='columns small-2 xlarge-12'>
<p className='wf-filters-container__title'>Name Prefix</p>
<InputFilter
value={this.props.namePrefix}
name='wfnamePrefix'
onChange={wfnamePrefix => {
this.props.onChange(
this.props.namespace,
this.props.name,
wfnamePrefix,
this.props.selectedPhases,
this.props.selectedLabels,
this.props.minStartedAt,
this.props.maxStartedAt
);
}}
/>
</div>
<div className='columns small-2 xlarge-12'>
<p className='wf-filters-container__title'>Labels</p>
<TagsInput
placeholder=''
autocomplete={this.state.labels}
sublistQuery={this.fetchArchivedWorkflowsLabels}
tags={this.props.selectedLabels}
onChange={tags => {
this.props.onChange(
this.props.namespace,
this.props.name,
this.props.namePrefix,
this.props.selectedPhases,
tags,
this.props.minStartedAt,
this.props.maxStartedAt
);
}}
/>
</div>
<div className='columns small-3 xlarge-12'>
<p className='wf-filters-container__title'>Phases</p>
<CheckboxFilter
selected={this.props.selectedPhases}
onChange={selected => {
this.props.onChange(
this.props.namespace,
this.props.name,
this.props.namePrefix,
selected,
this.props.selectedLabels,
this.props.minStartedAt,
this.props.maxStartedAt
);
}}
items={this.getPhaseItems(this.props.workflows)}
type='phase'
/>
</div>
<div className='columns small-5 xlarge-12'>
<p className='wf-filters-container__title'>Started Time</p>
<DatePicker
selected={this.props.minStartedAt}
onChange={date => {
this.props.onChange(
this.props.namespace,
this.props.name,
this.props.namePrefix,
this.props.selectedPhases,
this.props.selectedLabels,
date,
this.props.maxStartedAt
);
}}
placeholderText='From'
dateFormat='dd MMM yyyy'
todayButton='Today'
className='argo-field argo-textarea'
/>
<DatePicker
selected={this.props.maxStartedAt}
onChange={date => {
this.props.onChange(
this.props.namespace,
this.props.name,
this.props.namePrefix,
this.props.selectedPhases,
this.props.selectedLabels,
this.props.minStartedAt,
date
);
}}
placeholderText='To'
dateFormat='dd MMM yyyy'
todayButton='Today'
className='argo-field argo-textarea'
/>
</div>
</div>
</div>
);
}
private getPhaseItems(workflows: models.Workflow[]) {
const phasesMap = new Map<string, number>();
this.props.phaseItems.forEach(value => phasesMap.set(value, 0));
workflows.filter(wf => wf.status.phase).forEach(wf => phasesMap.set(wf.status.phase, (phasesMap.get(wf.status.phase) || 0) + 1));
const results = new Array<{name: string; count: number}>();
phasesMap.forEach((val, key) => {
results.push({name: key, count: val});
});
return results;
}
private fetchArchivedWorkflowsLabelKeys(): void {
services.archivedWorkflows.listLabelKeys().then(list => {
this.setState({
labels: list.items.sort((a, b) => a.localeCompare(b)) || []
});
});
}
private fetchArchivedWorkflowsLabels(key: string): Promise<any> {
return services.archivedWorkflows.listLabelValues(key).then(list => {
return list.items.map(i => key + '=' + i).sort((a, b) => a.localeCompare(b));
});
}
}