From a8b5bacb9eccb4bdac34387ad481deeeb8c86509 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Thu, 13 Apr 2023 17:31:46 +0200 Subject: [PATCH] refactor: Use DataCubeMetadata + Components queries --- app/charts/index.spec.ts | 30 ++++---- app/charts/index.ts | 8 +-- app/components/chart-filters-list.tsx | 4 +- app/components/chart-preview.tsx | 32 ++++++--- app/components/chart-published.tsx | 32 ++++++--- app/components/chart-selection-tabs.tsx | 29 ++++++-- .../components/chart-configurator.tsx | 5 +- .../components/chart-type-selector.tsx | 12 ++-- app/configurator/configurator-state.tsx | 41 ++++++++--- .../interactive-filters/helpers.ts | 6 +- .../interactive-filters-config-options.tsx | 13 ++-- .../interactive-filters-configurator.tsx | 4 +- app/graphql/apollo-sentry-plugin.ts | 3 +- app/graphql/queries/data-cubes.graphql | 35 --------- app/graphql/query-hooks.ts | 72 ------------------- app/graphql/types.ts | 10 +-- app/scripts/cube.ts | 31 ++++---- app/utils/opendata.ts | 9 +-- 18 files changed, 159 insertions(+), 217 deletions(-) diff --git a/app/charts/index.spec.ts b/app/charts/index.spec.ts index 039df36077..ac11d31ac0 100644 --- a/app/charts/index.spec.ts +++ b/app/charts/index.spec.ts @@ -1,6 +1,5 @@ import { TableFields } from "@/configurator"; -import { DataCubeMetadataWithComponentValuesQuery } from "@/graphql/query-hooks"; -import { DataCubeMetadata } from "@/graphql/types"; +import { ComponentsQuery } from "@/graphql/query-hooks"; import bathingWaterData from "../test/__fixtures/data/DataCubeMetadataWithComponentValues-bathingWater.json"; import forestAreaData from "../test/__fixtures/data/forest-area-by-production-region.json"; @@ -12,10 +11,10 @@ describe("initial config", () => { const config = getInitialConfig({ chartType: "table", dimensions: forestAreaData.data.dataCubeByIri.dimensions as NonNullable< - DataCubeMetadataWithComponentValuesQuery["dataCubeByIri"] + ComponentsQuery["dataCubeByIri"] >["dimensions"], measures: forestAreaData.data.dataCubeByIri.measures as NonNullable< - DataCubeMetadataWithComponentValuesQuery["dataCubeByIri"] + ComponentsQuery["dataCubeByIri"] >["measures"], }); expect( @@ -40,28 +39,31 @@ describe("possible chart types", () => { it("should allow appropriate chart types based on available dimensions", () => { const expectedChartTypes = ["area", "column", "line", "pie", "table"]; const possibleChartTypes = getPossibleChartType({ - metadata: bathingWaterData.data.dataCubeByIri as DataCubeMetadata, + dimensions: bathingWaterData.data.dataCubeByIri.dimensions as NonNullable< + ComponentsQuery["dataCubeByIri"] + >["dimensions"], + measures: bathingWaterData.data.dataCubeByIri.measures as NonNullable< + ComponentsQuery["dataCubeByIri"] + >["measures"], }).sort(); expect(possibleChartTypes).toEqual(expectedChartTypes); }); it("should only allow table if there are only measures available", () => { - const metadata = { + const possibleChartTypes = getPossibleChartType({ dimensions: [], - measures: [{ __typename: "NumericalMeasure" }], - } as any; - const possibleChartTypes = getPossibleChartType({ metadata }).sort(); + measures: [{ __typename: "NumericalMeasure" }] as any, + }); expect(possibleChartTypes).toEqual(["table"]); }); it("should only allow column, map, pie and table if only geo dimensions are available", () => { - const metadata = { - dimensions: [{ __typename: "GeoShapesDimension" }], - measures: [{ __typename: "NumericalMeasure" }], - } as any; - const possibleChartTypes = getPossibleChartType({ metadata }).sort(); + const possibleChartTypes = getPossibleChartType({ + dimensions: [{ __typename: "GeoShapesDimension" }] as any, + measures: [{ __typename: "NumericalMeasure" }] as any, + }).sort(); expect(possibleChartTypes).toEqual(["column", "map", "pie", "table"]); }); diff --git a/app/charts/index.ts b/app/charts/index.ts index 8fcfcf427d..fe29d2e075 100644 --- a/app/charts/index.ts +++ b/app/charts/index.ts @@ -1108,12 +1108,12 @@ const adjustSegmentSorting = ({ // Helpers export const getPossibleChartType = ({ - metadata, + dimensions, + measures, }: { - metadata: DataCubeMetadata; + dimensions: DimensionMetadataFragment[]; + measures: DimensionMetadataFragment[]; }): ChartType[] => { - const { measures, dimensions } = metadata; - const numericalMeasures = measures.filter(isNumericalMeasure); const ordinalMeasures = measures.filter(isOrdinalMeasure); const categoricalDimensions = getCategoricalDimensions(dimensions); diff --git a/app/components/chart-filters-list.tsx b/app/components/chart-filters-list.tsx index b61dd2dfee..383a19471d 100644 --- a/app/components/chart-filters-list.tsx +++ b/app/components/chart-filters-list.tsx @@ -6,7 +6,7 @@ import { OpenMetadataPanelWrapper } from "@/components/metadata-panel"; import { ChartConfig, DataSource } from "@/configurator"; import { isTemporalDimension } from "@/domain/data"; import { useTimeFormatUnit } from "@/formatters"; -import { useDataCubeMetadataWithComponentValuesQuery } from "@/graphql/query-hooks"; +import { useComponentsQuery } from "@/graphql/query-hooks"; import { useLocale } from "@/locales/use-locale"; export const ChartFiltersList = ({ @@ -21,7 +21,7 @@ export const ChartFiltersList = ({ const locale = useLocale(); const timeFormatUnit = useTimeFormatUnit(); - const [{ data }] = useDataCubeMetadataWithComponentValuesQuery({ + const [{ data }] = useComponentsQuery({ variables: { iri: dataSetIri, sourceType: dataSource.type, diff --git a/app/components/chart-preview.tsx b/app/components/chart-preview.tsx index 676fe7a03d..350ff062b2 100644 --- a/app/components/chart-preview.tsx +++ b/app/components/chart-preview.tsx @@ -24,8 +24,8 @@ import { MetadataPanel } from "@/components/metadata-panel"; import { ChartConfig, DataSource, useConfiguratorState } from "@/configurator"; import { DataSetTable } from "@/configurator/components/datatable"; import { - DimensionMetadataFragment, - useDataCubeMetadataWithComponentValuesQuery, + useComponentsQuery, + useDataCubeMetadataQuery, } from "@/graphql/query-hooks"; import { DataCubePublicationStatus } from "@/graphql/resolver-types"; import { useLocale } from "@/locales/use-locale"; @@ -72,7 +72,15 @@ export const ChartPreviewInner = ({ const [state, dispatch] = useConfiguratorState(); const locale = useLocale(); const classes = useStyles(); - const [{ data: metaData }] = useDataCubeMetadataWithComponentValuesQuery({ + const [{ data: metadata }] = useDataCubeMetadataQuery({ + variables: { + iri: dataSetIri, + sourceType: dataSource.type, + sourceUrl: dataSource.url, + locale, + }, + }); + const [{ data: components }] = useComponentsQuery({ variables: { iri: dataSetIri, sourceType: dataSource.type, @@ -89,12 +97,16 @@ export const ChartPreviewInner = ({ const handleToggleTableView = useEvent(() => setIsTablePreview((c) => !c)); - const allDimensions: DimensionMetadataFragment[] = useMemo(() => { + const allComponents = useMemo(() => { + if (!components?.dataCubeByIri) { + return []; + } + return [ - ...(metaData?.dataCubeByIri?.dimensions ?? []), - ...(metaData?.dataCubeByIri?.measures ?? []), + ...components.dataCubeByIri.dimensions, + ...components.dataCubeByIri.measures, ]; - }, [metaData?.dataCubeByIri?.dimensions, metaData?.dataCubeByIri?.measures]); + }, [components?.dataCubeByIri]); return ( - {metaData?.dataCubeByIri?.publicationStatus === + {metadata?.dataCubeByIri?.publicationStatus === DataCubePublicationStatus.Draft && ( @@ -154,14 +166,14 @@ export const ChartPreviewInner = ({ {state.meta.title[locale] === "" - ? metaData?.dataCubeByIri?.title + ? metadata?.dataCubeByIri?.title : state.meta.title[locale]}{" "} - visualize.admin.ch diff --git a/app/components/chart-published.tsx b/app/components/chart-published.tsx index 6adc0373ac..5a5909ef3d 100644 --- a/app/components/chart-published.tsx +++ b/app/components/chart-published.tsx @@ -40,8 +40,8 @@ import { useIsTrustedDataSource, } from "@/domain/datasource"; import { - DimensionMetadataFragment, - useDataCubeMetadataWithComponentValuesQuery, + useComponentsQuery, + useDataCubeMetadataQuery, } from "@/graphql/query-hooks"; import { DataCubePublicationStatus } from "@/graphql/resolver-types"; import { useLocale } from "@/locales/use-locale"; @@ -139,7 +139,15 @@ export const ChartPublishedInner = ({ const locale = useLocale(); const isTrustedDataSource = useIsTrustedDataSource(dataSource); - const [{ data: metaData }] = useDataCubeMetadataWithComponentValuesQuery({ + const [{ data: metadata }] = useDataCubeMetadataQuery({ + variables: { + iri: dataSet, + sourceType: dataSource.type, + sourceUrl: dataSource.url, + locale, + }, + }); + const [{ data: components }] = useComponentsQuery({ variables: { iri: dataSet, sourceType: dataSource.type, @@ -157,12 +165,16 @@ export const ChartPublishedInner = ({ }, [chartConfig, dataSource]); const handleToggleTableView = useEvent(() => setIsTablePreview((c) => !c)); - const allDimensions: DimensionMetadataFragment[] = useMemo(() => { + const allComponents = useMemo(() => { + if (!components?.dataCubeByIri) { + return []; + } + return [ - ...(metaData?.dataCubeByIri?.dimensions ?? []), - ...(metaData?.dataCubeByIri?.measures ?? []), + ...components.dataCubeByIri.dimensions, + ...components.dataCubeByIri.measures, ]; - }, [metaData?.dataCubeByIri?.dimensions, metaData?.dataCubeByIri?.measures]); + }, [components?.dataCubeByIri]); const [{ showDownload }] = useEmbedOptions(); @@ -170,7 +182,7 @@ export const ChartPublishedInner = ({ - {metaData?.dataCubeByIri?.publicationStatus === + {metadata?.dataCubeByIri?.publicationStatus === DataCubePublicationStatus.Draft && ( @@ -182,7 +194,7 @@ export const ChartPublishedInner = ({ )} - {metaData?.dataCubeByIri?.expires && ( + {metadata?.dataCubeByIri?.expires && ( @@ -220,7 +232,7 @@ export const ChartPublishedInner = ({ diff --git a/app/components/chart-selection-tabs.tsx b/app/components/chart-selection-tabs.tsx index cecf31f299..b255c1d2df 100644 --- a/app/components/chart-selection-tabs.tsx +++ b/app/components/chart-selection-tabs.tsx @@ -1,10 +1,10 @@ import { Trans } from "@lingui/macro"; -import { Box, Popover, Tab, Tabs, Theme, Button } from "@mui/material"; +import { Box, Button, Popover, Tab, Tabs, Theme } from "@mui/material"; import { makeStyles } from "@mui/styles"; import React, { - createContext, Dispatch, ReactNode, + createContext, useContext, useEffect, useState, @@ -18,7 +18,10 @@ import { } from "@/configurator"; import { ChartTypeSelector } from "@/configurator/components/chart-type-selector"; import { getIconName } from "@/configurator/components/ui-helpers"; -import { useDataCubeMetadataWithComponentValuesQuery } from "@/graphql/query-hooks"; +import { + useComponentsQuery, + useDataCubeMetadataQuery, +} from "@/graphql/query-hooks"; import { Icon, IconName } from "@/icons"; import { useLocale } from "@/src"; import useEvent from "@/utils/use-event"; @@ -155,7 +158,16 @@ const PublishChartButton = () => { | ConfiguratorStatePublishing | ConfiguratorStateConfiguringChart; const locale = useLocale(); - const [{ data }] = useDataCubeMetadataWithComponentValuesQuery({ + const [{ data: metadata }] = useDataCubeMetadataQuery({ + variables: { + iri: dataSetIri ?? "", + sourceType: state.dataSource.type, + sourceUrl: state.dataSource.url, + locale, + }, + pause: !dataSetIri, + }); + const [{ data: components }] = useComponentsQuery({ variables: { iri: dataSetIri ?? "", sourceType: state.dataSource.type, @@ -165,10 +177,13 @@ const PublishChartButton = () => { pause: !dataSetIri, }); const goNext = useEvent(() => { - if (data?.dataCubeByIri) { + if (metadata?.dataCubeByIri && components?.dataCubeByIri) { dispatch({ type: "STEP_NEXT", - dataSetMetadata: data?.dataCubeByIri, + dataSetMetadata: { + ...metadata.dataCubeByIri, + ...components.dataCubeByIri, + }, }); } }); @@ -177,7 +192,7 @@ const PublishChartButton = () => { diff --git a/app/configurator/components/chart-configurator.tsx b/app/configurator/components/chart-configurator.tsx index a22af10fc4..3d2d90be1f 100644 --- a/app/configurator/components/chart-configurator.tsx +++ b/app/configurator/components/chart-configurator.tsx @@ -61,7 +61,6 @@ import { } from "@/configurator/configurator-state"; import { isStandardErrorDimension, isTemporalDimension } from "@/domain/data"; import { - DataCubeMetadataWithComponentValuesQuery, HierarchyValue, PossibleFiltersDocument, PossibleFiltersQuery, @@ -266,9 +265,7 @@ const useEnsurePossibleFilters = ({ }; type Dimension = NonNullable< - NonNullable< - DataCubeMetadataWithComponentValuesQuery["dataCubeByIri"] - >["dimensions"] + NonNullable["dimensions"] >[number]; const useFilterReorder = ({ diff --git a/app/configurator/components/chart-type-selector.tsx b/app/configurator/components/chart-type-selector.tsx index 6b3146b70c..a6ce06c435 100644 --- a/app/configurator/components/chart-type-selector.tsx +++ b/app/configurator/components/chart-type-selector.tsx @@ -11,7 +11,7 @@ import { ControlSectionSkeleton } from "@/configurator/components/chart-controls import { getFieldLabel } from "@/configurator/components/field-i18n"; import { getIconName } from "@/configurator/components/ui-helpers"; import { FieldProps, useChartType } from "@/configurator/config-form"; -import { useDataCubeMetadataWithComponentValuesQuery } from "@/graphql/query-hooks"; +import { useComponentsQuery } from "@/graphql/query-hooks"; import { Icon } from "@/icons"; import { useLocale } from "@/locales/use-locale"; @@ -109,7 +109,7 @@ export const ChartTypeSelector = ({ } & BoxProps) => { const locale = useLocale(); const { value: chartType, onChange: onChangeChartType } = useChartType(); - const [{ data }] = useDataCubeMetadataWithComponentValuesQuery({ + const [{ data }] = useComponentsQuery({ variables: { iri: state.dataSet, sourceType: state.dataSource.type, @@ -117,13 +117,15 @@ export const ChartTypeSelector = ({ locale, }, }); - const metadata = data?.dataCubeByIri; - if (!metadata) { + if (!data?.dataCubeByIri) { return ; } - const possibleChartTypes = getPossibleChartType({ metadata }); + const possibleChartTypes = getPossibleChartType({ + dimensions: data.dataCubeByIri.dimensions, + measures: data.dataCubeByIri.measures, + }); return ( diff --git a/app/configurator/configurator-state.tsx b/app/configurator/configurator-state.tsx index 19776011de..18914d84f0 100644 --- a/app/configurator/configurator-state.tsx +++ b/app/configurator/configurator-state.tsx @@ -71,6 +71,12 @@ import { import { DEFAULT_DATA_SOURCE } from "@/domain/datasource"; import { client } from "@/graphql/client"; import { + ComponentsWithHierarchiesDocument, + ComponentsWithHierarchiesQuery, + ComponentsWithHierarchiesQueryVariables, + DataCubeMetadataDocument, + DataCubeMetadataQuery, + DataCubeMetadataQueryVariables, DataCubeMetadataWithComponentValuesAndHierarchiesDocument, DataCubeMetadataWithComponentValuesAndHierarchiesQuery, DataCubeMetadataWithComponentValuesAndHierarchiesQueryVariables, @@ -565,7 +571,8 @@ const transitionStepNext = ( case "SELECTING_DATASET": if (draft.dataSet) { const possibleChartTypes = getPossibleChartType({ - metadata: dataSetMetadata, + dimensions: dataSetMetadata.dimensions, + measures: dataSetMetadata.measures, }); const chartConfig = deriveFiltersFromFields( @@ -1466,25 +1473,37 @@ export const initChartStateFromCube = async ( dataSource: DataSource, locale: string ): Promise => { - const { data } = await client + const { data: metadata } = await client + .query( + DataCubeMetadataDocument, + { + iri: datasetIri, + sourceType: dataSource.type, + sourceUrl: dataSource.url, + locale, + } + ) + .toPromise(); + const { data: components } = await client .query< - DataCubeMetadataWithComponentValuesAndHierarchiesQuery, - DataCubeMetadataWithComponentValuesAndHierarchiesQueryVariables - >(DataCubeMetadataWithComponentValuesAndHierarchiesDocument, { + ComponentsWithHierarchiesQuery, + ComponentsWithHierarchiesQueryVariables + >(ComponentsWithHierarchiesDocument, { iri: datasetIri, sourceType: dataSource.type, sourceUrl: dataSource.url, locale, }) .toPromise(); - if (!data || !data?.dataCubeByIri) { + + if (metadata?.dataCubeByIri && components?.dataCubeByIri) { + return transitionStepNext( + getStateWithCurrentDataSource({ ...emptyState, dataSet: datasetIri }), + { ...metadata.dataCubeByIri, ...components.dataCubeByIri } + ); + } else { console.warn(`Could not fetch cube with iri ${datasetIri}`); - return; } - return transitionStepNext( - getStateWithCurrentDataSource({ ...emptyState, dataSet: datasetIri }), - data.dataCubeByIri - ); }; /** diff --git a/app/configurator/interactive-filters/helpers.ts b/app/configurator/interactive-filters/helpers.ts index 220c18c6b3..8b9d2e2b23 100644 --- a/app/configurator/interactive-filters/helpers.ts +++ b/app/configurator/interactive-filters/helpers.ts @@ -1,11 +1,11 @@ import { getFieldComponentIri, getFieldComponentIris } from "@/charts"; import { isTemporalDimension } from "@/domain/data"; import { - DataCubeMetadataWithComponentValuesQuery, DimensionMetadataFragment, TemporalDimension, TimeUnit, } from "@/graphql/query-hooks"; +import { DataCubeMetadata } from "@/graphql/types"; import { ChartConfig, @@ -42,9 +42,7 @@ export const getTimeSliderFilterDimensions = ({ export const getDataFilterDimensions = ( chartConfig: ConfiguratorStateConfiguringChart["chartConfig"], - dataCube: NonNullable< - DataCubeMetadataWithComponentValuesQuery["dataCubeByIri"] - > + dataCube: DataCubeMetadata ) => { const mappedIris = getFieldComponentIris(chartConfig.fields); // Dimensions that are not encoded in the visualization diff --git a/app/configurator/interactive-filters/interactive-filters-config-options.tsx b/app/configurator/interactive-filters/interactive-filters-config-options.tsx index 8d43707079..4688eb4ff5 100644 --- a/app/configurator/interactive-filters/interactive-filters-config-options.tsx +++ b/app/configurator/interactive-filters/interactive-filters-config-options.tsx @@ -2,7 +2,7 @@ import { t, Trans } from "@lingui/macro"; import { Box } from "@mui/material"; import { extent } from "d3"; import get from "lodash/get"; -import React, { useEffect, useMemo, useRef } from "react"; +import { useEffect, useMemo, useRef } from "react"; import { getFieldComponentIri } from "@/charts"; import { Checkbox, Select } from "@/components/form"; @@ -21,10 +21,7 @@ import { } from "@/configurator/interactive-filters/interactive-filters-config-state"; import { InteractiveFilterType } from "@/configurator/interactive-filters/interactive-filters-configurator"; import { useFormatFullDateAuto } from "@/formatters"; -import { - TemporalDimension, - useDataCubeMetadataWithComponentValuesQuery, -} from "@/graphql/query-hooks"; +import { TemporalDimension, useComponentsQuery } from "@/graphql/query-hooks"; import { useLocale } from "@/locales/use-locale"; import { FIELD_VALUE_NONE } from "../constants"; @@ -40,7 +37,7 @@ export const InteractiveFiltersOptions = ({ const activeField = state.activeField as InteractiveFilterType; const locale = useLocale(); - const [{ data }] = useDataCubeMetadataWithComponentValuesQuery({ + const [{ data }] = useComponentsQuery({ variables: { iri: dataSet, sourceType: dataSource.type, @@ -123,7 +120,7 @@ const InteractiveTimeRangeFilterOptions = ({ const locale = useLocale(); const formatDateAuto = useFormatFullDateAuto(); - const [{ data }] = useDataCubeMetadataWithComponentValuesQuery({ + const [{ data }] = useComponentsQuery({ variables: { iri: state.dataSet, sourceType: state.dataSource.type, @@ -200,7 +197,7 @@ const InteractiveTimeSliderFilterOptions = ({ state: ConfiguratorStateConfiguringChart; }) => { const locale = useLocale(); - const [{ data }] = useDataCubeMetadataWithComponentValuesQuery({ + const [{ data }] = useComponentsQuery({ variables: { iri: dataSet, sourceType: dataSource.type, diff --git a/app/configurator/interactive-filters/interactive-filters-configurator.tsx b/app/configurator/interactive-filters/interactive-filters-configurator.tsx index 3cf7ea86d4..efe477eaa8 100644 --- a/app/configurator/interactive-filters/interactive-filters-configurator.tsx +++ b/app/configurator/interactive-filters/interactive-filters-configurator.tsx @@ -18,7 +18,7 @@ import { } from "@/configurator/configurator-state"; import { isTemporalDimension } from "@/domain/data"; import { flag } from "@/flags/flag"; -import { useDataCubeMetadataWithComponentValuesQuery } from "@/graphql/query-hooks"; +import { useComponentsQuery } from "@/graphql/query-hooks"; import { useLocale } from "@/locales/use-locale"; import { getTimeSliderFilterDimensions } from "./helpers"; @@ -49,7 +49,7 @@ export const InteractiveFiltersConfigurator = ({ }) => { const { chartType, fields } = chartConfig; const locale = useLocale(); - const [{ data }] = useDataCubeMetadataWithComponentValuesQuery({ + const [{ data }] = useComponentsQuery({ variables: { iri: dataSet, sourceType: dataSource.type, diff --git a/app/graphql/apollo-sentry-plugin.ts b/app/graphql/apollo-sentry-plugin.ts index 1b9584d0f0..4f897a3f95 100644 --- a/app/graphql/apollo-sentry-plugin.ts +++ b/app/graphql/apollo-sentry-plugin.ts @@ -7,7 +7,8 @@ const getDataCubeIri = (req: GraphQLRequest) => { operationName === "DataCubePreview" || operationName === "DataCubeMetadata" || operationName === "DataCubeObservations" || - operationName === "DataCubeMetadataWithComponentValues" || + operationName === "Components" || + operationName === "ComponentsWithHierarchies" || operationName === "PossibleFilters" ) { return variables?.iri; diff --git a/app/graphql/queries/data-cubes.graphql b/app/graphql/queries/data-cubes.graphql index 57c0444cdb..e0904da308 100644 --- a/app/graphql/queries/data-cubes.graphql +++ b/app/graphql/queries/data-cubes.graphql @@ -183,41 +183,6 @@ query DataCubeMetadata( } } -query DataCubeMetadataWithComponentValues( - $iri: String! - $sourceType: String! - $sourceUrl: String! - $locale: String! - $latest: Boolean - $filters: Filters -) { - dataCubeByIri( - iri: $iri - sourceType: $sourceType - sourceUrl: $sourceUrl - locale: $locale - latest: $latest - ) { - iri - title - publisher - publicationStatus - expires - identifier - workExamples - creator { - iri - } - landingPage - dimensions(sourceType: $sourceType, sourceUrl: $sourceUrl) { - ...dimensionMetadata - } - measures(sourceType: $sourceType, sourceUrl: $sourceUrl) { - ...dimensionMetadata - } - } -} - query DataCubeMetadataWithComponentValuesAndHierarchies( $iri: String! $sourceType: String! diff --git a/app/graphql/query-hooks.ts b/app/graphql/query-hooks.ts index f13c1600ec..6cc8a9fafa 100644 --- a/app/graphql/query-hooks.ts +++ b/app/graphql/query-hooks.ts @@ -755,45 +755,6 @@ export type DataCubeMetadataQueryVariables = Exact<{ export type DataCubeMetadataQuery = { __typename: 'Query', dataCubeByIri?: Maybe<{ __typename: 'DataCube', iri: string, identifier?: Maybe, title: string, description?: Maybe, publisher?: Maybe, version?: Maybe, workExamples?: Maybe>>, contactName?: Maybe, contactEmail?: Maybe, landingPage?: Maybe, expires?: Maybe, datePublished?: Maybe, dateModified?: Maybe, publicationStatus: DataCubePublicationStatus, themes: Array<{ __typename: 'DataCubeTheme', iri: string, label?: Maybe }>, creator?: Maybe<{ __typename: 'DataCubeOrganization', iri: string, label?: Maybe }> }> }; -export type DataCubeMetadataWithComponentValuesQueryVariables = Exact<{ - iri: Scalars['String']; - sourceType: Scalars['String']; - sourceUrl: Scalars['String']; - locale: Scalars['String']; - latest?: Maybe; - filters?: Maybe; -}>; - - -export type DataCubeMetadataWithComponentValuesQuery = { __typename: 'Query', dataCubeByIri?: Maybe<{ __typename: 'DataCube', iri: string, title: string, publisher?: Maybe, publicationStatus: DataCubePublicationStatus, expires?: Maybe, identifier?: Maybe, workExamples?: Maybe>>, landingPage?: Maybe, creator?: Maybe<{ __typename: 'DataCubeOrganization', iri: string }>, dimensions: Array<( - { __typename: 'GeoCoordinatesDimension' } - & DimensionMetadata_GeoCoordinatesDimension_Fragment - ) | ( - { __typename: 'GeoShapesDimension' } - & DimensionMetadata_GeoShapesDimension_Fragment - ) | ( - { __typename: 'NominalDimension' } - & DimensionMetadata_NominalDimension_Fragment - ) | ( - { __typename: 'NumericalMeasure' } - & DimensionMetadata_NumericalMeasure_Fragment - ) | ( - { __typename: 'OrdinalDimension' } - & DimensionMetadata_OrdinalDimension_Fragment - ) | ( - { __typename: 'OrdinalMeasure' } - & DimensionMetadata_OrdinalMeasure_Fragment - ) | ( - { __typename: 'TemporalDimension' } - & DimensionMetadata_TemporalDimension_Fragment - )>, measures: Array<( - { __typename: 'NumericalMeasure' } - & DimensionMetadata_NumericalMeasure_Fragment - ) | ( - { __typename: 'OrdinalMeasure' } - & DimensionMetadata_OrdinalMeasure_Fragment - )> }> }; - export type DataCubeMetadataWithComponentValuesAndHierarchiesQueryVariables = Exact<{ iri: Scalars['String']; sourceType: Scalars['String']; @@ -1304,39 +1265,6 @@ export const DataCubeMetadataDocument = gql` export function useDataCubeMetadataQuery(options: Omit, 'query'> = {}) { return Urql.useQuery({ query: DataCubeMetadataDocument, ...options }); }; -export const DataCubeMetadataWithComponentValuesDocument = gql` - query DataCubeMetadataWithComponentValues($iri: String!, $sourceType: String!, $sourceUrl: String!, $locale: String!, $latest: Boolean, $filters: Filters) { - dataCubeByIri( - iri: $iri - sourceType: $sourceType - sourceUrl: $sourceUrl - locale: $locale - latest: $latest - ) { - iri - title - publisher - publicationStatus - expires - identifier - workExamples - creator { - iri - } - landingPage - dimensions(sourceType: $sourceType, sourceUrl: $sourceUrl) { - ...dimensionMetadata - } - measures(sourceType: $sourceType, sourceUrl: $sourceUrl) { - ...dimensionMetadata - } - } -} - ${DimensionMetadataFragmentDoc}`; - -export function useDataCubeMetadataWithComponentValuesQuery(options: Omit, 'query'> = {}) { - return Urql.useQuery({ query: DataCubeMetadataWithComponentValuesDocument, ...options }); -}; export const DataCubeMetadataWithComponentValuesAndHierarchiesDocument = gql` query DataCubeMetadataWithComponentValuesAndHierarchies($iri: String!, $sourceType: String!, $sourceUrl: String!, $locale: String!, $latest: Boolean, $filters: Filters) { dataCubeByIri( diff --git a/app/graphql/types.ts b/app/graphql/types.ts index 05e9a261c4..4e2c834940 100644 --- a/app/graphql/types.ts +++ b/app/graphql/types.ts @@ -1,12 +1,14 @@ import { - DataCubeMetadataWithComponentValuesAndHierarchiesQuery, - DataCubeMetadataWithComponentValuesQuery, + ComponentsQuery, + ComponentsWithHierarchiesQuery, + DataCubeMetadataQuery, } from "./query-hooks"; export type DataCubeMetadata = NonNullable< - DataCubeMetadataWithComponentValuesQuery["dataCubeByIri"] + DataCubeMetadataQuery["dataCubeByIri"] & ComponentsQuery["dataCubeByIri"] >; export type DataCubeMetadataWithHierarchies = NonNullable< - DataCubeMetadataWithComponentValuesAndHierarchiesQuery["dataCubeByIri"] + DataCubeMetadataQuery["dataCubeByIri"] & + ComponentsWithHierarchiesQuery["dataCubeByIri"] >; diff --git a/app/scripts/cube.ts b/app/scripts/cube.ts index 16435e145e..e35c85299e 100644 --- a/app/scripts/cube.ts +++ b/app/scripts/cube.ts @@ -9,12 +9,12 @@ import { DataSource } from "@/configurator"; import { GRAPHQL_ENDPOINT } from "../domain/env"; import { + ComponentsDocument, + ComponentsQuery, + ComponentsQueryVariables, DataCubeMetadataDocument, DataCubeMetadataQuery, DataCubeMetadataQueryVariables, - DataCubeMetadataWithComponentValuesDocument, - DataCubeMetadataWithComponentValuesQuery, - DataCubeMetadataWithComponentValuesQueryVariables, DataCubePreviewDocument, DataCubePreviewQuery, DataCubePreviewQueryVariables, @@ -80,10 +80,7 @@ const showCubeComponents = async ({ report, }: Args) => { const res = await client - .query< - DataCubeMetadataWithComponentValuesQuery, - DataCubeMetadataWithComponentValuesQueryVariables - >(DataCubeMetadataWithComponentValuesDocument, { + .query(ComponentsDocument, { iri, sourceType, sourceUrl, @@ -109,16 +106,16 @@ const previewCube = async ({ report, }: Args) => { const { data: info, error } = await client - .query< - DataCubeMetadataWithComponentValuesQuery, - DataCubeMetadataWithComponentValuesQueryVariables - >(DataCubeMetadataWithComponentValuesDocument, { - iri, - sourceType, - sourceUrl, - locale, - latest, - }) + .query( + DataCubeMetadataDocument, + { + iri, + sourceType, + sourceUrl, + locale, + latest, + } + ) .toPromise(); if (error) { diff --git a/app/utils/opendata.ts b/app/utils/opendata.ts index ebc388d040..076324d266 100644 --- a/app/utils/opendata.ts +++ b/app/utils/opendata.ts @@ -1,13 +1,8 @@ -import { - DataCubeMetadataWithComponentValuesQuery, - DataCubeMetadataQuery, -} from "@/graphql/query-hooks"; +import { DataCubeMetadataQuery } from "@/graphql/query-hooks"; const makeOpenDataLink = ( lang: string, - cube: - | DataCubeMetadataWithComponentValuesQuery["dataCubeByIri"] - | DataCubeMetadataQuery["dataCubeByIri"] + cube: DataCubeMetadataQuery["dataCubeByIri"] ) => { const identifier = cube?.identifier; const creatorIri = cube?.creator?.iri;