mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-10 01:16:39 +02:00
* refactor: ensure that [hidden] overrides other display styles * refactor: use numeric font weights * refactor: remove unnecessary Jest mock * refactor: add a fullWidth prop to GeneralSelect * refactor: remove unnecessary label id prop * refactor: the showActive prop is optional * refactor: add hooks for managing query string state * refactor: add a hour/minute timestamp formatter * refactor: add labels to button icons * feat: add new feature metrics page * refactor: remove prev feature metrics page * refactor: use new metric boxes on overview page * refactor: lazy-load the new metrics page * refactor: fix type error when formatting unknown error * refactor: extract interfaces for props * refactor: destructure all props * refactor: expand arg names * refactor: reorg component dirs and files * refactor: improve chart element label * refactor: hide chart dots until hover * refactor: add section titles to environments/applications * refactor: simplify FeatureMetricsHours types * refactor: sort chart tooltip items * refactor: add more chart labels * refactor: always show a dot in single point charts * refactor: improve chart tooltip styles * refactor: adjut metric page spacing * refactor: decrease legend box size * refactor: move date fmt fn inline * refactor: improve chart legend styles * refactor: increase Cypress timeouts * refactor: sort environment and application chips * refactor: format files * refactor: use stable lists of apps and envs * refactor: fix FeatureMetrics dir name * refactor: avoid ScrollToTop on query string change * refactor: use ConditionallyRender instead of inline condition * refactor: use makeStyles instead of styled API
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import { IFeatureMetricsRaw } from '../../../../../interfaces/featureToggle';
|
|
import React, { 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 { FEATURE_METRICS_TABLE_ID } from '../FeatureMetricsTable/FeatureMetricsTable';
|
|
import 'chartjs-adapter-date-fns';
|
|
import { createChartData } from './createChartData';
|
|
import { createChartOptions } from './createChartOptions';
|
|
|
|
interface IFeatureMetricsChartProps {
|
|
metrics: IFeatureMetricsRaw[];
|
|
hoursBack: number;
|
|
}
|
|
|
|
export const FeatureMetricsChart = ({
|
|
metrics,
|
|
hoursBack,
|
|
}: IFeatureMetricsChartProps) => {
|
|
const { locationSettings } = useLocationSettings();
|
|
|
|
const sortedMetrics = useMemo(() => {
|
|
return [...metrics].sort((metricA, metricB) => {
|
|
return metricA.timestamp.localeCompare(metricB.timestamp);
|
|
});
|
|
}, [metrics]);
|
|
|
|
const options = useMemo(() => {
|
|
return createChartOptions(sortedMetrics, hoursBack, locationSettings);
|
|
}, [sortedMetrics, hoursBack, locationSettings]);
|
|
|
|
const data = useMemo(() => {
|
|
return createChartData(sortedMetrics, locationSettings);
|
|
}, [sortedMetrics, locationSettings]);
|
|
|
|
return (
|
|
<div style={{ height: 400 }}>
|
|
<Line
|
|
options={options}
|
|
data={data}
|
|
aria-label="A line chart with series for all requests, positive requests, and negative requests."
|
|
aria-describedby={FEATURE_METRICS_TABLE_ID}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
// Register dependencies that we need to draw the chart.
|
|
ChartJS.register(
|
|
CategoryScale,
|
|
LinearScale,
|
|
PointElement,
|
|
LineElement,
|
|
TimeScale,
|
|
Legend,
|
|
Tooltip,
|
|
Title
|
|
);
|