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

perf: Specify component iris in query filters #1320

Merged
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
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
Loading