Skip to content

Commit

Permalink
feat: Load data before changing adding the cube
Browse files Browse the repository at this point in the history
We execute data cubes components query to fill up the cache before
changing the chart config & chart type. This diminish flashes
  • Loading branch information
ptbrowne committed Mar 7, 2024
1 parent 8a21432 commit 3744183
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
46 changes: 44 additions & 2 deletions app/configurator/components/add-dataset-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import {
} from "@mui/material";
import { Theme } from "@mui/material/styles";
import { makeStyles } from "@mui/styles";
import uniqBy from "lodash/uniqBy";
import { FormEvent, useMemo, useState } from "react";

import { DatasetResults, PartialSearchCube } from "@/browser/dataset-browse";
import { getPossibleChartTypes } from "@/charts";
import {
ConfiguratorStateConfiguringChart,
addDatasetInConfig,
isConfiguring,
useConfiguratorState,
} from "@/configurator";
Expand Down Expand Up @@ -284,11 +287,50 @@ const useAddDataset = () => {
currentComponents,
componentQueryResult.data.dataCubesComponents
);

const addDatasetOptions = {
iri,
joinBy: joinBy,
};
const nextState = JSON.parse(
JSON.stringify(state)
) as ConfiguratorStateConfiguringChart;
addDatasetInConfig(nextState, addDatasetOptions);

const allCubes = uniqBy(
nextState.chartConfigs.flatMap((x) => x.cubes),
(x) => x.iri
);
const res = await executeDataCubesComponentsQuery({
locale: locale,
sourceType,
sourceUrl,
cubeFilters: allCubes.map((cube) => ({
iri: cube.iri,
joinBy: cube.joinBy,
loadValues: true,
})),
});

if (res.error || !res.data) {
throw new Error("Could not fetch dimensions and measures");
}
dispatch({
type: "DATASET_ADD",
value: addDatasetOptions,
});
const { dimensions, measures } = res.data.dataCubesComponents;
const possibleType = getPossibleChartTypes({
dimensions: dimensions,
measures: measures,
cubeCount: allCubes.length,
});
dispatch({
type: "CHART_TYPE_CHANGED",
value: {
iri,
joinBy: joinBy,
locale,
chartKey: state.activeChartKey,
chartType: possibleType[0],
},
});
} finally {
Expand Down
1 change: 1 addition & 0 deletions app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ const getInitialConfiguringConfigBasedOnCube = ({
const possibleChartTypes = getPossibleChartTypes({
dimensions: dataCubesComponents.dimensions,
measures: dataCubesComponents.measures,
cubeCount: cubeIris.length,
});
const chartConfig = deriveFiltersFromFields(
getInitialConfig({
Expand Down

0 comments on commit 3744183

Please sign in to comment.