-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathApplicationDetailsTab.tsx
More file actions
331 lines (313 loc) · 11.2 KB
/
ApplicationDetailsTab.tsx
File metadata and controls
331 lines (313 loc) · 11.2 KB
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
import * as React from 'react';
import { RouteComponentProps } from 'react-router';
import classNames from 'classnames';
import {
ApplicationKind,
ApplicationModel,
ApplicationSource,
} from '@gitops/models/ApplicationModel';
import Revision from '@gitops/Revision/Revision';
import HealthStatus from '@gitops/Statuses/HealthStatus';
import { OperationState } from '@gitops/Statuses/OperationState';
import SyncStatus from '@gitops/Statuses/SyncStatus';
import { ArgoServer, getArgoServer, getFriendlyClusterName } from '@gitops/utils/gitops';
import { useGitOpsTranslation } from '@gitops/utils/hooks/useGitOpsTranslation';
import { useObjectModifyPermissions } from '@gitops/utils/utils';
import {
k8sUpdate,
ResourceLink,
useK8sModel,
useModal,
} from '@openshift-console/dynamic-plugin-sdk';
import { ModalComponent } from '@openshift-console/dynamic-plugin-sdk/lib/app/modal-support/ModalProvider';
import {
Button,
Label as PfLabel,
Modal,
ModalBody,
ModalFooter,
ModalHeader,
ToggleGroup,
ToggleGroupItem,
} from '@patternfly/react-core';
import {
DescriptionList,
Flex,
FlexItem,
PageSection,
PageSectionVariants,
Title,
} from '@patternfly/react-core';
import { ArgoCDLink } from '../shared/ArgoCDLink/ArgoCDLink';
import {
BaseDetailsSummary,
DetailsDescriptionGroup,
} from '../shared/BaseDetailsSummary/BaseDetailsSummary';
import { ConditionsPopover } from './Conditions/ConditionsPopover';
type ApplicationDetailsTabProps = RouteComponentProps<{
ns: string;
name: string;
}> & {
obj?: ApplicationKind;
};
const ApplicationDetailsTab: React.FC<ApplicationDetailsTabProps> = ({ obj }) => {
const { t } = useGitOpsTranslation();
const [model] = useK8sModel({ group: 'route.openshift.io', version: 'v1', kind: 'Route' });
const [canPatch, canUpdate] = useObjectModifyPermissions(obj, ApplicationModel);
const [argoServer, setArgoServer] = React.useState<ArgoServer>({ host: '', protocol: '' });
const launchModal = useModal();
React.useEffect(() => {
(async () => {
getArgoServer(model, obj)
.then((server) => {
setArgoServer(server);
})
.catch((err) => {
console.error('Error:', err);
});
})();
}, [model, obj]);
const modalStyle: React.CSSProperties = {
padding: '1rem 1rem',
textAlign: 'left',
zIndex: 9999,
width: '500px',
};
const syncErrorModal: ModalComponent = (props) => {
return (
<Modal
isOpen
onClose={props?.closeModal}
style={modalStyle}
aria-describedby="modal-title-icon-description"
aria-labelledby="title-icon-modal-title"
>
<ModalHeader title="Error" titleIconVariant="danger" labelId="title-icon-modal-title" />
<ModalBody>
<span id="modal-title-icon-description">
Sync policy change failed. Check your application/logs and try again.
</span>
</ModalBody>
<ModalFooter>
<Button key="cancel" variant="primary" onClick={props?.closeModal}>
Close
</Button>
</ModalFooter>
</Modal>
);
};
const onChangeAutomated = (event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent) => {
const id = event.currentTarget.id;
switch (id) {
case 'automated': {
if (obj.spec.syncPolicy?.automated) {
obj.spec.syncPolicy = {};
} else {
obj.spec.syncPolicy = { automated: {} };
}
break;
}
case 'self-heal': {
if (obj.spec.syncPolicy?.automated?.selfHeal) {
obj.spec.syncPolicy.automated.selfHeal = false;
} else {
obj.spec.syncPolicy.automated = {
...obj.spec.syncPolicy.automated,
...{ selfHeal: true },
};
}
break;
}
case 'prune': {
if (obj.spec.syncPolicy?.automated?.prune) {
obj.spec.syncPolicy.automated.prune = false;
} else {
obj.spec.syncPolicy.automated = { ...obj.spec.syncPolicy.automated, ...{ prune: true } };
}
break;
}
}
k8sUpdate({
model: ApplicationModel,
data: obj,
})
.then(() => {
// ignore
})
.catch((e) => {
launchModal(syncErrorModal, { errorMessage: e.message });
});
};
let sources: ApplicationSource[];
let revisions: string[];
if (obj?.spec?.source) {
sources = [obj?.spec?.source];
revisions = [obj.status?.sync?.revision];
} else if (obj?.spec?.sources) {
sources = obj.spec.sources;
revisions = obj.status?.sync?.revisions;
} else {
sources = [];
revisions = [];
}
return (
<div>
<PageSection
variant={PageSectionVariants.default}
className={classNames('co-m-pane__body', { 'co-m-pane__body--section-heading': true })}
>
<Title headingLevel="h2" className="co-section-heading">
{t('Application details')}
</Title>
<Flex
justifyContent={{ default: 'justifyContentSpaceEvenly' }}
direction={{ default: 'column', lg: 'row' }}
>
<Flex flex={{ default: 'flex_2' }}>
<FlexItem fullWidth={{ default: 'fullWidth' }}>
<BaseDetailsSummary
obj={obj}
model={ApplicationModel}
nameLink={
<>
<ArgoCDLink
href={
argoServer.protocol +
'://' +
argoServer.host +
'/applications/' +
obj?.metadata?.namespace +
'/' +
obj?.metadata?.name
}
/>
</>
}
/>
</FlexItem>
</Flex>
<Flex flex={{ default: 'flex_2' }} direction={{ default: 'column' }}>
<FlexItem>
<DescriptionList className="pf-c-description-list">
<DetailsDescriptionGroup
title={t('Health Status')}
help={t('Health status represents the overall health of the application.')}
>
<HealthStatus status={obj.status?.health?.status || ''} />
</DetailsDescriptionGroup>
<DetailsDescriptionGroup
title={t('Current Sync Status')}
help={t(
'Sync status represents the current synchronized state for the application.',
)}
>
<Flex>
<FlexItem>
<SyncStatus status={obj.status?.sync?.status || ''} />
</FlexItem>
{sources && sources.length && revisions && revisions.length && (
<FlexItem>
<PfLabel>
<Revision
revision={revisions[0] || ''}
repoURL={sources[0].repoURL}
helm={
obj.status?.sourceType == 'Helm' && sources[0].chart ? true : false
}
revisionExtra={
revisions.length > 1 && ' and ' + (revisions.length - 1) + ' more'
}
/>
</PfLabel>
</FlexItem>
)}
</Flex>
</DetailsDescriptionGroup>
<DetailsDescriptionGroup
title={t('Last Sync Status')}
help={t('The result of the last sync status.')}
>
<Flex>
{obj?.status?.operationState && (
<FlexItem>
<OperationState app={obj} />
</FlexItem>
)}
{obj?.status?.conditions && (
<FlexItem>
<ConditionsPopover conditions={obj.status?.conditions} />
</FlexItem>
)}
</Flex>
</DetailsDescriptionGroup>
<DetailsDescriptionGroup
title={t('Target Revision')}
help={t('The specified revision for the Application.')}
>
{sources && sources.length && sources[0].targetRevision
? sources[0].targetRevision
: 'HEAD'}
</DetailsDescriptionGroup>
<DetailsDescriptionGroup
title={t('Project')}
help={t('The Argo CD Project that this application belongs to.')}
>
{/* TODO - Update to handle App in Any Namespace when controller namespace is in status */}
<ResourceLink
namespace={obj?.metadata?.namespace}
groupVersionKind={{
group: 'argoproj.io',
version: 'v1alpha1',
kind: 'AppProject',
}}
name={obj?.spec?.project}
/>
</DetailsDescriptionGroup>
<DetailsDescriptionGroup
title={t('Destination')}
help={t('The cluster and namespace where the application is targeted')}
>
{getFriendlyClusterName(obj?.spec?.destination.server)}/
{obj?.spec?.destination.namespace}
</DetailsDescriptionGroup>
<DetailsDescriptionGroup
title={t('Sync Policy')}
help={t('Provides options to determine application synchronization behavior')}
>
<ToggleGroup isCompact areAllGroupsDisabled={!canPatch || !canUpdate}>
<ToggleGroupItem
text={t('Automated')}
buttonId="automated"
onChange={onChangeAutomated}
isSelected={obj?.spec?.syncPolicy?.automated ? true : false}
/>
<ToggleGroupItem
text={t('Prune')}
buttonId="prune"
onChange={onChangeAutomated}
isSelected={
obj?.spec?.syncPolicy?.automated && obj?.spec?.syncPolicy?.automated.prune
}
isDisabled={obj?.spec?.syncPolicy?.automated ? false : true}
/>
<ToggleGroupItem
text={t('Self Heal')}
buttonId="self-heal"
onChange={onChangeAutomated}
isSelected={
obj?.spec?.syncPolicy?.automated &&
obj?.spec?.syncPolicy?.automated.selfHeal
}
isDisabled={obj?.spec?.syncPolicy?.automated ? false : true}
/>
</ToggleGroup>
</DetailsDescriptionGroup>
</DescriptionList>
</FlexItem>
</Flex>
</Flex>
</PageSection>
</div>
);
};
export default ApplicationDetailsTab;