Skip to content

Commit c372a71

Browse files
authored
fix(app): pulse the list-bar and histogram charts while they refresh (#3229)
## Summary A follow-up to #3205, for the Services dashboard. Two chart types there already keep their previous data during a refresh (`placeholderData: prev => prev`) but give no sign that new data is loading: the "Top 20 Most Time Consuming Endpoints/Queries" list-bar charts and the "Request Latency" histogram. They now pulse while the refetch runs, like the categorical charts fixed in #3211. - `DBListBarChart` pulses the bar list, and its empty state, while `isPlaceholderData` is true. - `DBHistogramChart` does the same through a new `className` prop on `HistogramChart`, which is applied to its `ResponsiveContainer`. - `DBHistogramChart`'s loading state now shows only before the first data arrives (`isLoading && !data`), as `DBListBarChart` and `DBBarChart` already do. `useQueriedChartConfig` also reports `isLoading` while the materialized-view check for the new range runs, which briefly replaced the kept histogram with "Loading Chart Data...". - `DBListBarChart` is also used by the LLM token-cost charts and the endpoint side panel's performance chart, which now pulse the same way. **Tests** - `DBListBarChart.test.tsx`: - the bars pulse during a refresh and stop once fresh data loads; - the empty state pulses during a refresh, but not for a fresh empty result. - `DBHistogramChart.test.tsx`: - the histogram stays on screen and pulses while a refresh loads, and stops once fresh data loads; - the empty state pulses during a refresh, but not for a fresh empty result; - the loading state still shows before the first data. - Without the source changes, 4 of the 9 new tests fail. The ones that pass either way are the guards: no pulse once fresh, and the loading state before the first data. ### How to test on Vercel preview **Preview routes:** /services **Steps:** 1. Open the Services dashboard on the demo trace source. On the "HTTP Service" tab, switch "Request Latency" to "Display as Histogram". 2. Click "Refresh dashboard". 3. Verify the "Request Latency" histogram and the "Top 20 Most Time Consuming Endpoints" list keep their data on screen and pulse while they reload, and stop pulsing once the new data appears. ### References - Linear Issue: N/A - Related PRs: #3211, #3221, #3224 - Follow-up to #3205 Checks run locally: - `jest --findRelatedTests` for both charts: 33 passed across 4 suites. - `eslint` on the changed files: 0 errors, no new warnings. - `prettier --check`. - `tsc --noEmit` for `packages/app`.
1 parent 76d0865 commit c372a71

5 files changed

Lines changed: 208 additions & 24 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@hyperdx/app': patch
3+
---
4+
5+
fix: pulse the list-bar and histogram charts while they refresh
6+
7+
The Services dashboard's list-bar and latency histogram charts kept their
8+
previous data during a refresh but gave no sign that new data was loading,
9+
and the histogram could briefly swap its chart for "Loading Chart Data...".
10+
Both now keep their previous data on screen and pulse while the refetch runs,
11+
like the other charts.

‎packages/app/src/components/DBHistogramChart.tsx‎

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { memo, useEffect, useMemo, useState } from 'react';
2+
import cx from 'classnames';
23
import { omit } from 'lodash';
34
import { useHotkeys } from 'react-hotkeys-hook';
45
import {
@@ -47,7 +48,13 @@ export function resolvePinnedBarIndex(
4748
return Number.isInteger(idx) && idx >= 0 ? idx : undefined;
4849
}
4950

50-
function HistogramChart({ graphResults }: { graphResults: any[] }) {
51+
function HistogramChart({
52+
graphResults,
53+
className,
54+
}: {
55+
graphResults: any[];
56+
className?: string;
57+
}) {
5158
const data = useMemo(() => {
5259
return (
5360
graphResults?.map((result: any) => {
@@ -77,7 +84,12 @@ function HistogramChart({ graphResults }: { graphResults: any[] }) {
7784
}, [data]);
7885

7986
return (
80-
<ResponsiveContainer width="100%" height="100%" minWidth={0}>
87+
<ResponsiveContainer
88+
width="100%"
89+
height="100%"
90+
minWidth={0}
91+
className={className}
92+
>
8193
<BarChart
8294
width={500}
8395
height={300}
@@ -212,14 +224,12 @@ export default function DBHistogramChart({
212224
errorVariant?: ChartErrorStateVariant;
213225
}) {
214226
const queriedConfig = omit(config, ['granularity']);
215-
const { data, isLoading, isError, error } = useQueriedChartConfig(
216-
queriedConfig,
217-
{
227+
const { data, isLoading, isPlaceholderData, isError, error } =
228+
useQueriedChartConfig(queriedConfig, {
218229
placeholderData: (prev: any) => prev,
219230
queryKey: [queryKeyPrefix, queriedConfig],
220231
enabled,
221-
},
222-
);
232+
});
223233

224234
const { data: mvOptimizationData } =
225235
useMVOptimizationExplanation(queriedConfig);
@@ -272,18 +282,26 @@ export default function DBHistogramChart({
272282

273283
return (
274284
<ChartContainer title={title} toolbarItems={toolbarItemsMemo}>
275-
{isLoading ? (
285+
{isLoading && !data ? (
276286
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">
277287
Loading Chart Data...
278288
</div>
279289
) : isError ? (
280290
<ChartErrorState error={error} variant={errorVariant} />
281291
) : data?.data.length === 0 ? (
282-
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">
292+
<div
293+
className={cx(
294+
'd-flex h-100 w-100 align-items-center justify-content-center text-muted',
295+
{ 'effect-pulse': isPlaceholderData },
296+
)}
297+
>
283298
No data found within time range.
284299
</div>
285300
) : (
286-
<HistogramChart graphResults={buckets} />
301+
<HistogramChart
302+
graphResults={buckets}
303+
className={isPlaceholderData ? 'effect-pulse' : undefined}
304+
/>
287305
)}
288306
</ChartContainer>
289307
);

‎packages/app/src/components/DBListBarChart.tsx‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useMemo } from 'react';
22
import Link from 'next/link';
3+
import cx from 'classnames';
34
import { omit } from 'lodash';
45
import { BuilderChartConfigWithDateRange } from '@hyperdx/common-utils/dist/types';
56
import type { FloatingPosition } from '@mantine/core';
@@ -202,14 +203,12 @@ export default function DBListBarChart({
202203
errorVariant?: ChartErrorStateVariant;
203204
}) {
204205
const queriedConfig = omit(config, ['granularity']);
205-
const { data, isLoading, isError, error } = useQueriedChartConfig(
206-
queriedConfig,
207-
{
206+
const { data, isLoading, isPlaceholderData, isError, error } =
207+
useQueriedChartConfig(queriedConfig, {
208208
placeholderData: (prev: any) => prev,
209209
queryKey: [queryKeyPrefix, queriedConfig],
210210
enabled,
211-
},
212-
);
211+
});
213212

214213
const { data: mvOptimizationData } =
215214
useMVOptimizationExplanation(queriedConfig);
@@ -285,18 +284,25 @@ export default function DBListBarChart({
285284
) : isError ? (
286285
<ChartErrorState error={error} variant={errorVariant} />
287286
) : data?.data.length === 0 ? (
288-
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">
287+
<div
288+
className={cx(
289+
'd-flex h-100 w-100 align-items-center justify-content-center text-muted',
290+
{ 'effect-pulse': isPlaceholderData },
291+
)}
292+
>
289293
No data found within time range.
290294
</div>
291295
) : (
292-
<ListBar
293-
data={data?.data ?? []}
294-
columns={columns}
295-
getRowSearchLink={getRowSearchLink}
296-
hoverCardPosition={hoverCardPosition}
297-
groupColumn={groupColumn}
298-
valueColumn={valueColumn}
299-
/>
296+
<div className={isPlaceholderData ? 'effect-pulse' : undefined}>
297+
<ListBar
298+
data={data?.data ?? []}
299+
columns={columns}
300+
getRowSearchLink={getRowSearchLink}
301+
hoverCardPosition={hoverCardPosition}
302+
groupColumn={groupColumn}
303+
valueColumn={valueColumn}
304+
/>
305+
</div>
300306
)}
301307
</ChartContainer>
302308
);

‎packages/app/src/components/__tests__/DBHistogramChart.test.tsx‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,85 @@ describe('DBHistogramChart', () => {
156156
// Verify DateRangeIndicator was not called
157157
expect(jest.mocked(DateRangeIndicator)).not.toHaveBeenCalled();
158158
});
159+
160+
describe('refresh', () => {
161+
const buckets = { data: [{ data: [[0, 10, 5]] }], meta: [] };
162+
const chart = () =>
163+
document.querySelector('.recharts-responsive-container');
164+
165+
it('keeps the previous histogram on screen and pulses it while a refresh loads', () => {
166+
// The new range is still loading behind the previous buckets.
167+
mockUseQueriedChartConfig.mockReturnValue({
168+
data: buckets,
169+
isLoading: true,
170+
isPlaceholderData: true,
171+
isError: false,
172+
});
173+
174+
renderWithMantine(<DBHistogramChart config={baseTestConfig} />);
175+
176+
expect(
177+
screen.queryByText('Loading Chart Data...'),
178+
).not.toBeInTheDocument();
179+
expect(chart()).toHaveClass('effect-pulse');
180+
});
181+
182+
it('does not pulse once fresh buckets load', () => {
183+
mockUseQueriedChartConfig.mockReturnValue({
184+
data: buckets,
185+
isLoading: false,
186+
isPlaceholderData: false,
187+
isError: false,
188+
});
189+
190+
renderWithMantine(<DBHistogramChart config={baseTestConfig} />);
191+
192+
expect(chart()).not.toHaveClass('effect-pulse');
193+
});
194+
195+
it('pulses the empty state while a refresh loads', () => {
196+
mockUseQueriedChartConfig.mockReturnValue({
197+
data: { data: [], meta: [] },
198+
isLoading: false,
199+
isPlaceholderData: true,
200+
isError: false,
201+
});
202+
203+
renderWithMantine(<DBHistogramChart config={baseTestConfig} />);
204+
205+
expect(screen.getByText('No data found within time range.')).toHaveClass(
206+
'effect-pulse',
207+
);
208+
});
209+
210+
it('does not pulse a fresh empty result', () => {
211+
mockUseQueriedChartConfig.mockReturnValue({
212+
data: { data: [], meta: [] },
213+
isLoading: false,
214+
isPlaceholderData: false,
215+
isError: false,
216+
});
217+
218+
renderWithMantine(<DBHistogramChart config={baseTestConfig} />);
219+
220+
expect(
221+
screen.getByText('No data found within time range.'),
222+
).not.toHaveClass('effect-pulse');
223+
});
224+
225+
it('shows the loading state before the first buckets arrive', () => {
226+
mockUseQueriedChartConfig.mockReturnValue({
227+
data: undefined,
228+
isLoading: true,
229+
isPlaceholderData: false,
230+
isError: false,
231+
});
232+
233+
renderWithMantine(<DBHistogramChart config={baseTestConfig} />);
234+
235+
expect(screen.getByText('Loading Chart Data...')).toBeInTheDocument();
236+
});
237+
});
159238
});
160239

161240
describe('HISTOGRAM_BAR_COLOR', () => {

‎packages/app/src/components/__tests__/DBListBarChart.test.tsx‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { screen } from '@testing-library/react';
23

34
import DateRangeIndicator from '@/components/charts/DateRangeIndicator';
45
import DBListBarChart from '@/components/DBListBarChart';
@@ -169,4 +170,73 @@ describe('DBListBarChart', () => {
169170
// Verify DateRangeIndicator was not called
170171
expect(jest.mocked(DateRangeIndicator)).not.toHaveBeenCalled();
171172
});
173+
174+
describe('refresh', () => {
175+
const renderChart = () =>
176+
renderWithMantine(
177+
<DBListBarChart
178+
config={baseTestConfig}
179+
valueColumn="value"
180+
groupColumn="group"
181+
/>,
182+
);
183+
184+
it('pulses the previous bars while a refresh loads', () => {
185+
mockUseQueriedChartConfig.mockReturnValue({
186+
data: { data: [{ group: 'checkout', value: 100 }] },
187+
isLoading: false,
188+
isPlaceholderData: true,
189+
isError: false,
190+
});
191+
192+
renderChart();
193+
194+
expect(
195+
screen.getByText('checkout').closest('.effect-pulse'),
196+
).toBeInTheDocument();
197+
});
198+
199+
it('does not pulse once fresh bars load', () => {
200+
mockUseQueriedChartConfig.mockReturnValue({
201+
data: { data: [{ group: 'checkout', value: 100 }] },
202+
isLoading: false,
203+
isPlaceholderData: false,
204+
isError: false,
205+
});
206+
207+
renderChart();
208+
209+
expect(screen.getByText('checkout').closest('.effect-pulse')).toBeNull();
210+
});
211+
212+
it('pulses the empty state while a refresh loads', () => {
213+
mockUseQueriedChartConfig.mockReturnValue({
214+
data: { data: [] },
215+
isLoading: false,
216+
isPlaceholderData: true,
217+
isError: false,
218+
});
219+
220+
renderChart();
221+
222+
expect(screen.getByText('No data found within time range.')).toHaveClass(
223+
'effect-pulse',
224+
);
225+
});
226+
227+
it('does not pulse a fresh empty result', () => {
228+
mockUseQueriedChartConfig.mockReturnValue({
229+
data: { data: [] },
230+
isLoading: false,
231+
isPlaceholderData: false,
232+
isError: false,
233+
});
234+
235+
renderChart();
236+
237+
expect(
238+
screen.getByText('No data found within time range.'),
239+
).not.toHaveClass('effect-pulse');
240+
});
241+
});
172242
});

0 commit comments

Comments
 (0)