Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/dashboard-tiles-refresh-pulse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@hyperdx/app': patch
---

fix: show that number, bar and pie tiles are refreshing

During a dashboard refresh these tiles kept the previous result on screen with
no sign that new data was loading, so stale values looked current. They now
pulse while the refetch runs, like line and stacked-bar time charts already do.
11 changes: 9 additions & 2 deletions packages/app/src/components/DBBarChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { memo } from 'react';
import cx from 'classnames';
import {
Bar,
BarChart,
Expand Down Expand Up @@ -64,6 +65,7 @@ export const DBBarChart = (props: CategoricalChartProps) => {
toolbarItems,
data,
isLoading,
isPlaceholderData,
isError,
error,
chartData,
Expand All @@ -84,7 +86,12 @@ export const DBBarChart = (props: CategoricalChartProps) => {
variant={props.errorVariant}
/>
) : data?.data.length === 0 ? (
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">
<div
className={cx(
'd-flex h-100 w-100 align-items-center justify-content-center text-muted',
{ 'effect-pulse': isPlaceholderData },
)}
>
No data found within time range.
</div>
) : (
Expand All @@ -98,7 +105,7 @@ export const DBBarChart = (props: CategoricalChartProps) => {
<ResponsiveContainer
height="100%"
width="100%"
className={isLoading ? 'effect-pulse' : ''}
className={isLoading || isPlaceholderData ? 'effect-pulse' : ''}
>
<BarChart data={chartData}>
<XAxis
Expand Down
21 changes: 14 additions & 7 deletions packages/app/src/components/DBNumberChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useLayoutEffect, useMemo, useRef, useState } from 'react';
import cx from 'classnames';
import { ErrorBoundary } from 'react-error-boundary';
import {
filterColumnMetaByType,
Expand Down Expand Up @@ -235,14 +236,12 @@ export default function DBNumberChart({
const { data: mvOptimizationData } =
useMVOptimizationExplanation(builderQueriedConfig);

const { data, isLoading, isError, error } = useQueriedChartConfig(
queriedConfig,
{
const { data, isLoading, isError, error, isPlaceholderData } =
useQueriedChartConfig(queriedConfig, {
placeholderData: (prev: any) => prev,
queryKeyPrefix,
enabled,
},
);
});

// The value is the first numeric value in the first row of the result
const valueColumn = data?.meta
Expand Down Expand Up @@ -383,11 +382,19 @@ export default function DBNumberChart({
) : resultError ? (
<ChartErrorState error={resultError} variant={errorVariant} />
) : data?.data.length === 0 ? (
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">
<div
className={cx(
'd-flex h-100 w-100 align-items-center justify-content-center text-muted',
{ 'effect-pulse': isPlaceholderData },
)}
>
No data found within time range.
</div>
) : (
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
<div
className={isLoading || isPlaceholderData ? 'effect-pulse' : ''}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 minor — isLoading || can never be true in this branch, so it does nothing

isLoading is only true when the query is pending with no data, and that case is already caught by the isLoading && !data branch above. If this branch has data while pending, the data is the placeholder, so isPlaceholderData is already true. Use isPlaceholderData alone here and in the pie Flex (DBPieChart.tsx:128) so it matches the empty-state branches, which already check only isPlaceholderData.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept on purpose: useQueriedChartConfig's isLoading also covers the MV-optimization check, so it can be true while a value is on screen. f94a99c adds a test for that case, and it fails without isLoading ||.

style={{ position: 'relative', width: '100%', height: '100%' }}
>
{config.backgroundChart && (
<NumberTileBackgroundChart
config={config}
Expand Down
17 changes: 11 additions & 6 deletions packages/app/src/components/DBPieChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { memo } from 'react';
import cx from 'classnames';
import { Cell, Pie, PieChart, ResponsiveContainer, Tooltip } from 'recharts';
import { Box, Flex, ScrollArea, Text } from '@mantine/core';

Expand Down Expand Up @@ -94,6 +95,7 @@ export const DBPieChart = (props: CategoricalChartProps) => {
toolbarItems,
data,
isLoading,
isPlaceholderData,
isError,
error,
chartData,
Expand All @@ -111,7 +113,12 @@ export const DBPieChart = (props: CategoricalChartProps) => {
) : responseFormatError ? (
<ChartErrorState error={responseFormatError} variant={errorVariant} />
) : data?.data.length === 0 ? (
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">
<div
className={cx(
'd-flex h-100 w-100 align-items-center justify-content-center text-muted',
{ 'effect-pulse': isPlaceholderData },
)}
>
No data found within time range.
</div>
) : (
Expand All @@ -121,12 +128,10 @@ export const DBPieChart = (props: CategoricalChartProps) => {
justify="center"
h="100%"
style={{ flexGrow: 1, overflow: 'hidden' }}
// Pulse the pie and its legend together: the legend shows values too
className={isLoading || isPlaceholderData ? 'effect-pulse' : ''}
>
<ResponsiveContainer
height="100%"
width="100%"
className={isLoading ? 'effect-pulse' : ''}
>
<ResponsiveContainer height="100%" width="100%">
<PieChart>
<Pie
cx="50%"
Expand Down
59 changes: 59 additions & 0 deletions packages/app/src/components/__tests__/DBBarChart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,65 @@ describe('DBBarChart', () => {
expect(screen.getByText('Loading Chart Data...')).toBeInTheDocument();
});

describe('refresh indicator', () => {
const groupedData = {
data: [
{ status: 'success', count: 100 },
{ status: 'error', count: 50 },
],
meta: [
{ name: 'status', type: 'String' },
{ name: 'count', type: 'UInt64' },
],
};

it('pulses while a refetch is showing the previous result', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: groupedData,
isLoading: false,
isPlaceholderData: true,
isError: false,
});

renderWithMantine(<DBBarChart config={baseTestConfig} />);
expect(
screen
.getByTestId('bar-chart-container')
.querySelector('.effect-pulse'),
).not.toBeNull();
});

it('does not pulse once fresh data has loaded', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: groupedData,
isLoading: false,
isPlaceholderData: false,
isError: false,
});

renderWithMantine(<DBBarChart config={baseTestConfig} />);
expect(
screen
.getByTestId('bar-chart-container')
.querySelector('.effect-pulse'),
).toBeNull();
});

it('pulses the empty state while a refetch is running', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: { data: [], meta: groupedData.meta },
isLoading: false,
isPlaceholderData: true,
isError: false,
});

renderWithMantine(<DBBarChart config={baseTestConfig} />);
expect(screen.getByText('No data found within time range.')).toHaveClass(
'effect-pulse',
);
});
});

it('handles error state correctly', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: undefined,
Expand Down
60 changes: 60 additions & 0 deletions packages/app/src/components/__tests__/DBNumberChart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,66 @@ describe('DBNumberChart', () => {
expect(screen.getByText('Loading Chart Data...')).toBeInTheDocument();
});

describe('refresh indicator', () => {
it('pulses while a refetch is showing the previous value', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: { data: [{ value: 1234 }] },
isLoading: false,
isPlaceholderData: true,
isError: false,
});

renderWithMantine(<DBNumberChart config={baseTestConfig} />);
expect(
screen.getByTestId('number-chart-value').closest('.effect-pulse'),
).not.toBeNull();
});

it('pulses while still loading with a value on screen', () => {
// useQueriedChartConfig's isLoading also covers the MV-optimization
// check, which can be pending while a value is shown
mockUseQueriedChartConfig.mockReturnValue({
data: { data: [{ value: 1234 }] },
isLoading: true,
isPlaceholderData: false,
isError: false,
});

renderWithMantine(<DBNumberChart config={baseTestConfig} />);
expect(
screen.getByTestId('number-chart-value').closest('.effect-pulse'),
).not.toBeNull();
});

it('does not pulse once the fresh value has loaded', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: { data: [{ value: 1234 }] },
isLoading: false,
isPlaceholderData: false,
isError: false,
});

renderWithMantine(<DBNumberChart config={baseTestConfig} />);
expect(
screen.getByTestId('number-chart-value').closest('.effect-pulse'),
).toBeNull();
});

it('pulses the empty state while a refetch is running', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: { data: [] },
isLoading: false,
isPlaceholderData: true,
isError: false,
});

renderWithMantine(<DBNumberChart config={baseTestConfig} />);
expect(screen.getByText('No data found within time range.')).toHaveClass(
'effect-pulse',
);
});
});

it('handles error state correctly', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: undefined,
Expand Down
59 changes: 59 additions & 0 deletions packages/app/src/components/__tests__/DBPieChart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,65 @@ describe('DBPieChart', () => {
expect(screen.getByText('Loading Chart Data...')).toBeInTheDocument();
});

describe('refresh indicator', () => {
const groupedData = {
data: [
{ status: 'success', count: 100 },
{ status: 'error', count: 50 },
],
meta: [
{ name: 'status', type: 'String' },
{ name: 'count', type: 'UInt64' },
],
};

it('pulses while a refetch is showing the previous result', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: groupedData,
isLoading: false,
isPlaceholderData: true,
isError: false,
});

renderWithMantine(<DBPieChart config={baseTestConfig} />);
expect(screen.getByTestId('pie-chart-container')).toHaveClass(
'effect-pulse',
);
// The legend shows values too, so it pulses along with the pie
expect(
screen.getByTestId('pie-chart-legend').closest('.effect-pulse'),
).not.toBeNull();
});

it('does not pulse once fresh data has loaded', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: groupedData,
isLoading: false,
isPlaceholderData: false,
isError: false,
});

renderWithMantine(<DBPieChart config={baseTestConfig} />);
expect(screen.getByTestId('pie-chart-container')).not.toHaveClass(
'effect-pulse',
);
});

it('pulses the empty state while a refetch is running', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: { data: [], meta: groupedData.meta },
isLoading: false,
isPlaceholderData: true,
isError: false,
});

renderWithMantine(<DBPieChart config={baseTestConfig} />);
expect(screen.getByText('No data found within time range.')).toHaveClass(
'effect-pulse',
);
});
});

it('handles error state correctly', () => {
mockUseQueriedChartConfig.mockReturnValue({
data: undefined,
Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/components/charts/CategoricalChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ export function useCategoricalChart({
const { data: mvOptimizationData } =
useMVOptimizationExplanation(builderQueriedConfig);

const { data, isLoading, isError, error } = useQueriedChartConfig(
queriedConfig,
{
const { data, isLoading, isError, error, isPlaceholderData } =
useQueriedChartConfig(queriedConfig, {
placeholderData: (prev: any) => prev,
queryKey: [queryKeyPrefix, queriedConfig],
enabled,
},
);
});

const toolbarItems = useMemo(() => {
const allToolbarItems: React.ReactNode[] = [];
Expand Down Expand Up @@ -130,6 +128,8 @@ export function useCategoricalChart({
toolbarItems,
data,
isLoading,
// True while a refetch (e.g. dashboard refresh) shows the previous result
isPlaceholderData,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 minor — Two different pulse conditions: the empty state checks only isPlaceholderData, the chart checks isLoading || isPlaceholderData

Work out the refresh flag once in useCategoricalChart, e.g. isRefreshing: isLoading || isPlaceholderData (useAvailableMetricNames.ts:85 already folds the two flags the same way). Then use that one flag for the chart and the empty-state div in DBBarChart and DBPieChart, and the same expression in DBNumberChart. Right now each of the three tiles repeats the same cx(... { 'effect-pulse': isPlaceholderData }) / isLoading || isPlaceholderData ? 'effect-pulse' : '' pair, and the two halves already disagree. The PR's own number-chart test says isLoading can be true without placeholder data while a result is shown (the MV-optimization check in useChartConfig.tsx:450). When that happens, a non-empty tile pulses but an empty one does not.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair: the empty state should match the chart's isLoading || isPlaceholderData. Per AGENTS.md I've stopped addressing bot findings after two rounds, so I'll make that change if a maintainer wants it in this PR.

isError,
error,
chartData,
Expand Down
Loading