-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
Copy pathapplications-tiles.tsx
256 lines (243 loc) · 14.3 KB
/
applications-tiles.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
import {Tooltip} from 'argo-ui';
import * as classNames from 'classnames';
import * as React from 'react';
import {Key, KeybindingContext, NumKey, NumKeyToNumber, NumPadKey, useNav} from 'argo-ui/v2';
import {Cluster} from '../../../shared/components';
import {Consumer, Context} from '../../../shared/context';
import * as models from '../../../shared/models';
import {ApplicationURLs} from '../application-urls';
import * as AppUtils from '../utils';
import {OperationState} from '../utils';
require('./applications-tiles.scss');
export interface ApplicationTilesProps {
applications: models.Application[];
syncApplication: (appName: string) => any;
refreshApplication: (appName: string) => any;
deleteApplication: (appName: string) => any;
}
const useItemsPerContainer = (itemRef: any, containerRef: any): number => {
const [itemsPer, setItemsPer] = React.useState(0);
React.useEffect(() => {
const handleResize = () => {
let timeoutId: any;
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
timeoutId = null;
const itemWidth = itemRef.current ? itemRef.current.offsetWidth : -1;
const containerWidth = containerRef.current ? containerRef.current.offsetWidth : -1;
const curItemsPer = containerWidth > 0 && itemWidth > 0 ? Math.floor(containerWidth / itemWidth) : 1;
if (curItemsPer !== itemsPer) {
setItemsPer(curItemsPer);
}
}, 1000);
};
window.addEventListener('resize', handleResize);
handleResize();
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);
return itemsPer || 1;
};
export const ApplicationTiles = ({applications, syncApplication, refreshApplication, deleteApplication}: ApplicationTilesProps) => {
const [selectedApp, navApp, reset] = useNav(applications.length);
const ctxh = React.useContext(Context);
const appRef = {ref: React.useRef(null), set: false};
const appContainerRef = React.useRef(null);
const appsPerRow = useItemsPerContainer(appRef.ref, appContainerRef);
const {useKeybinding} = React.useContext(KeybindingContext);
useKeybinding({keys: Key.RIGHT, action: () => navApp(1)});
useKeybinding({keys: Key.LEFT, action: () => navApp(-1)});
useKeybinding({keys: Key.DOWN, action: () => navApp(appsPerRow)});
useKeybinding({keys: Key.UP, action: () => navApp(-1 * appsPerRow)});
useKeybinding({
keys: Key.ENTER,
action: () => {
if (selectedApp > -1) {
ctxh.navigation.goto(`/applications/${applications[selectedApp].metadata.name}`);
return true;
}
return false;
}
});
useKeybinding({
keys: Key.ESCAPE,
action: () => {
if (selectedApp > -1) {
reset();
return true;
}
return false;
}
});
useKeybinding({
keys: Object.values(NumKey) as NumKey[],
action: n => {
reset();
return navApp(NumKeyToNumber(n));
}
});
useKeybinding({
keys: Object.values(NumPadKey) as NumPadKey[],
action: n => {
reset();
return navApp(NumKeyToNumber(n));
}
});
return (
<Consumer>
{ctx => (
<div className='applications-tiles argo-table-list argo-table-list--clickable row small-up-1 medium-up-2 large-up-3 xxxlarge-up-4' ref={appContainerRef}>
{applications.map((app, i) => (
<div key={app.metadata.name} className='column column-block'>
<div
ref={appRef.set ? null : appRef.ref}
className={`argo-table-list__row applications-list__entry applications-list__entry--health-${app.status.health.status} ${
selectedApp === i ? 'applications-tiles__selected' : ''
}`}>
<div className='row' onClick={e => ctx.navigation.goto(`/applications/${app.metadata.name}`, {}, {event: e})}>
<div className={`columns small-12 applications-list__info qe-applications-list-${app.metadata.name}`}>
<div className='applications-list__external-link'>
<ApplicationURLs urls={app.status.summary.externalURLs} />
</div>
<div className='row'>
<div className='columns small-12'>
<i className={'icon argo-icon-' + (app.spec.source.chart != null ? 'helm' : 'git')} />
<span className='applications-list__title'>{app.metadata.name}</span>
</div>
</div>
<div className='row'>
<div className='columns small-3' title='Project:'>
Project:
</div>
<div className='columns small-9'>{app.spec.project}</div>
</div>
<div className='row'>
<div className='columns small-3' title='Labels:'>
Labels:
</div>
<div className='columns small-9'>
<Tooltip
zIndex={4}
content={
<div>
{Object.keys(app.metadata.labels || {})
.map(label => ({label, value: app.metadata.labels[label]}))
.map(item => (
<div key={item.label}>
{item.label}={item.value}
</div>
))}
</div>
}>
<span>
{Object.keys(app.metadata.labels || {})
.map(label => `${label}=${app.metadata.labels[label]}`)
.join(', ')}
</span>
</Tooltip>
</div>
</div>
<div className='row'>
<div className='columns small-3' title='Status:'>
Status:
</div>
<div className='columns small-9' qe-id='applications-tiles-health-status'>
<AppUtils.HealthStatusIcon state={app.status.health} /> {app.status.health.status}
<AppUtils.ComparisonStatusIcon status={app.status.sync.status} /> {app.status.sync.status}
<OperationState app={app} quiet={true} />
</div>
</div>
<div className='row'>
<div className='columns small-3' title='Repository:'>
Repository:
</div>
<div className='columns small-9'>
<Tooltip content={app.spec.source.repoURL} zIndex={4}>
<span>{app.spec.source.repoURL}</span>
</Tooltip>
</div>
</div>
<div className='row'>
<div className='columns small-3' title='Target Revision:'>
Target Revision:
</div>
<div className='columns small-9'>{app.spec.source.targetRevision}</div>
</div>
{app.spec.source.path && (
<div className='row'>
<div className='columns small-3' title='Path:'>
Path:
</div>
<div className='columns small-9'>{app.spec.source.path}</div>
</div>
)}
{app.spec.source.chart && (
<div className='row'>
<div className='columns small-3' title='Chart:'>
Chart:
</div>
<div className='columns small-9'>{app.spec.source.chart}</div>
</div>
)}
<div className='row'>
<div className='columns small-3' title='Destination:'>
Destination:
</div>
<div className='columns small-9'>
<Cluster server={app.spec.destination.server} name={app.spec.destination.name} />
</div>
</div>
<div className='row'>
<div className='columns small-3' title='Namespace:'>
Namespace:
</div>
<div className='columns small-9'>{app.spec.destination.namespace}</div>
</div>
<div className='row'>
<div className='columns applications-list__entry--actions'>
<a
className='argo-button argo-button--base'
qe-id='applications-tiles-button-sync'
onClick={e => {
e.stopPropagation();
syncApplication(app.metadata.name);
}}>
<i className='fa fa-sync' /> Sync
</a>
<a
className='argo-button argo-button--base'
qe-id='applications-tiles-button-refresh'
{...AppUtils.refreshLinkAttrs(app)}
onClick={e => {
e.stopPropagation();
refreshApplication(app.metadata.name);
}}>
<i className={classNames('fa fa-redo', {'status-icon--spin': AppUtils.isAppRefreshing(app)})} />{' '}
<span className='show-for-xxlarge'>Refresh</span>
</a>
<a
className='argo-button argo-button--base'
qe-id='applications-tiles-button-delete'
onClick={e => {
e.stopPropagation();
deleteApplication(app.metadata.name);
}}>
<i className='fa fa-times-circle' /> <span className='show-for-xxlarge'>Delete</span>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
))}
</div>
)}
</Consumer>
);
};