From 0dc215a9287bc605b5aabfb7b9d9e8eddc1e0e38 Mon Sep 17 00:00:00 2001 From: jrhoads Date: Mon, 22 Jul 2024 14:52:10 +0200 Subject: [PATCH 1/4] Add allRelated to the doiQuery and types --- src/data/queries/doiQuery.ts | 32 +++++++++++++++++++++++--------- src/data/types.ts | 25 ++----------------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/data/queries/doiQuery.ts b/src/data/queries/doiQuery.ts index 9fbd59fe..feaeccc0 100644 --- a/src/data/queries/doiQuery.ts +++ b/src/data/queries/doiQuery.ts @@ -109,7 +109,7 @@ export const workFragment = gql` title } repository { - id:uid + id: uid name } rights { @@ -164,9 +164,7 @@ export const DOI_METADATA_QUERY = gql` ` export const DOI_QUERY = gql` - query getDoiQuery( - $id: ID! - ) { + query getDoiQuery($id: ID!) { work(id: $id) { ...WorkFragment contentUrl @@ -229,11 +227,28 @@ export const RELATED_CONTENT_QUERY = gql` $repositoryId: String ) { work(id: $id) { - doi, + doi types { - resourceTypeGeneral, + resourceTypeGeneral resourceType - }, + } + allRelated( + first: 25 + query: $filterQuery + after: $cursor + published: $published + resourceTypeId: $resourceTypeId + fieldOfScience: $fieldOfScience + language: $language + license: $license + registrationAgency: $registrationAgency + repositoryId: $repositoryId + ) { + ...WorkConnectionFragment + nodes { + ...WorkFragment + } + } citations( first: 25 query: $filterQuery @@ -333,7 +348,6 @@ export interface MetadataQueryData { work: WorkMetadata } - export interface QueryData { work: Work } @@ -348,4 +362,4 @@ export interface QueryVar { license?: string fieldOfScience?: string registrationAgency?: string -} \ No newline at end of file +} diff --git a/src/data/types.ts b/src/data/types.ts index 69eb41bf..4528dbce 100644 --- a/src/data/types.ts +++ b/src/data/types.ts @@ -40,7 +40,7 @@ export type Work = WorkMetadata & { id: string name: string } - + registered?: Date formattedCitation?: string claims?: Claim[] @@ -57,9 +57,9 @@ export type Work = WorkMetadata & { parts?: Works partOf?: Works otherRelated?: Works + allRelated?: Works } - export type Works = { totalCount: number pageInfo: PageInfo @@ -73,8 +73,6 @@ export type Works = { personToWorkTypesMultilevel: MultilevelFacet[] } - - type Title = { title: string } @@ -97,7 +95,6 @@ export type Rights = { rightsIdentifier: string } - type Creator = { id: string name: string @@ -153,8 +150,6 @@ type UsageMonth = { total: number } - - // Organization types export type OrganizationMetadata = { name: string @@ -179,7 +174,6 @@ export type Organization = OrganizationMetadata & { works: Works } - export type Organizations = { totalCount: number pageInfo: PageInfo @@ -188,8 +182,6 @@ export type Organizations = { nodes: Organization[] } - - type Geolocation = { pointLongitude: number pointLatitude: number @@ -200,8 +192,6 @@ type OrganizationIdentifier = { identifierType: string } - - // People types export type PersonMetadata = { id: string @@ -225,7 +215,6 @@ export interface Person extends PersonMetadata { works: PersonWorks } - export interface People { __typename: String totalCount: number @@ -233,7 +222,6 @@ export interface People { nodes: Person[] } - interface Link { name: string url: string @@ -253,8 +241,6 @@ interface PersonWorks extends Works { openLicenseResourceTypes: Facet[] } - - // Repository types export type RepositoryMetadata = { id: string @@ -293,8 +279,6 @@ export interface Repositories { nodes: Repository[] } - - interface RepositoryWorks { totalCount: number languages: Facet[] @@ -305,8 +289,6 @@ interface RepositoryWorks { published: Facet[] } - - interface RepositoryFacet extends Facet { name: string } @@ -319,9 +301,6 @@ type DefinedTerm = { name: string } - - - // Shared types type Identifier = { identifier: string From 84a18b08bf8d2a6cc51bd714bad59997db5e8f9a Mon Sep 17 00:00:00 2001 From: jrhoads Date: Mon, 22 Jul 2024 15:04:12 +0200 Subject: [PATCH 2/4] Add allRelated to commons UI --- src/app/doi.org/[...doi]/RelatedContent.tsx | 2 ++ src/components/WorkFacets/WorkFacets.tsx | 3 ++- src/components/WorksListing/WorksListing.tsx | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/doi.org/[...doi]/RelatedContent.tsx b/src/app/doi.org/[...doi]/RelatedContent.tsx index 25763586..d6265d81 100644 --- a/src/app/doi.org/[...doi]/RelatedContent.tsx +++ b/src/app/doi.org/[...doi]/RelatedContent.tsx @@ -45,6 +45,7 @@ export default function RelatedContent(props: Props) { const relatedWorks = data.work + const allRelatedCount = relatedWorks.allRelated?.totalCount || 0 const referenceCount = relatedWorks.references?.totalCount || 0 const citationCount = relatedWorks.citations?.totalCount || 0 const partCount = relatedWorks.parts?.totalCount || 0 @@ -56,6 +57,7 @@ export default function RelatedContent(props: Props) { const url = '/doi.org/' + relatedWorks.doi + '/?' const connectionTypeCounts = { + allRelated: allRelatedCount, references: referenceCount, citations: citationCount, parts: partCount, diff --git a/src/components/WorkFacets/WorkFacets.tsx b/src/components/WorkFacets/WorkFacets.tsx index a50028c9..a7fe44f4 100644 --- a/src/components/WorkFacets/WorkFacets.tsx +++ b/src/components/WorkFacets/WorkFacets.tsx @@ -12,7 +12,7 @@ interface Props { model: string url: string loading: boolean - connectionTypesCounts?: { references: number, citations: number, parts: number, partOf: number, otherRelated: number } + connectionTypesCounts?: { references: number, citations: number, parts: number, partOf: number, otherRelated: number, allRelated: number } } interface Facets { @@ -50,6 +50,7 @@ export default function WorkFacets({ const path = url.substring(0, url.length - 2) const connectionTypeList: Facet[] = connectionTypesCounts ? [ + { id: 'allRelated', title: 'All', count: connectionTypesCounts.allRelated }, { id: 'references', title: 'References', count: connectionTypesCounts.references }, { id: 'citations', title: 'Citations', count: connectionTypesCounts.citations }, { id: 'parts', title: 'Parts', count: connectionTypesCounts.parts }, diff --git a/src/components/WorksListing/WorksListing.tsx b/src/components/WorksListing/WorksListing.tsx index c02626e5..b5fdd07c 100644 --- a/src/components/WorksListing/WorksListing.tsx +++ b/src/components/WorksListing/WorksListing.tsx @@ -17,7 +17,7 @@ interface Props { showSankey?: boolean sankeyTitle?: string showFacets: boolean - connectionTypesCounts?: { references: number, citations: number, parts: number, partOf: number, otherRelated: number } + connectionTypesCounts?: { references: number, citations: number, parts: number, partOf: number, otherRelated: number , allRelated: number} showClaimStatus: boolean loading: boolean model: string From 9c80ffc5cb5ceb8faee14cc7ef561be8adbe66bf Mon Sep 17 00:00:00 2001 From: jrhoads Date: Tue, 30 Jul 2024 13:34:56 +0200 Subject: [PATCH 3/4] Set allRelated as the default relatedContent connection type. --- src/app/doi.org/[...doi]/RelatedContent.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/doi.org/[...doi]/RelatedContent.tsx b/src/app/doi.org/[...doi]/RelatedContent.tsx index d6265d81..125a3349 100644 --- a/src/app/doi.org/[...doi]/RelatedContent.tsx +++ b/src/app/doi.org/[...doi]/RelatedContent.tsx @@ -66,10 +66,11 @@ export default function RelatedContent(props: Props) { } const defaultConnectionType = + allRelatedCount > 0 ? 'allRelated' : referenceCount > 0 ? 'references' : - citationCount > 0 ? 'citations' : - partCount > 0 ? 'parts' : - partOfCount > 0 ? 'partOf' : 'otherRelated' + citationCount > 0 ? 'citations' : + partCount > 0 ? 'parts' : + partOfCount > 0 ? 'partOf' : 'otherRelated' const displayedConnectionType = connectionType ? connectionType : defaultConnectionType From 83591bf1b2aa8e67679a830c210fea656321fc66 Mon Sep 17 00:00:00 2001 From: jrhoads Date: Tue, 30 Jul 2024 15:08:21 +0200 Subject: [PATCH 4/4] Help craft the Sankey Title a littel better --- src/app/doi.org/[...doi]/RelatedContent.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/doi.org/[...doi]/RelatedContent.tsx b/src/app/doi.org/[...doi]/RelatedContent.tsx index 125a3349..d8644b32 100644 --- a/src/app/doi.org/[...doi]/RelatedContent.tsx +++ b/src/app/doi.org/[...doi]/RelatedContent.tsx @@ -73,6 +73,14 @@ export default function RelatedContent(props: Props) { partOfCount > 0 ? 'partOf' : 'otherRelated' const displayedConnectionType = connectionType ? connectionType : defaultConnectionType + //convert camel case to title and make first letter uppercase + //convert connectionType to title, allRelated becomes All Related Wokrs, references becomes References, citations becomes Citations, parts becomes Parts, partOf becomes Part Of, and otherRelated becomes Other Works + const displayedConnectionTitle = + displayedConnectionType === 'allRelated' ? 'All Related Works' : + displayedConnectionType === 'otherRelated' ? 'Other Works' : + displayedConnectionType.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase()) + + const works: Works = displayedConnectionType in relatedWorks ? @@ -101,7 +109,7 @@ export default function RelatedContent(props: Props) { connectionTypesCounts={connectionTypeCounts} showAnalytics={true} showSankey={showSankey} - sankeyTitle={`Contributions to ${displayedConnectionType}`} + sankeyTitle={`Contributions to ${displayedConnectionTitle}`} showClaimStatus={true} hasPagination={works.totalCount > 25} hasNextPage={hasNextPage}