Skip to content

Commit

Permalink
Merge pull request #1320 from visualize-admin/perf/specifiy-component…
Browse files Browse the repository at this point in the history
…s-iris-for-observation-query

perf: Specify component iris in query filters
  • Loading branch information
bprusinowski authored Jan 29, 2024
2 parents 21a6347 + 8aa3aee commit 4ac7d78
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 44 deletions.
1 change: 1 addition & 0 deletions app/browse/datatable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export const DataSetTable = ({
chartConfig,
dimensions: componentsData?.dataCubesComponents?.dimensions,
measures: componentsData?.dataCubesComponents?.measures,
componentIris,
});
const [{ data: observationsData }] = useDataCubesObservationsQuery({
variables: {
Expand Down
5 changes: 3 additions & 2 deletions app/charts/shared/chart-data-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ export const ChartDataFilters = (props: ChartDataFiltersProps) => {
const { dataSource, chartConfig, dimensions, measures } = props;
const { loading } = useLoadingState();
const dataFilters = useInteractiveFilters((d) => d.dataFilters);
const componentIris = chartConfig.interactiveFiltersConfig?.dataFilters
.componentIris as string[];
const queryFilters = useQueryFilters({
chartConfig,
dimensions,
measures,
allowNoneValues: true,
componentIris,
});
const componentIris = chartConfig.interactiveFiltersConfig?.dataFilters
.componentIris as string[];
const [filtersVisible, setFiltersVisible] = React.useState(false);

React.useEffect(() => {
Expand Down
44 changes: 4 additions & 40 deletions app/charts/shared/chart-helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ export const useQueryFilters = ({
dimensions,
measures,
allowNoneValues,
componentIris,
}: {
chartConfig: ChartConfig;
dimensions?: Dimension[];
measures?: Measure[];
allowNoneValues?: boolean;
componentIris?: string[];
}): DataCubeObservationFilter[] | undefined => {
const allDataFilters = useInteractiveFilters((d) => d.dataFilters);

Expand All @@ -94,10 +96,7 @@ export const useQueryFilters = ({

return {
iri: cube.iri,
// componentIris: getComponentIris(cube.iri, {
// dimensions,
// measures,
// }),
componentIris,
filters: prepareQueryFilters(
chartConfig.chartType,
filters,
Expand All @@ -116,45 +115,10 @@ export const useQueryFilters = ({
allowNoneValues,
dimensions,
measures,
componentIris,
]);
};

// Handle correctly when improving performance of data fetching!
// const getComponentIris = (
// cubeIri: string,
// options: {
// dimensions: Dimension[];
// measures: Measure[];
// }
// ) => {
// const { dimensions, measures } = options;

// if (dimensions.length === 0 && measures.length === 0) {
// return;
// }

// const filteredDimensionIris: string[] = [];

// for (const dimension of dimensions) {
// if (dimension.isJoinByDimension) {
// if (dimension.originalIris.some((d) => d.cubeIri === cubeIri)) {
// filteredDimensionIris.push(
// ...dimension.originalIris.map((d) => d.dimensionIri)
// );
// }
// } else {
// if (dimension.cubeIri === cubeIri) {
// filteredDimensionIris.push(dimension.iri);
// }
// }
// }

// return [
// ...filteredDimensionIris,
// ...measures.filter((d) => d.cubeIri === cubeIri).map((d) => d.iri),
// ];
// };

type IFKey = keyof NonNullable<InteractiveFiltersConfig>;

export const getChartConfigFilterComponentIris = ({ cubes }: ChartConfig) => {
Expand Down
6 changes: 5 additions & 1 deletion app/components/chart-filters-list.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Box, Typography } from "@mui/material";
import React, { Fragment } from "react";

import { useQueryFilters } from "@/charts/shared/chart-helpers";
import {
extractChartConfigComponentIris,
useQueryFilters,
} from "@/charts/shared/chart-helpers";
import { OpenMetadataPanelWrapper } from "@/components/metadata-panel";
import {
ChartConfig,
Expand Down Expand Up @@ -38,6 +41,7 @@ export const ChartFiltersList = (props: ChartFiltersListProps) => {
chartConfig,
dimensions,
measures,
componentIris: extractChartConfigComponentIris(chartConfig),
});
const [{ data }] = useDataCubesComponentsQuery({
variables: {
Expand Down
6 changes: 5 additions & 1 deletion app/components/chart-footnotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { Box, Button, Link, Theme, Typography } from "@mui/material";
import { makeStyles } from "@mui/styles";
import { PropsWithChildren, useEffect, useState } from "react";

import { useQueryFilters } from "@/charts/shared/chart-helpers";
import {
extractChartConfigComponentIris,
useQueryFilters,
} from "@/charts/shared/chart-helpers";
import { useChartTablePreview } from "@/components/chart-table-preview";
import { DataDownloadMenu, RunSparqlQuery } from "@/components/data-download";
import { ChartConfig, DataSource } from "@/configurator";
Expand Down Expand Up @@ -73,6 +76,7 @@ export const ChartFootnotes = ({
chartConfig,
dimensions,
measures,
componentIris: extractChartConfigComponentIris(chartConfig),
});
const commonQueryVariables = {
sourceType: dataSource.type,
Expand Down
1 change: 1 addition & 0 deletions app/components/chart-with-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const GenericChart = (props: GenericChartProps) => {
chartConfig,
dimensions,
measures,
componentIris,
});
const commonProps = {
dataSource,
Expand Down

1 comment on commit 4ac7d78

@vercel
Copy link

@vercel vercel bot commented on 4ac7d78 Jan 29, 2024

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

visualization-tool – ./

visualization-tool-git-main-ixt1.vercel.app
visualization-tool-alpha.vercel.app
visualization-tool-ixt1.vercel.app

Please sign in to comment.