From d8a4fb7bdc4c79ea30cc7b8d4e538571779efea8 Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Tue, 31 May 2022 14:46:11 +0200 Subject: [PATCH] fix: Show opendata.swiss link only if it is published there --- app/graphql/queries/data-cubes.graphql | 3 +++ app/graphql/query-hooks.ts | 10 +++++++--- app/graphql/resolver-types.ts | 2 ++ app/graphql/resolvers.ts | 1 + app/graphql/schema.graphql | 1 + app/graphql/shared-types.ts | 1 + app/rdf/parse.ts | 1 + app/utils/opendata.ts | 5 ++++- 8 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/graphql/queries/data-cubes.graphql b/app/graphql/queries/data-cubes.graphql index 8a1df199a..5647ec690 100644 --- a/app/graphql/queries/data-cubes.graphql +++ b/app/graphql/queries/data-cubes.graphql @@ -17,6 +17,7 @@ query DataCubes( dataCube { iri title + workExamples creator { iri label @@ -91,6 +92,7 @@ query DataCubeMetadata($iri: String!, $locale: String!, $latest: Boolean) { description publisher version + workExamples contactName contactEmail landingPage @@ -119,6 +121,7 @@ query DataCubeMetadataWithComponentValues( title publisher identifier + workExamples creator { iri } diff --git a/app/graphql/query-hooks.ts b/app/graphql/query-hooks.ts index b784fa119..7bca0fba3 100644 --- a/app/graphql/query-hooks.ts +++ b/app/graphql/query-hooks.ts @@ -30,6 +30,7 @@ export type DataCube = { contactEmail?: Maybe; creator?: Maybe; landingPage?: Maybe; + workExamples?: Maybe>>; publisher?: Maybe; description?: Maybe; datePublished?: Maybe; @@ -334,7 +335,7 @@ export type DataCubesQueryVariables = Exact<{ }>; -export type DataCubesQuery = { __typename: 'Query', dataCubes: Array<{ __typename: 'DataCubeResult', highlightedTitle?: Maybe, highlightedDescription?: Maybe, dataCube: { __typename: 'DataCube', iri: string, title: string, description?: Maybe, publicationStatus: DataCubePublicationStatus, datePublished?: Maybe, creator?: Maybe<{ __typename: 'DataCubeOrganization', iri: string, label?: Maybe }>, themes: Array<{ __typename: 'DataCubeTheme', iri: string, label?: Maybe }> } }> }; +export type DataCubesQuery = { __typename: 'Query', dataCubes: Array<{ __typename: 'DataCubeResult', highlightedTitle?: Maybe, highlightedDescription?: Maybe, dataCube: { __typename: 'DataCube', iri: string, title: string, workExamples?: Maybe>>, description?: Maybe, publicationStatus: DataCubePublicationStatus, datePublished?: Maybe, creator?: Maybe<{ __typename: 'DataCubeOrganization', iri: string, label?: Maybe }>, themes: Array<{ __typename: 'DataCubeTheme', iri: string, label?: Maybe }> } }> }; type DimensionMetaData_GeoCoordinatesDimension_Fragment = { __typename: 'GeoCoordinatesDimension', iri: string, label: string, isNumerical: boolean, isKeyDimension: boolean, values: Array, unit?: Maybe, related?: Maybe> }; @@ -398,7 +399,7 @@ 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, contactName?: Maybe, contactEmail?: Maybe, landingPage?: Maybe, expires?: Maybe, datePublished?: Maybe, publicationStatus: DataCubePublicationStatus, themes: Array<{ __typename: 'DataCubeTheme', iri: string, label?: Maybe }>, creator?: Maybe<{ __typename: 'DataCubeOrganization', iri: string, label?: Maybe }> }> }; +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, 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']; @@ -408,7 +409,7 @@ export type DataCubeMetadataWithComponentValuesQueryVariables = Exact<{ }>; -export type DataCubeMetadataWithComponentValuesQuery = { __typename: 'Query', dataCubeByIri?: Maybe<{ __typename: 'DataCube', iri: string, title: string, publisher?: Maybe, identifier?: Maybe, creator?: Maybe<{ __typename: 'DataCubeOrganization', iri: string }>, dimensions: Array<( +export type DataCubeMetadataWithComponentValuesQuery = { __typename: 'Query', dataCubeByIri?: Maybe<{ __typename: 'DataCube', iri: string, title: string, publisher?: Maybe, identifier?: Maybe, workExamples?: Maybe>>, creator?: Maybe<{ __typename: 'DataCubeOrganization', iri: string }>, dimensions: Array<( { __typename: 'GeoCoordinatesDimension' } & DimensionMetaData_GeoCoordinatesDimension_Fragment ) | ( @@ -599,6 +600,7 @@ export const DataCubesDocument = gql` dataCube { iri title + workExamples creator { iri label @@ -661,6 +663,7 @@ export const DataCubeMetadataDocument = gql` description publisher version + workExamples contactName contactEmail landingPage @@ -689,6 +692,7 @@ export const DataCubeMetadataWithComponentValuesDocument = gql` title publisher identifier + workExamples creator { iri } diff --git a/app/graphql/resolver-types.ts b/app/graphql/resolver-types.ts index da20ac475..b4ae4fc0e 100644 --- a/app/graphql/resolver-types.ts +++ b/app/graphql/resolver-types.ts @@ -35,6 +35,7 @@ export type DataCube = { contactEmail?: Maybe; creator?: Maybe; landingPage?: Maybe; + workExamples?: Maybe>>; publisher?: Maybe; description?: Maybe; datePublished?: Maybe; @@ -470,6 +471,7 @@ export type DataCubeResolvers, ParentType, ContextType>; creator?: Resolver, ParentType, ContextType>; landingPage?: Resolver, ParentType, ContextType>; + workExamples?: Resolver>>, ParentType, ContextType>; publisher?: Resolver, ParentType, ContextType>; description?: Resolver, ParentType, ContextType>; datePublished?: Resolver, ParentType, ContextType>; diff --git a/app/graphql/resolvers.ts b/app/graphql/resolvers.ts index 282870c96..8501e45ef 100644 --- a/app/graphql/resolvers.ts +++ b/app/graphql/resolvers.ts @@ -227,6 +227,7 @@ const DataCube: DataCubeResolvers = { title: ({ data: { title } }) => title, version: ({ data: { version } }) => version ?? null, identifier: ({ data: { identifier } }) => identifier ?? null, + workExamples: ({ data: { workExamples } }) => workExamples ?? null, publisher: ({ data: { publisher } }) => publisher ?? null, contactName: ({ data: { contactPoint } }) => contactPoint?.name ?? null, contactEmail: ({ data: { contactPoint } }) => contactPoint?.email ?? null, diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index a75ad46ac..0612d6f40 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -30,6 +30,7 @@ type DataCube { contactEmail: String creator: DataCubeOrganization landingPage: String + workExamples: [String] publisher: String description: String datePublished: String diff --git a/app/graphql/shared-types.ts b/app/graphql/shared-types.ts index 5fe753701..6639f3f8c 100644 --- a/app/graphql/shared-types.ts +++ b/app/graphql/shared-types.ts @@ -35,6 +35,7 @@ export type ResolvedDataCube = { landingPage?: string; expires?: string; keywords?: string[]; + workExamples?: string[]; }; }; diff --git a/app/rdf/parse.ts b/app/rdf/parse.ts index 355fe2c66..ba3f3c41d 100644 --- a/app/rdf/parse.ts +++ b/app/rdf/parse.ts @@ -78,6 +78,7 @@ export const parseCube = ({ landingPage: cube.out(ns.dcat.landingPage)?.value, expires: cube.out(ns.schema.expires)?.value, keywords: cube.out(ns.dcat.keyword)?.values, + workExamples: cube.out(ns.schema.workExample)?.values, }, }; }; diff --git a/app/utils/opendata.ts b/app/utils/opendata.ts index 112c386c5..ebc388d04 100644 --- a/app/utils/opendata.ts +++ b/app/utils/opendata.ts @@ -11,7 +11,10 @@ const makeOpenDataLink = ( ) => { const identifier = cube?.identifier; const creatorIri = cube?.creator?.iri; - if (!identifier || !creatorIri) { + const isPublished = cube?.workExamples?.includes( + "https://ld.admin.ch/application/opendataswiss" + ); + if (!identifier || !creatorIri || !isPublished) { return; } return `https://opendata.swiss/${lang}/perma/${encodeURIComponent(