diff --git a/app/browse/datatable.tsx b/app/browse/datatable.tsx index 42ca10fb5..9b15a5ace 100644 --- a/app/browse/datatable.tsx +++ b/app/browse/datatable.tsx @@ -30,9 +30,9 @@ import { } from "@/domain/data"; import { useDimensionFormatters } from "@/formatters"; import { - useDataCubeMetadataQuery, useDataCubeObservationsQuery, useDataCubesComponentsQuery, + useDataCubesMetadataQuery, } from "@/graphql/query-hooks"; import SvgIcChevronDown from "@/icons/components/IcChevronDown"; import { useLocale } from "@/locales/use-locale"; @@ -257,10 +257,10 @@ export const DataSetTable = ({ sourceUrl: dataSource.url, locale, }; - const [{ data: metadataData }] = useDataCubeMetadataQuery({ + const [{ data: metadataData }] = useDataCubesMetadataQuery({ variables: { ...commonQueryVariables, - iri: dataSetIri, + filters: [{ iri: dataSetIri }], }, }); const [{ data: componentsData }] = useDataCubesComponentsQuery({ @@ -289,12 +289,13 @@ export const DataSetTable = ({ ]); }, [componentsData?.dataCubesComponents]); - return metadataData?.dataCubeByIri && + return metadataData?.dataCubesMetadata && componentsData?.dataCubesComponents && observationsData?.dataCubeByIri ? ( d.title).join(", ")} headers={headers} observations={observationsData.dataCubeByIri.observations.data} linkToMetadataPanel={true} diff --git a/app/charts/area/chart-area.tsx b/app/charts/area/chart-area.tsx index 5e31a4235..9c634c79e 100644 --- a/app/charts/area/chart-area.tsx +++ b/app/charts/area/chart-area.tsx @@ -17,9 +17,9 @@ import { LegendColor } from "@/charts/shared/legend-color"; import { InteractionHorizontal } from "@/charts/shared/overlay-horizontal"; import { AreaConfig, DataSource, QueryFilters } from "@/config-types"; import { - useDataCubeMetadataQuery, useDataCubeObservationsQuery, useDataCubesComponentsQuery, + useDataCubesMetadataQuery, } from "@/graphql/query-hooks"; import { useLocale } from "@/locales/use-locale"; @@ -44,10 +44,10 @@ export const ChartAreasVisualization = ({ sourceUrl: dataSource.url, locale, }; - const [metadataQuery] = useDataCubeMetadataQuery({ + const [metadataQuery] = useDataCubesMetadataQuery({ variables: { ...commonQueryVariables, - iri: dataSetIri, + filters: [{ iri: dataSetIri }], }, }); const [componentsQuery] = useDataCubesComponentsQuery({ diff --git a/app/charts/chart-loading-wrapper.tsx b/app/charts/chart-loading-wrapper.tsx index 34b2ed2ac..40186e70d 100644 --- a/app/charts/chart-loading-wrapper.tsx +++ b/app/charts/chart-loading-wrapper.tsx @@ -15,9 +15,9 @@ import { } from "@/components/hint"; import { ChartConfig } from "@/configurator"; import { - DataCubeMetadataQuery, DataCubeObservationsQuery, DataCubesComponentsQuery, + DataCubesMetadataQuery, } from "@/graphql/query-hooks"; type ElementProps = RE extends React.ElementType ? P : never; @@ -35,7 +35,7 @@ export const ChartLoadingWrapper = < ComponentProps, }: { metadataQuery: Pick< - UseQueryResponse[0], + UseQueryResponse[0], "data" | "fetching" | "error" >; componentsQuery: Pick< @@ -70,7 +70,7 @@ export const ChartLoadingWrapper = < error: observationsError, } = observationsQuery; - const metadata = metadataData?.dataCubeByIri; + const metadata = metadataData?.dataCubesMetadata; const observations = observationsData?.dataCubeByIri?.observations.data; const dimensions = componentsData?.dataCubesComponents.dimensions; const measures = componentsData?.dataCubesComponents.measures; @@ -90,7 +90,8 @@ export const ChartLoadingWrapper = < }, [dimensions, measures]); if (metadata && dimensions && measures && observations) { - const { title } = metadata; + // FIXME: adapt to design + const title = metadata.map((d) => d.title).join(", "); return ( { - return makeOpenDataLink(locale, data?.dataCubeByIri); - }, [locale, data?.dataCubeByIri]); const [ { @@ -108,141 +108,166 @@ export const ChartFootnotes = ({ }, ] = useEmbedOptions(); - if (data?.dataCubeByIri) { - const { dataCubeByIri } = data; + return ( + <> + {data?.dataCubesMetadata + ? data.dataCubesMetadata.map((dataCubeMetadata) => { + const cubeLink = makeOpenDataLink(locale, dataCubeMetadata); - return ( - - {showDatasetTitle !== false ? ( - - - Dataset - - : - {cubeLink ? ( - - {dataCubeByIri.title}{" "} - - - ) : ( - dataCubeByIri.title - )} - - ) : null} + return ( + + {showDatasetTitle !== false ? ( + + + Dataset + + : + {cubeLink ? ( + + {dataCubeMetadata.title}{" "} + + + ) : ( + dataCubeMetadata.title + )} + + ) : null} - {dataCubeByIri.dateModified && showDatePublished !== false ? ( - - ,  - - Latest update - - : - {formatLocale.format("%d.%m.%Y %H:%M")( - new Date(dataCubeByIri.dateModified) - )} - - ) : null} + {dataCubeMetadata.dateModified && + showDatePublished !== false ? ( + + ,  + + + Latest update + + + : + {formatLocale.format("%d.%m.%Y %H:%M")( + new Date(dataCubeMetadata.dateModified) + )} + + ) : null} - {showSource !== false ? ( - - - Source - - : - {dataCubeByIri.publisher && ( - a": { color: "grey.600" } }} - dangerouslySetInnerHTML={{ __html: dataCubeByIri.publisher }} - > - )} - {configKey && shareUrl && visualizeLinkText && ( - <> - {" "} - / {visualizeLinkText} - - )} - - ) : null} + {showSource !== false ? ( + + + Source + + : + {dataCubeMetadata.publisher && ( + a": { color: "grey.600" } }} + dangerouslySetInnerHTML={{ + __html: dataCubeMetadata.publisher, + }} + /> + )} + {configKey && shareUrl && visualizeLinkText && ( + <> + {" "} + /{" "} + + {" "} + {visualizeLinkText} + + + )} + + ) : null} - - {showDownload !== false ? ( - - ) : null} - {showTableSwitch !== false ? ( - <> - {chartConfig.chartType !== "table" && ( - + )} + + ) : null} + {dataCubeMetadata.landingPage && showLandingPage !== false && ( + )} - - )} - - ) : null} - {dataCubeByIri.landingPage && showLandingPage !== false && ( - - )} - {sparqlEditorUrl && showSparqlQuery !== false && ( - - )} - {configKey && shareUrl && !visualizeLinkText && ( - - - Created with visualize.admin.ch - - - )} - - - ); - } else { - return null; - } + {sparqlEditorUrl && showSparqlQuery !== false && ( + + )} + {configKey && shareUrl && !visualizeLinkText && ( + + + Created with visualize.admin.ch + + + )} + + + ); + }) + : null} + + ); }; const LinkButton = (props: PropsWithChildren<{ href: string }>) => { diff --git a/app/components/chart-preview.tsx b/app/components/chart-preview.tsx index c0e6462db..faae469a9 100644 --- a/app/components/chart-preview.tsx +++ b/app/components/chart-preview.tsx @@ -22,8 +22,8 @@ import { useConfiguratorState, } from "@/configurator"; import { - useDataCubeMetadataQuery, useDataCubesComponentsQuery, + useDataCubesMetadataQuery, } from "@/graphql/query-hooks"; import { DataCubePublicationStatus } from "@/graphql/resolver-types"; import { useLocale } from "@/locales/use-locale"; @@ -67,21 +67,17 @@ export const ChartPreviewInner = (props: ChartPreviewProps) => { const chartConfig = getChartConfig(state); const locale = useLocale(); const classes = useStyles(); - const [{ data: metadata }] = useDataCubeMetadataQuery({ - variables: { - iri: dataSetIri, - sourceType: dataSource.type, - sourceUrl: dataSource.url, - locale, - }, + const commonQueryVariables = { + sourceType: dataSource.type, + sourceUrl: dataSource.url, + locale, + filters: [{ iri: dataSetIri }], + }; + const [{ data: metadata }] = useDataCubesMetadataQuery({ + variables: commonQueryVariables, }); const [{ data: components }] = useDataCubesComponentsQuery({ - variables: { - sourceType: dataSource.type, - sourceUrl: dataSource.url, - locale, - filters: [{ iri: dataSetIri }], - }, + variables: commonQueryVariables, }); const { state: isTablePreview, @@ -115,8 +111,10 @@ export const ChartPreviewInner = (props: ChartPreviewProps) => { }} > - {metadata?.dataCubeByIri?.publicationStatus === - DataCubePublicationStatus.Draft && ( + {/* FIXME: adapt to design */} + {metadata?.dataCubesMetadata.some( + (d) => d.publicationStatus === DataCubePublicationStatus.Draft + ) && ( @@ -171,7 +169,8 @@ export const ChartPreviewInner = (props: ChartPreviewProps) => { {chartConfig.meta.title[locale] === "" - ? metadata?.dataCubeByIri?.title + ? // FIXME: adapt to design + metadata?.dataCubesMetadata.map((d) => d.title).join(", ") : chartConfig.meta.title[locale]}{" "} - visualize.admin.ch diff --git a/app/components/chart-published.tsx b/app/components/chart-published.tsx index 2bf81cd43..dd71f27e1 100644 --- a/app/components/chart-published.tsx +++ b/app/components/chart-published.tsx @@ -35,8 +35,8 @@ import { useIsTrustedDataSource, } from "@/domain/datasource"; import { - useDataCubeMetadataQuery, useDataCubesComponentsQuery, + useDataCubesMetadataQuery, } from "@/graphql/query-hooks"; import { DataCubePublicationStatus } from "@/graphql/resolver-types"; import { useLocale } from "@/locales/use-locale"; @@ -137,10 +137,12 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => { sourceUrl: dataSource.url, locale, }; - const [{ data: metadata }] = useDataCubeMetadataQuery({ + const [{ data: metadata }] = useDataCubesMetadataQuery({ variables: { - ...commonQueryVariables, - iri: chartConfig.dataSet, + sourceType: dataSource.type, + sourceUrl: dataSource.url, + locale, + filters: [{ iri: chartConfig.dataSet }], }, }); const componentIris = extractChartConfigsComponentIris(state.chartConfigs); @@ -169,8 +171,9 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => { - {metadata?.dataCubeByIri?.publicationStatus === - DataCubePublicationStatus.Draft && ( + {metadata?.dataCubesMetadata.some( + (d) => d.publicationStatus === DataCubePublicationStatus.Draft + ) && ( @@ -181,7 +184,7 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => { )} - {metadata?.dataCubeByIri?.expires && ( + {metadata?.dataCubesMetadata.some((d) => d.expires) && ( diff --git a/app/components/chart-selection-tabs.tsx b/app/components/chart-selection-tabs.tsx index 0254e3621..84330df3e 100644 --- a/app/components/chart-selection-tabs.tsx +++ b/app/components/chart-selection-tabs.tsx @@ -19,10 +19,7 @@ import { } from "@/configurator"; import { ChartTypeSelector } from "@/configurator/components/chart-type-selector"; import { getIconName } from "@/configurator/components/ui-helpers"; -import { - useDataCubeMetadataQuery, - useDataCubesComponentsQuery, -} from "@/graphql/query-hooks"; +import { useDataCubesComponentsQuery } from "@/graphql/query-hooks"; import { Icon, IconName } from "@/icons"; import { useLocale } from "@/src"; import { fetchChartConfig } from "@/utils/chart-config/api"; @@ -260,21 +257,13 @@ const PublishChartButton = () => { sourceType: state.dataSource.type, sourceUrl: state.dataSource.url, locale, + filters: [{ iri: chartConfig.dataSet }], }; - const [{ data: metadata }] = useDataCubeMetadataQuery({ - variables: { - ...commonQueryVariables, - iri: chartConfig.dataSet, - }, - }); const [{ data: components }] = useDataCubesComponentsQuery({ - variables: { - ...commonQueryVariables, - filters: [{ iri: chartConfig.dataSet }], - }, + variables: commonQueryVariables, }); const goNext = useEvent(() => { - if (metadata?.dataCubeByIri && components?.dataCubesComponents) { + if (components?.dataCubesComponents) { dispatch({ type: "STEP_NEXT", dataCubesComponents: components.dataCubesComponents, @@ -301,7 +290,7 @@ const PublishChartButton = () => {