forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication-deployment-history.tsx
103 lines (101 loc) · 5.4 KB
/
application-deployment-history.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
import {DataLoader, DropDownMenu, Duration} from 'argo-ui';
import * as moment from 'moment';
import * as React from 'react';
import {Revision, Timestamp} from '../../../shared/components';
import * as models from '../../../shared/models';
import {services} from '../../../shared/services';
import {ApplicationParameters} from '../application-parameters/application-parameters';
import {RevisionMetadataRows} from './revision-metadata-rows';
import './application-deployment-history.scss';
export const ApplicationDeploymentHistory = ({
app,
rollbackApp,
selectedRollbackDeploymentIndex,
selectDeployment
}: {
app: models.Application;
selectedRollbackDeploymentIndex: number;
rollbackApp: (info: models.RevisionHistory) => any;
selectDeployment: (index: number) => any;
}) => {
const deployments = (app.status.history || []).slice().reverse();
const recentDeployments = deployments.map((info, i) => {
const nextDeployedAt = i === 0 ? null : deployments[i - 1].deployedAt;
const runEnd = nextDeployedAt ? moment(nextDeployedAt) : moment();
return {...info, nextDeployedAt, durationMs: runEnd.diff(moment(info.deployedAt)) / 1000};
});
return (
<div className='application-deployment-history'>
{recentDeployments.map((info, index) => (
<div className='row application-deployment-history__item' key={info.deployedAt} onClick={() => selectDeployment(index)}>
<div className='columns small-3'>
<div>
<i className='fa fa-clock' /> <span class='show-for-large'>Deployed At:</span>
<br />
<Timestamp date={info.deployedAt} />
</div>
<div>
<br />
<i className='fa fa-hourglass-half' /> <span class='show-for-large'>Time to deploy:</span>
<br />
{(info.deployStartedAt && <Duration durationMs={moment(info.deployedAt).diff(moment(info.deployStartedAt)) / 1000} />) || 'Unknown'}
</div>
<div>
<br />
Active for:
<br />
<Duration durationMs={info.durationMs} />
</div>
</div>
<div className='columns small-9'>
<div className='row'>
<div className='columns small-3'>Revision:</div>
<div className='columns small-9'>
<Revision repoUrl={info.source.repoURL} revision={info.revision} />
<div className='application-deployment-history__item-menu'>
<DropDownMenu
anchor={() => (
<button className='argo-button argo-button--light argo-button--lg argo-button--short'>
<i className='fa fa-ellipsis-v' />
</button>
)}
items={[
{
title: (info.nextDeployedAt && 'Rollback') || 'Redeploy',
action: () => rollbackApp(info)
}
]}
/>
</div>
</div>
</div>
{selectedRollbackDeploymentIndex === index ? (
<React.Fragment>
<RevisionMetadataRows
applicationName={app.metadata.name}
applicationNamespace={app.metadata.namespace}
source={{...recentDeployments[index].source, targetRevision: recentDeployments[index].revision}}
/>
<DataLoader
input={{...recentDeployments[index].source, targetRevision: recentDeployments[index].revision, appName: app.metadata.name}}
load={src => services.repos.appDetails(src, src.appName, app.spec.project)}>
{(details: models.RepoAppDetails) => (
<div>
<ApplicationParameters
application={{
...app,
spec: {...app.spec, source: recentDeployments[index].source}
}}
details={details}
/>
</div>
)}
</DataLoader>
</React.Fragment>
) : null}
</div>
</div>
))}
</div>
);
};