1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-09 11:14:29 +02:00
unleash.unleash/frontend/src/component/executiveDashboard/componentsChart/MetricsSummaryChart/MetricsChartTooltip/MetricsChartTooltip.tsx
andreas-unleash c126ae130d
fix: insights UI improvements and aggreated TTP (#6584)
Various ui enhancements
Aggregates the time to production and metrics summary by averaging by
date across all projects to get the value. Creates a single dataset for
the aggregation. This makes theme behave like eg the Health chart
(showing aggregated graph when show all projects and per project when
not)

Gradient fill when all projects across all related charts
Attached recording with generated data for 3 months 




https://github.com/Unleash/unleash/assets/104830839/7acd80a8-b799-4a35-9a2e-bf3798f56d32

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
2024-03-20 09:24:56 +02:00

155 lines
5.1 KiB
TypeScript

import type { VFC } from 'react';
import type { ExecutiveSummarySchemaMetricsSummaryTrendsItem } from 'openapi';
import { Box, Divider, Paper, styled, Typography } from '@mui/material';
import type { TooltipState } from '../../../components/LineChart/ChartTooltip/ChartTooltip';
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 InfoLine = ({
iconChar,
title,
color,
}: {
iconChar: string;
title: string;
color: 'info' | 'success' | 'error';
}) => (
<Typography
variant='body2'
component='p'
sx={{
color: (theme) => theme.palette[color].main,
}}
>
<Typography component='span'>{iconChar}</Typography>
<strong>{title}</strong>
</Typography>
);
const InfoSummary = ({
data,
}: { data: { key: string; value: string | number }[] }) => (
<Box display={'flex'} flexDirection={'row'}>
{data
.filter(({ value }) => value !== 'N/A')
.map(({ key, value }) => (
<div style={{ flex: 1, flexDirection: 'column' }} key={key}>
<div
style={{
flex: 1,
textAlign: 'center',
marginBottom: '4px',
}}
>
<Typography variant={'body1'} component={'p'}>
{key}
</Typography>
</div>
<div style={{ flex: 1, textAlign: 'center' }}>{value}</div>
</div>
))}
</Box>
);
export const MetricsSummaryTooltip: 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 ExecutiveSummarySchemaMetricsSummaryTrendsItem & {
total: number;
},
};
});
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' component='span'>
<Typography
sx={{ color: point.color }}
component='span'
>
{'● '}
</Typography>
<strong>{point.title}</strong>
</Typography>
<Typography
variant='body2'
color='textSecondary'
component='span'
>
{point.label}
</Typography>
</StyledItemHeader>
<Divider
sx={(theme) => ({ margin: theme.spacing(1.5, 0) })}
/>
<InfoLine
iconChar={'▣ '}
title={`Total requests: ${
point.value.totalRequests ?? 0
}`}
color={'info'}
/>
<InfoLine
iconChar={'▲ '}
title={`Exposed: ${point.value.totalYes ?? 0}`}
color={'success'}
/>
<InfoLine
iconChar={'▼ '}
title={`Not exposed: ${point.value.totalNo ?? 0}`}
color={'error'}
/>
<Divider
sx={(theme) => ({ margin: theme.spacing(1.5, 0) })}
/>
<InfoSummary
data={[
{
key: 'Flags',
value: point.value.totalFlags ?? 'N/A',
},
{
key: 'Environments',
value: point.value.totalEnvironments ?? 'N/A',
},
{
key: 'Apps',
value: point.value.totalApps ?? 'N/A',
},
]}
/>
</StyledTooltipItemContainer>
)) || null}
</Box>
);
};