Skip to content

Commit

Permalink
fix: loading spinner finishes before all series load (#1729)
Browse files Browse the repository at this point in the history
Closes #1654
  • Loading branch information
ethanalvizo authored Jan 22, 2024
1 parent 6547814 commit e79297b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/chart/src/FigureChartModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ class FigureChartModel extends ChartModel {
const { charts } = this.figure;
const axisTypeMap = ChartUtils.getAxisTypeMap(this.figure);
const activeSeriesNames: string[] = [];

this.seriesToProcess = new Set();

for (let i = 0; i < charts.length; i += 1) {
const chart = charts[i];

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

/**
Expand All @@ -241,6 +243,7 @@ class FigureChartModel extends ChartModel {
);

this.seriesDataMap.set(series.name, seriesData);
this.seriesToProcess.add(series.name);

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

Expand Down
27 changes: 25 additions & 2 deletions packages/dashboard-core-plugins/src/panels/ChartPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ function makeChartPanelWrapper({
);
}

function callUpdateFunction() {
MockChart.mock.calls[MockChart.mock.calls.length - 1][0]?.onUpdate();
function callUpdateFunction(isLoading = false) {
MockChart.mock.calls[MockChart.mock.calls.length - 1][0]?.onUpdate({
isLoading,
});
}

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

it('shows loading spinner until all series to process are loaded', async () => {
const filterFields = [];
const model = makeChartModel({ filterFields });
const modelPromise = Promise.resolve(model);
const makeModel = () => modelPromise;

const { container } = render(makeChartPanelWrapper({ makeModel }));

await act(() => expect(modelPromise).resolves.toBe(model));

// Overlays shouldn't appear yet because we haven't received an update or error event, should just see loading
expectLoading(container);

// Loading spinner should be shown until the update event is received and the isLoading flag is false
callUpdateFunction(true);
expectLoading(container);

callUpdateFunction(false);
expectNotLoading(container);
});

describe('linker column selection', () => {
it('does not show overlay if linker active but no filterable columns', async () => {
const model = makeChartModel();
Expand Down
8 changes: 6 additions & 2 deletions packages/dashboard-core-plugins/src/panels/ChartPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ interface ChartPanelState {
panelState?: GLChartPanelState;
}

interface LoadState {
isLoading: boolean;
}

function hasInputFilter(
panel: PanelProps
): panel is PanelProps & { inputFilters: InputFilter[] } {
Expand Down Expand Up @@ -714,8 +718,8 @@ export class ChartPanel extends Component<ChartPanelProps, ChartPanelState> {
this.setActive(!isHidden);
}

handleUpdate(): void {
this.setState({ isLoading: false });
handleUpdate({ isLoading }: LoadState): void {
this.setState({ isLoading });
}

handleClearAllFilters(): void {
Expand Down

0 comments on commit e79297b

Please sign in to comment.