generated from openshift/console-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathPipelineRunsDurationCard.tsx
158 lines (149 loc) · 4.32 KB
/
PipelineRunsDurationCard.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
import * as React from 'react';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import {
HistoryIcon,
InfoCircleIcon,
MonitoringIcon,
} from '@patternfly/react-icons';
import {
Card,
CardBody,
CardTitle,
Divider,
Grid,
GridItem,
} from '@patternfly/react-core';
import { SummaryProps, getFilter, useInterval } from './utils';
import { getResultsSummary } from '../utils/summary-api';
import { DataType } from '../../types';
import { ALL_NAMESPACES_KEY } from '../../consts';
import { formatTime, getDropDownDate } from './dateTime';
import { LoadingInline } from '../Loading';
import './PipelineRunsDurationCard.scss';
interface PipelinesRunsDurationProps {
namespace: string;
timespan: number;
interval: number;
parentName?: string;
summaryData?: SummaryProps;
bordered?: boolean;
kind?: string;
}
const PipelinesRunsDurationCard: React.FC<PipelinesRunsDurationProps> = ({
namespace,
timespan,
parentName,
interval,
bordered,
kind,
}) => {
const { t } = useTranslation('plugin__pipelines-console-plugin');
const [summaryData, setSummaryData] = React.useState<SummaryProps>({});
const [loaded, setLoaded] = React.useState(false);
if (namespace == ALL_NAMESPACES_KEY) {
namespace = '-';
}
React.useEffect(() => {
setLoaded(false);
}, [namespace, timespan]);
const date = getDropDownDate(timespan).toISOString();
const getSummaryData = () => {
getResultsSummary(namespace, {
summary: 'total_duration,avg_duration,max_duration',
data_type: DataType?.PipelineRun,
filter: getFilter(date, parentName, kind),
})
.then((response) => {
setLoaded(true);
setSummaryData(response.summary?.[0]);
})
.catch((e) => {
console.error('unable to post', e);
});
};
useInterval(getSummaryData, interval, namespace, date);
return (
<>
<Card
className={classNames('pipeline-overview__duration-card', {
'card-border': bordered,
})}
>
<CardTitle>
<span>{t('Duration')}</span>
</CardTitle>
<Divider />
<CardBody>
<Grid hasGutter className="pipeline-overview__duration-card__grid">
<GridItem span={6}>
<span>
<MonitoringIcon className="pipeline-overview__duration-card__icon" />
{t('Average duration')}
</span>
</GridItem>
<GridItem
span={6}
className="pipeline-overview__duration-card__value"
>
{loaded ? (
summaryData?.['avg_duration'] ? (
formatTime(summaryData?.['avg_duration'])
) : (
'-'
)
) : (
<LoadingInline />
)}
</GridItem>
</Grid>
<Grid hasGutter className="pipeline-overview__duration-card__grid">
<GridItem span={6}>
<span>
<InfoCircleIcon className="pipeline-overview__duration-card__info-icon" />
{t('Maximum')}
</span>
</GridItem>
<GridItem
span={6}
className="pipeline-overview__duration-card__value"
>
{loaded ? (
summaryData?.['max_duration'] ? (
formatTime(summaryData?.['max_duration'])
) : (
'-'
)
) : (
<LoadingInline />
)}
</GridItem>
</Grid>
<Grid hasGutter>
<GridItem span={6}>
<span>
<HistoryIcon className="pipeline-overview__duration-card__icon" />
{t('Total duration')}
</span>
</GridItem>
<GridItem
span={6}
className="pipeline-overview__duration-card__value"
>
{loaded ? (
summaryData?.['total_duration'] ? (
formatTime(summaryData?.['total_duration'])
) : (
'-'
)
) : (
<LoadingInline />
)}
</GridItem>
</Grid>
</CardBody>
</Card>
</>
);
};
export default PipelinesRunsDurationCard;