mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-04 11:17:02 +02:00
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome to the frontend as well.  Added a few `biome-ignore` to speed up the process but we may want to check and fix them in the future.
80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import { IFeatureMetricsRaw } from 'interfaces/featureToggle';
|
|
import { useMemo } from 'react';
|
|
import { Line } from 'react-chartjs-2';
|
|
import {
|
|
CategoryScale,
|
|
Chart as ChartJS,
|
|
Legend,
|
|
LinearScale,
|
|
LineElement,
|
|
PointElement,
|
|
TimeScale,
|
|
Title,
|
|
Tooltip,
|
|
} from 'chart.js';
|
|
import { useLocationSettings } from 'hooks/useLocationSettings';
|
|
import 'chartjs-adapter-date-fns';
|
|
import { createChartData } from './createChartData';
|
|
import { createChartOptions } from './createChartOptions';
|
|
import { useTheme } from '@mui/material';
|
|
|
|
interface IFeatureMetricsChartProps {
|
|
metrics: IFeatureMetricsRaw[];
|
|
hoursBack: number;
|
|
statsSectionId: string;
|
|
}
|
|
|
|
export const FeatureMetricsChart = ({
|
|
metrics,
|
|
hoursBack,
|
|
statsSectionId,
|
|
}: IFeatureMetricsChartProps) => {
|
|
const theme = useTheme();
|
|
const { locationSettings } = useLocationSettings();
|
|
|
|
const sortedMetrics = useMemo(() => {
|
|
return [...metrics].sort((metricA, metricB) => {
|
|
return metricA.timestamp.localeCompare(metricB.timestamp);
|
|
});
|
|
}, [metrics]);
|
|
|
|
const options = useMemo(() => {
|
|
return createChartOptions(
|
|
theme,
|
|
sortedMetrics,
|
|
hoursBack,
|
|
locationSettings,
|
|
);
|
|
}, [theme, sortedMetrics, hoursBack, locationSettings]);
|
|
|
|
const data = useMemo(() => {
|
|
return createChartData(theme, sortedMetrics, locationSettings);
|
|
}, [theme, sortedMetrics, locationSettings]);
|
|
|
|
return (
|
|
<div style={{ height: 400 }}>
|
|
<Line
|
|
options={options}
|
|
data={data}
|
|
aria-label='A feature metrics line chart, with three lines: all requests, positive requests, and negative requests.'
|
|
aria-describedby={statsSectionId}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
// Register dependencies that we need to draw the chart.
|
|
ChartJS.register(
|
|
CategoryScale,
|
|
LinearScale,
|
|
PointElement,
|
|
LineElement,
|
|
TimeScale,
|
|
Legend,
|
|
Tooltip,
|
|
Title,
|
|
);
|
|
|
|
// Use a default export to lazy-load the charting library.
|
|
export default FeatureMetricsChart;
|