Skip to content

Commit e79297b

Browse files
authored
fix: loading spinner finishes before all series load (#1729)
Closes #1654
1 parent 6547814 commit e79297b

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

packages/chart/src/FigureChartModel.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ class FigureChartModel extends ChartModel {
157157
const { charts } = this.figure;
158158
const axisTypeMap = ChartUtils.getAxisTypeMap(this.figure);
159159
const activeSeriesNames: string[] = [];
160+
161+
this.seriesToProcess = new Set();
162+
160163
for (let i = 0; i < charts.length; i += 1) {
161164
const chart = charts[i];
162165

@@ -216,7 +219,6 @@ class FigureChartModel extends ChartModel {
216219
const seriesName = inactiveSeriesNames[i];
217220
this.seriesDataMap.delete(seriesName);
218221
}
219-
this.seriesToProcess = new Set([...this.seriesDataMap.keys()]);
220222
}
221223

222224
/**
@@ -241,6 +243,7 @@ class FigureChartModel extends ChartModel {
241243
);
242244

243245
this.seriesDataMap.set(series.name, seriesData);
246+
this.seriesToProcess.add(series.name);
244247

245248
this.data = [...this.seriesDataMap.values()];
246249

packages/dashboard-core-plugins/src/panels/ChartPanel.test.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ function makeChartPanelWrapper({
9696
);
9797
}
9898

99-
function callUpdateFunction() {
100-
MockChart.mock.calls[MockChart.mock.calls.length - 1][0]?.onUpdate();
99+
function callUpdateFunction(isLoading = false) {
100+
MockChart.mock.calls[MockChart.mock.calls.length - 1][0]?.onUpdate({
101+
isLoading,
102+
});
101103
}
102104

103105
function callErrorFunction() {
@@ -390,6 +392,27 @@ it('shows loading spinner until an error is received B', async () => {
390392
checkPanelOverlays({ container, isLoading: false });
391393
});
392394

395+
it('shows loading spinner until all series to process are loaded', async () => {
396+
const filterFields = [];
397+
const model = makeChartModel({ filterFields });
398+
const modelPromise = Promise.resolve(model);
399+
const makeModel = () => modelPromise;
400+
401+
const { container } = render(makeChartPanelWrapper({ makeModel }));
402+
403+
await act(() => expect(modelPromise).resolves.toBe(model));
404+
405+
// Overlays shouldn't appear yet because we haven't received an update or error event, should just see loading
406+
expectLoading(container);
407+
408+
// Loading spinner should be shown until the update event is received and the isLoading flag is false
409+
callUpdateFunction(true);
410+
expectLoading(container);
411+
412+
callUpdateFunction(false);
413+
expectNotLoading(container);
414+
});
415+
393416
describe('linker column selection', () => {
394417
it('does not show overlay if linker active but no filterable columns', async () => {
395418
const model = makeChartModel();

packages/dashboard-core-plugins/src/panels/ChartPanel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ interface ChartPanelState {
174174
panelState?: GLChartPanelState;
175175
}
176176

177+
interface LoadState {
178+
isLoading: boolean;
179+
}
180+
177181
function hasInputFilter(
178182
panel: PanelProps
179183
): panel is PanelProps & { inputFilters: InputFilter[] } {
@@ -714,8 +718,8 @@ export class ChartPanel extends Component<ChartPanelProps, ChartPanelState> {
714718
this.setActive(!isHidden);
715719
}
716720

717-
handleUpdate(): void {
718-
this.setState({ isLoading: false });
721+
handleUpdate({ isLoading }: LoadState): void {
722+
this.setState({ isLoading });
719723
}
720724

721725
handleClearAllFilters(): void {

0 commit comments

Comments
 (0)