argo-cd
79 строк · 3.0 Кб
1import {Tooltip} from 'argo-ui/v2';
2import * as React from 'react';
3import {COLORS} from '../../../shared/components';
4import {Consumer} from '../../../shared/context';
5import * as models from '../../../shared/models';
6
7import './applications-status-bar.scss';
8
9export interface ApplicationsStatusBarProps {
10applications: models.Application[];
11}
12
13export const ApplicationsStatusBar = ({applications}: ApplicationsStatusBarProps) => {
14const readings = [
15{
16name: 'Healthy',
17value: applications.filter(app => app.status.health.status === 'Healthy').length,
18color: COLORS.health.healthy
19},
20{
21name: 'Progressing',
22value: applications.filter(app => app.status.health.status === 'Progressing').length,
23color: COLORS.health.progressing
24},
25{
26name: 'Degraded',
27value: applications.filter(app => app.status.health.status === 'Degraded').length,
28color: COLORS.health.degraded
29},
30{
31name: 'Suspended',
32value: applications.filter(app => app.status.health.status === 'Suspended').length,
33color: COLORS.health.suspended
34},
35{
36name: 'Missing',
37value: applications.filter(app => app.status.health.status === 'Missing').length,
38color: COLORS.health.missing
39},
40{
41name: 'Unknown',
42value: applications.filter(app => app.status.health.status === 'Unknown').length,
43color: COLORS.health.unknown
44}
45];
46
47// will sort readings by value greatest to lowest, then by name
48readings.sort((a, b) => (a.value < b.value ? 1 : a.value === b.value ? (a.name > b.name ? 1 : -1) : -1));
49
50const totalItems = readings.reduce((total, i) => {
51return total + i.value;
52}, 0);
53
54return (
55<Consumer>
56{ctx => (
57<>
58{totalItems > 1 && (
59<div className='status-bar'>
60{readings &&
61readings.length > 1 &&
62readings.map((item, i) => {
63if (item.value > 0) {
64return (
65<div className='status-bar__segment' style={{backgroundColor: item.color, width: (item.value / totalItems) * 100 + '%'}} key={i}>
66<Tooltip content={`${item.value} ${item.name}`} inverted={true}>
67<div className='status-bar__segment__fill' />
68</Tooltip>
69</div>
70);
71}
72})}
73</div>
74)}
75</>
76)}
77</Consumer>
78);
79};
80