-
-
Notifications
You must be signed in to change notification settings - Fork 656
/
HealthChartTooltip.tsx
164 lines (154 loc) · 5.4 KB
/
HealthChartTooltip.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
import type { VFC } from 'react';
import type { InstanceInsightsSchemaProjectFlagTrendsItem } from 'openapi';
import { Box, Divider, Paper, Typography, styled } from '@mui/material';
import { Badge } from 'component/common/Badge/Badge';
import type { TooltipState } from 'component/insights/components/LineChart/ChartTooltip/ChartTooltip';
import { HorizontalDistributionChart } from 'component/insights/components/HorizontalDistributionChart/HorizontalDistributionChart';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
const StyledTooltipItemContainer = styled(Paper)(({ theme }) => ({
padding: theme.spacing(2),
}));
const StyledItemHeader = styled(Box)(({ theme }) => ({
display: 'flex',
justifyContent: 'space-between',
gap: theme.spacing(2),
alignItems: 'center',
}));
const getHealthBadgeColor = (health?: number | null) => {
if (health === undefined || health === null) {
return 'info';
}
if (health >= 75) {
return 'success';
}
if (health >= 50) {
return 'warning';
}
return 'error';
};
const Distribution = ({ stale = 0, potentiallyStale = 0, total = 0 }) => (
<>
<HorizontalDistributionChart
sections={[{ type: 'default', value: 100 }]}
size='small'
/>
<HorizontalDistributionChart
sections={[
{
type: 'error',
value: (stale / total) * 100,
},
{
type: 'warning',
value: (potentiallyStale / total) * 100,
},
]}
size='small'
/>
<Typography
variant='body2'
component='p'
sx={(theme) => ({ marginTop: theme.spacing(0.5) })}
>
<Typography
component='span'
sx={(theme) => ({
color: theme.palette.error.border,
})}
>
{'● '}
</Typography>
Stale flags: {stale}
</Typography>
<Typography variant='body2' component='p'>
<Typography
component='span'
sx={(theme) => ({
color: theme.palette.warning.border,
})}
>
{'● '}
</Typography>
Potentially stale flags: {potentiallyStale}
</Typography>
</>
);
export const HealthTooltip: VFC<{ tooltip: TooltipState | null }> = ({
tooltip,
}) => {
const data = tooltip?.dataPoints.map((point) => {
return {
label: point.label,
title: point.dataset.label,
color: point.dataset.borderColor,
value: point.raw as InstanceInsightsSchemaProjectFlagTrendsItem,
};
});
const limitedData = data?.slice(0, 5);
return (
<Box
sx={(theme) => ({
display: 'flex',
flexDirection: 'column',
gap: theme.spacing(2),
width: '300px',
})}
>
{limitedData?.map((point, index) => (
<StyledTooltipItemContainer
elevation={3}
key={`${point.title}-${index}`}
>
<StyledItemHeader>
<Typography
variant='body2'
color='textSecondary'
component='span'
>
{point.label}
</Typography>
<Typography
variant='body2'
color='textSecondary'
component='span'
>
Project health
</Typography>
</StyledItemHeader>
<StyledItemHeader>
<Typography variant='body2' component='span'>
<Typography
sx={{ color: point.color }}
component='span'
>
{'● '}
</Typography>
<strong>{point.title}</strong>
</Typography>
<Badge color={getHealthBadgeColor(point.value.health)}>
{point.value.health}%
</Badge>
</StyledItemHeader>{' '}
<Divider
sx={(theme) => ({ margin: theme.spacing(1.5, 0) })}
/>
<Typography
variant='body2'
component='p'
sx={(theme) => ({
marginBottom: theme.spacing(0.5),
})}
>
Total flags: {point.value.total}
</Typography>
<ConditionallyRender
condition={Boolean(
point.value.stale || point.value.potentiallyStale,
)}
show={<Distribution {...point.value} />}
/>
</StyledTooltipItemContainer>
)) || null}
</Box>
);
};