1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-04 11:17:02 +02:00
unleash.unleash/frontend/src/component/feature/FeatureView/FeatureMetrics/FeatureMetricsChart/FeatureMetricsChart.tsx
Nuno Góis 4167a60588
feat: biome lint frontend (#4903)
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome
to the frontend as well.


![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65)

Added a few `biome-ignore` to speed up the process but we may want to
check and fix them in the future.
2023-10-02 13:25:46 +01:00

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;