From bc0d21df5d50a25ef78a060f04fb2f78a475bbed Mon Sep 17 00:00:00 2001 From: thomasgross Date: Mon, 18 Nov 2024 15:05:31 +0100 Subject: [PATCH 1/8] initial setup --- app/work/[id]/page.tsx | 13 +++ .../shared/publizonReader/PublizonReader.tsx | 87 +++++++++++++++++++ components/shared/publizonReader/helper.ts | 43 +++++++++ 3 files changed, 143 insertions(+) create mode 100644 app/work/[id]/page.tsx create mode 100644 components/shared/publizonReader/PublizonReader.tsx create mode 100644 components/shared/publizonReader/helper.ts diff --git a/app/work/[id]/page.tsx b/app/work/[id]/page.tsx new file mode 100644 index 00000000..e949feb4 --- /dev/null +++ b/app/work/[id]/page.tsx @@ -0,0 +1,13 @@ +import React from "react" + +function Page({ searchParams, queryParams }) { + return ( +
+
{JSON.stringify(queryParams, null, 2)}
+
{JSON.stringify(searchParams, null, 2)}
+ Page +
+ ) +} + +export default Page diff --git a/components/shared/publizonReader/PublizonReader.tsx b/components/shared/publizonReader/PublizonReader.tsx new file mode 100644 index 00000000..05c07d9a --- /dev/null +++ b/components/shared/publizonReader/PublizonReader.tsx @@ -0,0 +1,87 @@ +import React, { CSSProperties, useEffect } from "react" + +import { appendAsset, readerAssets } from "./helper" + +// type ReaderType = { identifier?: string; orderId?: string }; + +// Define mutually exclusive types for identifier and orderId +type ReaderType = + | { + identifier: string + orderId?: never + } + | { + identifier?: never + orderId: string + } + +const Reader = ({ identifier, orderId }: ReaderType) => { + useEffect(() => { + readerAssets.forEach(appendAsset) + }, [identifier, orderId]) + + const readerStyles: CSSProperties = { + position: "absolute", + top: "0", // Padding from the top + left: "0", // Padding from the left + right: "0", // Padding from the right + bottom: "0", // Padding from the bottom + padding: "20px", // Padding for the reader + width: "100%", + maxWidth: "unset", + zIndex: 1000, + // border: "1px dotted black", // Should be removed in production + margin: "0", + } + + const handleBack = () => { + window.history.back() + } + + const handleKeyDown = (event: React.KeyboardEvent) => { + if (event.key === "Escape") { + handleBack() + } + } + + if (orderId) { + return ( +
+

orderId: {orderId}

+
+
+ ) + } + + if (identifier) { + return ( +
+ ) + } + + return null +} + +export default Reader diff --git a/components/shared/publizonReader/helper.ts b/components/shared/publizonReader/helper.ts new file mode 100644 index 00000000..21d6d1f0 --- /dev/null +++ b/components/shared/publizonReader/helper.ts @@ -0,0 +1,43 @@ +type AssetType = { + src: string + type: "script" | "link" +} + +export const readerAssets: AssetType[] = [ + { + src: "https://reader.pubhub.dk/2.2.0/js/chunk-vendors.js", + type: "script", + }, + { + src: "https://reader.pubhub.dk/2.2.0/js/app.js", + type: "script", + }, + { + src: "https://reader.pubhub.dk/2.2.0/css/chunk-vendors.css", + type: "link", + }, + { + src: "https://reader.pubhub.dk/2.2.0/css/app.css", + type: "link", + }, +] + +export const appendAsset = ({ src, type }: AssetType) => { + if (type === "script") { + const scriptElement = document.createElement("script") + scriptElement.src = src + scriptElement.defer = true + scriptElement.async = false + scriptElement.type = "module" + document.head.appendChild(scriptElement) + } + + if (type === "link") { + const linkElement = document.createElement("link") + linkElement.href = src + linkElement.rel = "stylesheet" + document.head.appendChild(linkElement) + } +} + +export default {} From 5385cb37fa6c90b1b044df7752257785df8326be Mon Sep 17 00:00:00 2001 From: thomasgross Date: Tue, 19 Nov 2024 10:25:56 +0100 Subject: [PATCH 2/8] feat: add GraphQL queries and fragments for material and work + update TypeScript configuration --- app/work/[id]/page.tsx | 8 +- .../fragments/manifestation.fbi.graphql | 152 +++++++++ lib/graphql/fragments/work.fbi.graphql | 87 +++++ lib/graphql/generated/fbi/graphql.tsx | 314 ++++++++++++++++++ lib/graphql/queries/material.fbi.graphql | 5 + package.json | 2 +- tsconfig.json | 4 +- 7 files changed, 566 insertions(+), 6 deletions(-) create mode 100644 lib/graphql/queries/material.fbi.graphql diff --git a/app/work/[id]/page.tsx b/app/work/[id]/page.tsx index e949feb4..a02a2235 100644 --- a/app/work/[id]/page.tsx +++ b/app/work/[id]/page.tsx @@ -1,10 +1,12 @@ import React from "react" -function Page({ searchParams, queryParams }) { +function Page({ params: { id } }: { params: { id: string } }) { + + + return (
-
{JSON.stringify(queryParams, null, 2)}
-
{JSON.stringify(searchParams, null, 2)}
+
{JSON.stringify(id, null, 2)}
Page
) diff --git a/lib/graphql/fragments/manifestation.fbi.graphql b/lib/graphql/fragments/manifestation.fbi.graphql index 4c2374af..a62f2abb 100644 --- a/lib/graphql/fragments/manifestation.fbi.graphql +++ b/lib/graphql/fragments/manifestation.fbi.graphql @@ -18,3 +18,155 @@ fragment ManifestationIdentifiers on Manifestation { value } } + +fragment Manifestations on Manifestations { + all { + ...ManifestationsFields + } + latest { + ...ManifestationsFields + } + bestRepresentation { + ...ManifestationsFields + } +} + +fragment ManifestationsAccess on Manifestations { + all { + pid + identifiers { + type + value + } + access { + __typename + ... on AccessUrl { + origin + url + loginRequired + } + ... on InfomediaService { + id + } + ... on InterLibraryLoan { + loanIsPossible + } + ... on Ereol { + origin + url + canAlwaysBeLoaned + } + ... on DigitalArticleService { + issn + } + } + } +} + +fragment ManifestationsFields on Manifestation { + pid + genreAndForm + source + # ...WithLanguages + titles { + main + original + } + fictionNonfiction { + display + code + } + materialTypes { + materialTypeSpecific { + display + } + } + creators { + display + nameSort + __typename + } + publisher + identifiers { + value + } + contributors { + display + roles { + function { + singular + } + } + } + edition { + summary + publicationYear { + display + } + } + dateFirstEdition { + display + year + } + audience { + generalAudience + ages { + display + } + } + notes { + display + } + languages { + notes + } + physicalDescription { + summaryFull + numberOfPages + # playingTime + } + hostPublication { + summary + } + manifestationParts { + parts { + title + } + } + accessTypes { + code + } + access { + __typename + ... on AccessUrl { + origin + url + loginRequired + } + ... on InfomediaService { + id + } + ... on InterLibraryLoan { + loanIsPossible + } + ... on Ereol { + origin + url + canAlwaysBeLoaned + } + ... on DigitalArticleService { + issn + } + } + shelfmark { + postfix + shelfmark + } + workYear { + year + } + catalogueCodes { + nationalBibliography + otherCatalogues + } +} diff --git a/lib/graphql/fragments/work.fbi.graphql b/lib/graphql/fragments/work.fbi.graphql index d95d6d8a..507ae7b0 100644 --- a/lib/graphql/fragments/work.fbi.graphql +++ b/lib/graphql/fragments/work.fbi.graphql @@ -1,3 +1,26 @@ +fragment SeriesSimple on Series { + title + isPopular + members { + numberInSeries + work { + workId + titles { + main + } + } + } + readThisFirst + readThisWhenever +} + +fragment WorkAccess on Work { + workId + manifestations { + ...ManifestationsAccess + } +} + fragment WorkTeaser on Work { workId titles { @@ -26,3 +49,67 @@ fragment WorkTeaser on Work { } } } + +fragment Work on Work { + workId + titles { + full + original + } + abstract + creators { + display + __typename + } + series { + ...SeriesSimple + } + workYear { + year + } + genreAndForm + manifestations { + ...Manifestations + } + materialTypes { + materialTypeSpecific { + display + } + } + creators { + nameSort + } + mainLanguages { + display + isoCode + } + subjects { + all { + display + } + dbcVerified { + display + } + } + fictionNonfiction { + display + code + } + dk5MainEntry { + display + } + relations { + hasReview { + pid + } + hasAdaptation { + ownerWork { + workId + workTypes + titles { + main + } + } + } + } +} diff --git a/lib/graphql/generated/fbi/graphql.tsx b/lib/graphql/generated/fbi/graphql.tsx index 3b67c0a5..87666bde 100644 --- a/lib/graphql/generated/fbi/graphql.tsx +++ b/lib/graphql/generated/fbi/graphql.tsx @@ -190,6 +190,8 @@ export type ComplexSearchFiltersInput = { branchId?: InputMaybe>; /** Overall location in library (eg. Voksne). */ department?: InputMaybe>; + /** Date of first accession */ + firstAccessionDate?: InputMaybe; /** Id of publishing issue. */ issueId?: InputMaybe>; /** Local id of the item. */ @@ -616,6 +618,8 @@ export type InfomediaService = { export type InterLibraryLoan = { __typename?: 'InterLibraryLoan'; + /** Is newly added - nice to know if there are no localizations */ + accessNew: Scalars['Boolean']['output']; /** Is true when manifestation can be borrowed via ill */ loanIsPossible: Scalars['Boolean']['output']; }; @@ -1927,8 +1931,27 @@ export type ManifestationCoverFragment = { __typename?: 'Manifestation', pid: st export type ManifestationIdentifiersFragment = { __typename?: 'Manifestation', identifiers: Array<{ __typename?: 'Identifier', type: IdentifierTypeEnum, value: string }> }; +export type ManifestationsFragment = { __typename?: 'Manifestations', all: Array<{ __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }>, latest: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }, bestRepresentation: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } } }; + +export type ManifestationsAccessFragment = { __typename?: 'Manifestations', all: Array<{ __typename?: 'Manifestation', pid: string, identifiers: Array<{ __typename?: 'Identifier', type: IdentifierTypeEnum, value: string }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }> }> }; + +export type ManifestationsFieldsFragment = { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }; + +export type SeriesSimpleFragment = { __typename?: 'Series', title: string, isPopular?: boolean | null, readThisFirst?: boolean | null, readThisWhenever?: boolean | null, members: Array<{ __typename?: 'SerieWork', numberInSeries?: string | null, work: { __typename?: 'Work', workId: string, titles: { __typename?: 'WorkTitles', main: Array } } }> }; + +export type WorkAccessFragment = { __typename?: 'Work', workId: string, manifestations: { __typename?: 'Manifestations', all: Array<{ __typename?: 'Manifestation', pid: string, identifiers: Array<{ __typename?: 'Identifier', type: IdentifierTypeEnum, value: string }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }> }> } }; + export type WorkTeaserFragment = { __typename?: 'Work', workId: string, titles: { __typename?: 'WorkTitles', full: Array, original?: Array | null }, creators: Array<{ __typename: 'Corporation', display: string } | { __typename: 'Person', display: string }>, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeGeneral: { __typename?: 'GeneralMaterialType', display: string, code: GeneralMaterialTypeCodeEnum } }>, manifestations: { __typename?: 'Manifestations', all: Array<{ __typename?: 'Manifestation', pid: string, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeGeneral: { __typename?: 'GeneralMaterialType', code: GeneralMaterialTypeCodeEnum } }>, identifiers: Array<{ __typename?: 'Identifier', type: IdentifierTypeEnum, value: string }> }>, bestRepresentation: { __typename?: 'Manifestation', pid: string, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeGeneral: { __typename?: 'GeneralMaterialType', code: GeneralMaterialTypeCodeEnum } }>, identifiers: Array<{ __typename?: 'Identifier', type: IdentifierTypeEnum, value: string }> } } }; +export type WorkFragment = { __typename?: 'Work', workId: string, abstract?: Array | null, genreAndForm: Array, titles: { __typename?: 'WorkTitles', full: Array, original?: Array | null }, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, series: Array<{ __typename?: 'Series', title: string, isPopular?: boolean | null, readThisFirst?: boolean | null, readThisWhenever?: boolean | null, members: Array<{ __typename?: 'SerieWork', numberInSeries?: string | null, work: { __typename?: 'Work', workId: string, titles: { __typename?: 'WorkTitles', main: Array } } }> }>, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, manifestations: { __typename?: 'Manifestations', all: Array<{ __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }>, latest: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }, bestRepresentation: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } } }, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, mainLanguages: Array<{ __typename?: 'Language', display: string, isoCode: string }>, subjects: { __typename?: 'SubjectContainer', all: Array<{ __typename?: 'Corporation', display: string } | { __typename?: 'Mood', display: string } | { __typename?: 'NarrativeTechnique', display: string } | { __typename?: 'Person', display: string } | { __typename?: 'Setting', display: string } | { __typename?: 'SubjectText', display: string } | { __typename?: 'SubjectWithRating', display: string } | { __typename?: 'TimePeriod', display: string }>, dbcVerified: Array<{ __typename?: 'Corporation', display: string } | { __typename?: 'Mood', display: string } | { __typename?: 'NarrativeTechnique', display: string } | { __typename?: 'Person', display: string } | { __typename?: 'Setting', display: string } | { __typename?: 'SubjectText', display: string } | { __typename?: 'SubjectWithRating', display: string } | { __typename?: 'TimePeriod', display: string }> }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, dk5MainEntry?: { __typename?: 'DK5MainEntry', display: string } | null, relations: { __typename?: 'Relations', hasReview: Array<{ __typename?: 'Manifestation', pid: string }>, hasAdaptation: Array<{ __typename?: 'Manifestation', ownerWork: { __typename?: 'Work', workId: string, workTypes: Array, titles: { __typename?: 'WorkTitles', main: Array } } }> } }; + +export type GetMaterialQueryVariables = Exact<{ + wid: Scalars['String']['input']; +}>; + + +export type GetMaterialQuery = { __typename?: 'Query', work?: { __typename?: 'Work', workId: string, abstract?: Array | null, genreAndForm: Array, titles: { __typename?: 'WorkTitles', full: Array, original?: Array | null }, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, series: Array<{ __typename?: 'Series', title: string, isPopular?: boolean | null, readThisFirst?: boolean | null, readThisWhenever?: boolean | null, members: Array<{ __typename?: 'SerieWork', numberInSeries?: string | null, work: { __typename?: 'Work', workId: string, titles: { __typename?: 'WorkTitles', main: Array } } }> }>, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, manifestations: { __typename?: 'Manifestations', all: Array<{ __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }>, latest: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }, bestRepresentation: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } } }, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, mainLanguages: Array<{ __typename?: 'Language', display: string, isoCode: string }>, subjects: { __typename?: 'SubjectContainer', all: Array<{ __typename?: 'Corporation', display: string } | { __typename?: 'Mood', display: string } | { __typename?: 'NarrativeTechnique', display: string } | { __typename?: 'Person', display: string } | { __typename?: 'Setting', display: string } | { __typename?: 'SubjectText', display: string } | { __typename?: 'SubjectWithRating', display: string } | { __typename?: 'TimePeriod', display: string }>, dbcVerified: Array<{ __typename?: 'Corporation', display: string } | { __typename?: 'Mood', display: string } | { __typename?: 'NarrativeTechnique', display: string } | { __typename?: 'Person', display: string } | { __typename?: 'Setting', display: string } | { __typename?: 'SubjectText', display: string } | { __typename?: 'SubjectWithRating', display: string } | { __typename?: 'TimePeriod', display: string }> }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, dk5MainEntry?: { __typename?: 'DK5MainEntry', display: string } | null, relations: { __typename?: 'Relations', hasReview: Array<{ __typename?: 'Manifestation', pid: string }>, hasAdaptation: Array<{ __typename?: 'Manifestation', ownerWork: { __typename?: 'Work', workId: string, workTypes: Array, titles: { __typename?: 'WorkTitles', main: Array } } }> } } | null }; + export type SearchWithPaginationQueryVariables = Exact<{ q: SearchQueryInput; offset: Scalars['Int']['input']; @@ -1960,6 +1983,47 @@ export const SearchFacetFragmentDoc = ` } } `; +export const ManifestationsAccessFragmentDoc = ` + fragment ManifestationsAccess on Manifestations { + all { + pid + identifiers { + type + value + } + access { + __typename + ... on AccessUrl { + origin + url + loginRequired + } + ... on InfomediaService { + id + } + ... on InterLibraryLoan { + loanIsPossible + } + ... on Ereol { + origin + url + canAlwaysBeLoaned + } + ... on DigitalArticleService { + issn + } + } + } +} + `; +export const WorkAccessFragmentDoc = ` + fragment WorkAccess on Work { + workId + manifestations { + ...ManifestationsAccess + } +} + ${ManifestationsAccessFragmentDoc}`; export const ManifestationCoverFragmentDoc = ` fragment ManifestationCover on Manifestation { pid @@ -2015,6 +2079,256 @@ export const WorkTeaserFragmentDoc = ` } } ${ManifestationTeaserFragmentDoc}`; +export const SeriesSimpleFragmentDoc = ` + fragment SeriesSimple on Series { + title + isPopular + members { + numberInSeries + work { + workId + titles { + main + } + } + } + readThisFirst + readThisWhenever +} + `; +export const ManifestationsFieldsFragmentDoc = ` + fragment ManifestationsFields on Manifestation { + pid + genreAndForm + source + titles { + main + original + } + fictionNonfiction { + display + code + } + materialTypes { + materialTypeSpecific { + display + } + } + creators { + display + nameSort + __typename + } + publisher + identifiers { + value + } + contributors { + display + roles { + function { + singular + } + } + } + edition { + summary + publicationYear { + display + } + } + dateFirstEdition { + display + year + } + audience { + generalAudience + ages { + display + } + } + notes { + display + } + languages { + notes + } + physicalDescription { + summaryFull + numberOfPages + } + hostPublication { + summary + } + manifestationParts { + parts { + title + } + } + accessTypes { + code + } + access { + __typename + ... on AccessUrl { + origin + url + loginRequired + } + ... on InfomediaService { + id + } + ... on InterLibraryLoan { + loanIsPossible + } + ... on Ereol { + origin + url + canAlwaysBeLoaned + } + ... on DigitalArticleService { + issn + } + } + shelfmark { + postfix + shelfmark + } + workYear { + year + } + catalogueCodes { + nationalBibliography + otherCatalogues + } +} + `; +export const ManifestationsFragmentDoc = ` + fragment Manifestations on Manifestations { + all { + ...ManifestationsFields + } + latest { + ...ManifestationsFields + } + bestRepresentation { + ...ManifestationsFields + } +} + ${ManifestationsFieldsFragmentDoc}`; +export const WorkFragmentDoc = ` + fragment Work on Work { + workId + titles { + full + original + } + abstract + creators { + display + __typename + } + series { + ...SeriesSimple + } + workYear { + year + } + genreAndForm + manifestations { + ...Manifestations + } + materialTypes { + materialTypeSpecific { + display + } + } + creators { + nameSort + } + mainLanguages { + display + isoCode + } + subjects { + all { + display + } + dbcVerified { + display + } + } + fictionNonfiction { + display + code + } + dk5MainEntry { + display + } + relations { + hasReview { + pid + } + hasAdaptation { + ownerWork { + workId + workTypes + titles { + main + } + } + } + } +} + ${SeriesSimpleFragmentDoc} +${ManifestationsFragmentDoc}`; +export const GetMaterialDocument = ` + query getMaterial($wid: String!) { + work(id: $wid) { + ...Work + } +} + ${WorkFragmentDoc}`; + +export const useGetMaterialQuery = < + TData = GetMaterialQuery, + TError = unknown + >( + variables: GetMaterialQueryVariables, + options?: Omit, 'queryKey'> & { queryKey?: UseQueryOptions['queryKey'] } + ) => { + + return useQuery( + { + queryKey: ['getMaterial', variables], + queryFn: fetchData(GetMaterialDocument, variables), + ...options + } + )}; + +useGetMaterialQuery.getKey = (variables: GetMaterialQueryVariables) => ['getMaterial', variables]; + +export const useSuspenseGetMaterialQuery = < + TData = GetMaterialQuery, + TError = unknown + >( + variables: GetMaterialQueryVariables, + options?: Omit, 'queryKey'> & { queryKey?: UseSuspenseQueryOptions['queryKey'] } + ) => { + + return useSuspenseQuery( + { + queryKey: ['getMaterialSuspense', variables], + queryFn: fetchData(GetMaterialDocument, variables), + ...options + } + )}; + +useSuspenseGetMaterialQuery.getKey = (variables: GetMaterialQueryVariables) => ['getMaterialSuspense', variables]; + + +useGetMaterialQuery.fetcher = (variables: GetMaterialQueryVariables, options?: RequestInit['headers']) => fetchData(GetMaterialDocument, variables, options); + export const SearchWithPaginationDocument = ` query searchWithPagination($q: SearchQueryInput!, $offset: Int!, $limit: PaginationLimitScalar!, $filters: SearchFiltersInput) { search(q: $q, filters: $filters) { diff --git a/lib/graphql/queries/material.fbi.graphql b/lib/graphql/queries/material.fbi.graphql new file mode 100644 index 00000000..b9c4fdf3 --- /dev/null +++ b/lib/graphql/queries/material.fbi.graphql @@ -0,0 +1,5 @@ +query getMaterial($wid: String!) { + work(id: $wid) { + ...Work + } +} diff --git a/package.json b/package.json index 04485268..cb790975 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "format:check": "prettier --check .", "format:write": "prettier --write .", "test:unit": "vitest", - "codegen:graphql": "graphql-codegen --config codegen.ts", + "codegen:graphql": "graphql-codegen --require tsconfig-paths/register --config codegen.ts", "codegen:all-rest-services": "orval", "codegen:covers": "rm -rf src/lib/rest/cover-service-api/generated/model/*.* && orval --project coverService", "codegen:publizon": "rm -rf lib/rest/publizon-api/generated/model/*.* && orval --project publizonAdapter", diff --git a/tsconfig.json b/tsconfig.json index 3ce184b6..15417281 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,6 +23,7 @@ "schema": "graphql/generated/dpl-cms/graphql.schema.json" } ], + "baseUrl": ".", "paths": { "@/*": ["./*"] } @@ -32,7 +33,6 @@ "node_modules", "lib/rest/cover-service-api/model", "lib/rest/cover-service-api/cover-service.ts", - "lib/graphql/generated/fbi/*.tsx", - "__tests__" + "lib/graphql/generated/fbi/*.tsx" ] } From 86bd77c79f841b10180abbf50bcc9e484d3b23f9 Mon Sep 17 00:00:00 2001 From: thomasgross Date: Wed, 20 Nov 2024 00:59:13 +0100 Subject: [PATCH 3/8] feat: refactor GraphQL queries and fragments names for work, update routing parameters, and implement WorkPageLayout component --- app/work/[id]/page.tsx | 24 +++++++++++++++---- .../pages/workPageLayout/WorkPageLayout.tsx | 21 ++++++++++++++++ components/shared/workCard/WorkCard.tsx | 2 +- lib/graphql/fragments/work.fbi.graphql | 2 +- lib/graphql/generated/fbi/graphql.tsx | 10 ++++---- lib/graphql/queries/material.fbi.graphql | 2 +- lib/helpers/helper.routes.ts | 10 +++++--- 7 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 components/pages/workPageLayout/WorkPageLayout.tsx diff --git a/app/work/[id]/page.tsx b/app/work/[id]/page.tsx index a02a2235..c20704ca 100644 --- a/app/work/[id]/page.tsx +++ b/app/work/[id]/page.tsx @@ -1,14 +1,28 @@ +import { HydrationBoundary, dehydrate } from "@tanstack/react-query" import React from "react" +import WorkPageLayout from "@/components/pages/workPageLayout/WorkPageLayout" +import getQueryClient from "@/lib/getQueryClient" +import { useGetMaterialQuery } from "@/lib/graphql/generated/fbi/graphql" + function Page({ params: { id } }: { params: { id: string } }) { + const queryClient = getQueryClient() + + const decodedWid = decodeURIComponent(id) - + queryClient.prefetchQuery({ + queryKey: useGetMaterialQuery.getKey({ wid: decodedWid }), + queryFn: useGetMaterialQuery.fetcher({ wid: decodedWid }), + }) return ( -
-
{JSON.stringify(id, null, 2)}
- Page -
+ +
+ +
{JSON.stringify(id, null, 2)}
+ Page +
+
) } diff --git a/components/pages/workPageLayout/WorkPageLayout.tsx b/components/pages/workPageLayout/WorkPageLayout.tsx new file mode 100644 index 00000000..6867f43b --- /dev/null +++ b/components/pages/workPageLayout/WorkPageLayout.tsx @@ -0,0 +1,21 @@ +"use client" + +import { useQuery } from "@tanstack/react-query" +import React from "react" + +import { useGetMaterialQuery } from "@/lib/graphql/generated/fbi/graphql" + +function WorkPageLayout({ wid }: { wid: string }) { + const data = useQuery({ + queryKey: useGetMaterialQuery.getKey({ wid }), + queryFn: useGetMaterialQuery.fetcher({ wid }), + }) + + return ( +
+
{JSON.stringify({ data }, null, 2)}
+
+ ) +} + +export default WorkPageLayout diff --git a/components/shared/workCard/WorkCard.tsx b/components/shared/workCard/WorkCard.tsx index 61d2bbd4..99ff1b03 100644 --- a/components/shared/workCard/WorkCard.tsx +++ b/components/shared/workCard/WorkCard.tsx @@ -58,7 +58,7 @@ const WorkCard = ({ work }: WorkCardProps) => { return ( + href={resolveUrl({ type: "work", routeParams: { wid: work.workId } })}>
, original?: Array | null }, creators: Array<{ __typename: 'Corporation', display: string } | { __typename: 'Person', display: string }>, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeGeneral: { __typename?: 'GeneralMaterialType', display: string, code: GeneralMaterialTypeCodeEnum } }>, manifestations: { __typename?: 'Manifestations', all: Array<{ __typename?: 'Manifestation', pid: string, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeGeneral: { __typename?: 'GeneralMaterialType', code: GeneralMaterialTypeCodeEnum } }>, identifiers: Array<{ __typename?: 'Identifier', type: IdentifierTypeEnum, value: string }> }>, bestRepresentation: { __typename?: 'Manifestation', pid: string, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeGeneral: { __typename?: 'GeneralMaterialType', code: GeneralMaterialTypeCodeEnum } }>, identifiers: Array<{ __typename?: 'Identifier', type: IdentifierTypeEnum, value: string }> } } }; -export type WorkFragment = { __typename?: 'Work', workId: string, abstract?: Array | null, genreAndForm: Array, titles: { __typename?: 'WorkTitles', full: Array, original?: Array | null }, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, series: Array<{ __typename?: 'Series', title: string, isPopular?: boolean | null, readThisFirst?: boolean | null, readThisWhenever?: boolean | null, members: Array<{ __typename?: 'SerieWork', numberInSeries?: string | null, work: { __typename?: 'Work', workId: string, titles: { __typename?: 'WorkTitles', main: Array } } }> }>, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, manifestations: { __typename?: 'Manifestations', all: Array<{ __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }>, latest: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }, bestRepresentation: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } } }, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, mainLanguages: Array<{ __typename?: 'Language', display: string, isoCode: string }>, subjects: { __typename?: 'SubjectContainer', all: Array<{ __typename?: 'Corporation', display: string } | { __typename?: 'Mood', display: string } | { __typename?: 'NarrativeTechnique', display: string } | { __typename?: 'Person', display: string } | { __typename?: 'Setting', display: string } | { __typename?: 'SubjectText', display: string } | { __typename?: 'SubjectWithRating', display: string } | { __typename?: 'TimePeriod', display: string }>, dbcVerified: Array<{ __typename?: 'Corporation', display: string } | { __typename?: 'Mood', display: string } | { __typename?: 'NarrativeTechnique', display: string } | { __typename?: 'Person', display: string } | { __typename?: 'Setting', display: string } | { __typename?: 'SubjectText', display: string } | { __typename?: 'SubjectWithRating', display: string } | { __typename?: 'TimePeriod', display: string }> }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, dk5MainEntry?: { __typename?: 'DK5MainEntry', display: string } | null, relations: { __typename?: 'Relations', hasReview: Array<{ __typename?: 'Manifestation', pid: string }>, hasAdaptation: Array<{ __typename?: 'Manifestation', ownerWork: { __typename?: 'Work', workId: string, workTypes: Array, titles: { __typename?: 'WorkTitles', main: Array } } }> } }; +export type WorkFragmentFragment = { __typename?: 'Work', workId: string, abstract?: Array | null, genreAndForm: Array, titles: { __typename?: 'WorkTitles', full: Array, original?: Array | null }, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, series: Array<{ __typename?: 'Series', title: string, isPopular?: boolean | null, readThisFirst?: boolean | null, readThisWhenever?: boolean | null, members: Array<{ __typename?: 'SerieWork', numberInSeries?: string | null, work: { __typename?: 'Work', workId: string, titles: { __typename?: 'WorkTitles', main: Array } } }> }>, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, manifestations: { __typename?: 'Manifestations', all: Array<{ __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }>, latest: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } }, bestRepresentation: { __typename?: 'Manifestation', pid: string, genreAndForm: Array, source: Array, publisher: Array, titles: { __typename?: 'ManifestationTitles', main: Array, original?: Array | null }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, creators: Array<{ __typename: 'Corporation', display: string, nameSort: string } | { __typename: 'Person', display: string, nameSort: string }>, identifiers: Array<{ __typename?: 'Identifier', value: string }>, contributors: Array<{ __typename?: 'Corporation', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> } | { __typename?: 'Person', display: string, roles: Array<{ __typename?: 'Role', function: { __typename?: 'Translation', singular: string } }> }>, edition?: { __typename?: 'Edition', summary: string, publicationYear?: { __typename?: 'PublicationYear', display: string } | null } | null, dateFirstEdition?: { __typename?: 'PublicationYear', display: string, year?: number | null } | null, audience?: { __typename?: 'Audience', generalAudience: Array, ages: Array<{ __typename?: 'Range', display: string }> } | null, notes: Array<{ __typename?: 'Note', display: Array }>, languages?: { __typename?: 'Languages', notes?: Array | null } | null, physicalDescription?: { __typename?: 'PhysicalUnitDescription', summaryFull?: string | null, numberOfPages?: number | null } | null, hostPublication?: { __typename?: 'HostPublication', summary: string } | null, manifestationParts?: { __typename?: 'ManifestationParts', parts: Array<{ __typename?: 'ManifestationPart', title: string }> } | null, accessTypes: Array<{ __typename?: 'AccessType', code: AccessTypeCodeEnum }>, access: Array<{ __typename: 'AccessUrl', origin: string, url: string, loginRequired: boolean } | { __typename: 'DigitalArticleService', issn: string } | { __typename: 'Ereol', origin: string, url: string, canAlwaysBeLoaned: boolean } | { __typename: 'InfomediaService', id: string } | { __typename: 'InterLibraryLoan', loanIsPossible: boolean }>, shelfmark?: { __typename?: 'Shelfmark', postfix?: string | null, shelfmark: string } | null, workYear?: { __typename?: 'PublicationYear', year?: number | null } | null, catalogueCodes: { __typename?: 'CatalogueCodes', nationalBibliography: Array, otherCatalogues: Array } } }, materialTypes: Array<{ __typename?: 'MaterialType', materialTypeSpecific: { __typename?: 'SpecificMaterialType', display: string } }>, mainLanguages: Array<{ __typename?: 'Language', display: string, isoCode: string }>, subjects: { __typename?: 'SubjectContainer', all: Array<{ __typename?: 'Corporation', display: string } | { __typename?: 'Mood', display: string } | { __typename?: 'NarrativeTechnique', display: string } | { __typename?: 'Person', display: string } | { __typename?: 'Setting', display: string } | { __typename?: 'SubjectText', display: string } | { __typename?: 'SubjectWithRating', display: string } | { __typename?: 'TimePeriod', display: string }>, dbcVerified: Array<{ __typename?: 'Corporation', display: string } | { __typename?: 'Mood', display: string } | { __typename?: 'NarrativeTechnique', display: string } | { __typename?: 'Person', display: string } | { __typename?: 'Setting', display: string } | { __typename?: 'SubjectText', display: string } | { __typename?: 'SubjectWithRating', display: string } | { __typename?: 'TimePeriod', display: string }> }, fictionNonfiction?: { __typename?: 'FictionNonfiction', display: string, code: FictionNonfictionCodeEnum } | null, dk5MainEntry?: { __typename?: 'DK5MainEntry', display: string } | null, relations: { __typename?: 'Relations', hasReview: Array<{ __typename?: 'Manifestation', pid: string }>, hasAdaptation: Array<{ __typename?: 'Manifestation', ownerWork: { __typename?: 'Work', workId: string, workTypes: Array, titles: { __typename?: 'WorkTitles', main: Array } } }> } }; export type GetMaterialQueryVariables = Exact<{ wid: Scalars['String']['input']; @@ -2216,8 +2216,8 @@ export const ManifestationsFragmentDoc = ` } } ${ManifestationsFieldsFragmentDoc}`; -export const WorkFragmentDoc = ` - fragment Work on Work { +export const WorkFragmentFragmentDoc = ` + fragment WorkFragment on Work { workId titles { full @@ -2285,10 +2285,10 @@ ${ManifestationsFragmentDoc}`; export const GetMaterialDocument = ` query getMaterial($wid: String!) { work(id: $wid) { - ...Work + ...WorkFragment } } - ${WorkFragmentDoc}`; + ${WorkFragmentFragmentDoc}`; export const useGetMaterialQuery = < TData = GetMaterialQuery, diff --git a/lib/graphql/queries/material.fbi.graphql b/lib/graphql/queries/material.fbi.graphql index b9c4fdf3..606a48cd 100644 --- a/lib/graphql/queries/material.fbi.graphql +++ b/lib/graphql/queries/material.fbi.graphql @@ -1,5 +1,5 @@ query getMaterial($wid: String!) { work(id: $wid) { - ...Work + ...WorkFragment } } diff --git a/lib/helpers/helper.routes.ts b/lib/helpers/helper.routes.ts index bc7d5b98..be112464 100644 --- a/lib/helpers/helper.routes.ts +++ b/lib/helpers/helper.routes.ts @@ -34,7 +34,7 @@ export function buildRoute({ type ResolveUrlOptions = | { type: "work" - routeParams?: { id: number | string } + routeParams?: { wid: number | string } queryParams?: QueryParams } | { @@ -46,8 +46,12 @@ type ResolveUrlOptions = export const resolveUrl = ({ type, routeParams, queryParams }: ResolveUrlOptions) => { switch (type as ResolveUrlOptions["type"]) { case "work": - if (!routeParams?.id) return "" - return buildRoute({ route: "/work/:id", params: { id: routeParams.id }, query: queryParams }) + if (!routeParams?.wid) return "" + return buildRoute({ + route: "/work/:wid", + params: { wid: routeParams.wid }, + query: queryParams, + }) case "search": return buildRoute({ route: "/search", query: queryParams }) default: From a24e5bffbb07ec1b82ffa3e0bf4bfa5161e731d6 Mon Sep 17 00:00:00 2001 From: thomasgross Date: Wed, 20 Nov 2024 10:46:34 +0100 Subject: [PATCH 4/8] feat: update search configuration to use constants for facet keys and define TConfigSearchFacets type --- lib/config/resolvers/search.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/config/resolvers/search.ts b/lib/config/resolvers/search.ts index 07ba0cb1..b3f79dad 100644 --- a/lib/config/resolvers/search.ts +++ b/lib/config/resolvers/search.ts @@ -1,5 +1,7 @@ import { FacetFieldEnum } from "@/lib/graphql/generated/fbi/graphql" +export type TConfigSearchFacets = Record + const search = { "search.item.limit": 12, "search.offset.initial": 0, @@ -37,20 +39,18 @@ const search = { "775130", ], "search.facets": { - [FacetFieldEnum.Materialtypesgeneral]: { + MATERIALTYPESGENERAL: { filter: "materialTypesGeneral", translation: "Type", }, - [FacetFieldEnum.Mainlanguages]: { + MAINLANGUAGES: { filter: "mainLanguages", translation: "Sprog", }, - [FacetFieldEnum.Age]: { filter: "age", translation: "Alder" }, - [FacetFieldEnum.Lix]: { filter: "lixRange", translation: "Lix" }, - [FacetFieldEnum.Subjects]: { filter: "subjects", translation: "Emne" }, - }, + AGE: { filter: "age", translation: "Alder" }, + LIX: { filter: "lixRange", translation: "Lix" }, + SUBJECTS: { filter: "subjects", translation: "Emne" }, + } as TConfigSearchFacets, } -export type TConfigSearchFacets = Record - export default search From eac067d57832c32bc84710ad749525d1cba23246 Mon Sep 17 00:00:00 2001 From: thomasgross Date: Wed, 20 Nov 2024 10:48:21 +0100 Subject: [PATCH 5/8] feat: add typecheck and ci-check scripts to package.json for improved development workflow --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index cb790975..0cf69870 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "format:check": "prettier --check .", "format:write": "prettier --write .", "test:unit": "vitest", + "typecheck": "tsc --noEmit", + "ci-check": "yarn typecheck && yarn lint && yarn format:check && yarn test:unit", "codegen:graphql": "graphql-codegen --require tsconfig-paths/register --config codegen.ts", "codegen:all-rest-services": "orval", "codegen:covers": "rm -rf src/lib/rest/cover-service-api/generated/model/*.* && orval --project coverService", From 93b9d655ed463aeefab26b2a0433389721d7fa2c Mon Sep 17 00:00:00 2001 From: thomasgross Date: Wed, 20 Nov 2024 11:03:43 +0100 Subject: [PATCH 6/8] fix: update tests to ignore TypeScript errors and fix route parameter naming --- __tests__/config.test.ts | 3 ++- __tests__/refresh-token.test.ts | 5 +++++ __tests__/search.test.ts | 3 +++ __tests__/url.test.ts | 6 +++--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/__tests__/config.test.ts b/__tests__/config.test.ts index a6d668cc..c9e9617b 100644 --- a/__tests__/config.test.ts +++ b/__tests__/config.test.ts @@ -1,9 +1,10 @@ -import { expect, test, vi } from "vitest" +import { expect, test } from "vitest" import goConfig from "@/lib/config/config" import MissingConfigurationError from "@/lib/config/errors/MissingConfigurationError" test("That an error is thrown if we ask for unknown config", async () => { + // @ts-ignore expect(() => goConfig("unknown.thingy")).toThrowError(MissingConfigurationError) }) diff --git a/__tests__/refresh-token.test.ts b/__tests__/refresh-token.test.ts index 7dd31ce4..b1068679 100644 --- a/__tests__/refresh-token.test.ts +++ b/__tests__/refresh-token.test.ts @@ -4,6 +4,7 @@ import { IronSession, getIronSession } from "iron-session" import { testApiHandler } from "next-test-api-route-handler" import { afterAll, beforeAll, beforeEach, expect, test, vi } from "vitest" +// @ts-ignore import * as tokenRefreshHandler from "@/app/auth/token/refresh/route" import { TSessionData, accessTokenShouldBeRefreshed } from "@/lib/session/session" @@ -24,6 +25,7 @@ afterAll(() => { }) beforeEach(() => { + // @ts-ignore getIronSession.mockResolvedValue({ isLoggedIn: true, }) @@ -41,6 +43,7 @@ const sessionThatShouldBeRefreshed = () => ({ test("That the refresh endpoint redirects to the frontpage if there is no active session", async () => { // Simulate an anonymous session. + // @ts-ignore getIronSession.mockResolvedValue({ isLoggedIn: false, }) @@ -57,6 +60,7 @@ test("That the refresh endpoint redirects to the frontpage if there is no active test("That the refresh endpoint redirects to the given endpoint after refreshing token", async () => { // This is an authorized session that should be refreshed. + // @ts-ignore getIronSession.mockResolvedValue(sessionThatShouldBeRefreshed()) await testApiHandler({ @@ -69,6 +73,7 @@ test("That the refresh endpoint redirects to the given endpoint after refreshing }) // This is an authorized session that should NOT be refreshed. + // @ts-ignore getIronSession.mockResolvedValue({ isLoggedIn: true, expires: add(new Date(), { seconds: 300 }), diff --git a/__tests__/search.test.ts b/__tests__/search.test.ts index b6d52d41..bec98730 100644 --- a/__tests__/search.test.ts +++ b/__tests__/search.test.ts @@ -32,6 +32,7 @@ export const facets = { } as const beforeEach(() => { + // @ts-ignore ;(goConfig as jest.Mock).mockImplementation((key: string) => { if (key === "search.item.limit") { return 9 // Mocked return value for "search.item.limit" @@ -49,6 +50,7 @@ beforeEach(() => { describe("Facet functionality", () => { it("getMachineNames should return all the facet machine names", () => { + // @ts-ignore goConfig.mockReturnValue(facets) const machineNames = getFacetMachineNames() expect(machineNames).toStrictEqual([ @@ -109,6 +111,7 @@ describe("Facet functionality", () => { }) it("getFacetTranslation should give a translated facet when given a facet machine name", () => { + // @ts-ignore const translation = getFacetTranslation("LIX") expect(translation).toBe("Lix") }) diff --git a/__tests__/url.test.ts b/__tests__/url.test.ts index c12c5ef8..eb160586 100644 --- a/__tests__/url.test.ts +++ b/__tests__/url.test.ts @@ -1,16 +1,16 @@ -import { expect, test, vi } from "vitest" +import { expect, test } from "vitest" import { resolveUrl } from "../lib/helpers/helper.routes" test("That resolveUrl can return a work url", async () => { - const workUrl = resolveUrl({ type: "work", routeParams: { id: 123 } }) + const workUrl = resolveUrl({ type: "work", routeParams: { wid: 123 } }) expect(workUrl).toBe("/work/123") }) test("That resolveUrl can return a work url with a manifestation type", async () => { const workUrl = resolveUrl({ type: "work", - routeParams: { id: 123 }, + routeParams: { wid: 123 }, queryParams: { audio: "true" }, }) expect(workUrl).toBe("/work/123?audio=true") From d49f7f35beff40a641703967bb6a2dd8bb3eae5c Mon Sep 17 00:00:00 2001 From: thomasgross Date: Wed, 20 Nov 2024 11:03:49 +0100 Subject: [PATCH 7/8] refactor: remove unused export from publizonReader helper --- components/shared/publizonReader/helper.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/shared/publizonReader/helper.ts b/components/shared/publizonReader/helper.ts index 21d6d1f0..feb64fa7 100644 --- a/components/shared/publizonReader/helper.ts +++ b/components/shared/publizonReader/helper.ts @@ -39,5 +39,3 @@ export const appendAsset = ({ src, type }: AssetType) => { document.head.appendChild(linkElement) } } - -export default {} From 557c39e92c504f2f92312f7e7d1ed211eb6c489e Mon Sep 17 00:00:00 2001 From: thomasgross Date: Wed, 20 Nov 2024 11:08:24 +0100 Subject: [PATCH 8/8] chore: update unit test command to run once in CI and adjust ci-check script accordingly --- .github/workflows/unit-test.yml | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 59ec76f0..78a7c804 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -31,4 +31,4 @@ jobs: run: yarn install --frozen-lockfile - name: Run unit tests - run: yarn test:unit + run: yarn test:unit:once diff --git a/package.json b/package.json index 0cf69870..61e0613f 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,9 @@ "format:check": "prettier --check .", "format:write": "prettier --write .", "test:unit": "vitest", + "test:unit:once": "vitest run", "typecheck": "tsc --noEmit", - "ci-check": "yarn typecheck && yarn lint && yarn format:check && yarn test:unit", + "ci-check": "yarn typecheck && yarn lint && yarn format:check && yarn test:unit:once", "codegen:graphql": "graphql-codegen --require tsconfig-paths/register --config codegen.ts", "codegen:all-rest-services": "orval", "codegen:covers": "rm -rf src/lib/rest/cover-service-api/generated/model/*.* && orval --project coverService",