Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: loading spinner finishes before all series load #1729

Merged
merged 2 commits into from
Jan 22, 2024
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
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[] = [];
Copy link
Member

Choose a reason for hiding this comment

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

Side note - this could be optimized by using a Set<string> instead of a 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
Loading