Skip to content

Commit

Permalink
feat(insights): placeholder for empty metrics (#6422)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed Mar 5, 2024
1 parent 6678012 commit 6cede44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
@@ -1,9 +1,10 @@
import { type VFC } from 'react';
import { useMemo, type VFC } from 'react';
import 'chartjs-adapter-date-fns';
import { ExecutiveSummarySchema } from 'openapi';
import { LineChart } from '../../components/LineChart/LineChart';
import { LineChart, NotEnoughData } from '../../components/LineChart/LineChart';
import { MetricsSummaryTooltip } from './MetricsChartTooltip/MetricsChartTooltip';
import { useMetricsSummary } from '../../hooks/useMetricsSummary';
import { usePlaceholderData } from 'component/executiveDashboard/hooks/usePlaceholderData';

interface IMetricsSummaryChartProps {
metricsSummaryTrends: ExecutiveSummarySchema['metricsSummaryTrends'];
Expand All @@ -13,15 +14,21 @@ export const MetricsSummaryChart: VFC<IMetricsSummaryChartProps> = ({
metricsSummaryTrends,
}) => {
const data = useMetricsSummary(metricsSummaryTrends);
const notEnoughData = useMemo(
() => (data.datasets.some((d) => d.data.length > 1) ? false : true),
[data],
);
const placeholderData = usePlaceholderData();

return (
<LineChart
data={data}
data={notEnoughData ? placeholderData : data}
isLocalTooltip
TooltipComponent={MetricsSummaryTooltip}
overrideOptions={{
parsing: { yAxisKey: 'totalRequests', xAxisKey: 'week' },
}}
cover={notEnoughData ? <NotEnoughData /> : false}
/>
);
};
Expand Up @@ -2,13 +2,15 @@ import { useTheme } from '@mui/material';
import { useMemo } from 'react';
import { fillGradientPrimary } from '../components/LineChart/LineChart';

export const usePlaceholderData = ({
fill = false,
type = 'constant',
}: {
type PlaceholderDataOptions = {
fill?: boolean;
type?: 'rising' | 'constant' | 'double';
}) => {
};

export const usePlaceholderData = (
placeholderDataOptions?: PlaceholderDataOptions,
) => {
const { fill = false, type = 'constant' } = placeholderDataOptions || {};
const theme = useTheme();

return useMemo(
Expand Down

0 comments on commit 6cede44

Please sign in to comment.