Skip to content

Commit

Permalink
Merge pull request #376 from datacite/all-related
Browse files Browse the repository at this point in the history
Add All option to related works filters
  • Loading branch information
jrhoads authored Jul 30, 2024
2 parents 9093c7e + 83591bf commit 403926e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 38 deletions.
19 changes: 15 additions & 4 deletions src/app/doi.org/[...doi]/RelatedContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -64,12 +66,21 @@ 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
//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 ?
Expand Down Expand Up @@ -98,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}
Expand Down
3 changes: 2 additions & 1 deletion src/components/WorkFacets/WorkFacets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion src/components/WorksListing/WorksListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 23 additions & 9 deletions src/data/queries/doiQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const workFragment = gql`
title
}
repository {
id:uid
id: uid
name
}
rights {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -333,7 +348,6 @@ export interface MetadataQueryData {
work: WorkMetadata
}


export interface QueryData {
work: Work
}
Expand All @@ -348,4 +362,4 @@ export interface QueryVar {
license?: string
fieldOfScience?: string
registrationAgency?: string
}
}
25 changes: 2 additions & 23 deletions src/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type Work = WorkMetadata & {
id: string
name: string
}

registered?: Date
formattedCitation?: string
claims?: Claim[]
Expand All @@ -57,9 +57,9 @@ export type Work = WorkMetadata & {
parts?: Works
partOf?: Works
otherRelated?: Works
allRelated?: Works
}


export type Works = {
totalCount: number
pageInfo: PageInfo
Expand All @@ -73,8 +73,6 @@ export type Works = {
personToWorkTypesMultilevel: MultilevelFacet[]
}



type Title = {
title: string
}
Expand All @@ -97,7 +95,6 @@ export type Rights = {
rightsIdentifier: string
}


type Creator = {
id: string
name: string
Expand Down Expand Up @@ -153,8 +150,6 @@ type UsageMonth = {
total: number
}



// Organization types
export type OrganizationMetadata = {
name: string
Expand All @@ -179,7 +174,6 @@ export type Organization = OrganizationMetadata & {
works: Works
}


export type Organizations = {
totalCount: number
pageInfo: PageInfo
Expand All @@ -188,8 +182,6 @@ export type Organizations = {
nodes: Organization[]
}



type Geolocation = {
pointLongitude: number
pointLatitude: number
Expand All @@ -200,8 +192,6 @@ type OrganizationIdentifier = {
identifierType: string
}



// People types
export type PersonMetadata = {
id: string
Expand All @@ -225,15 +215,13 @@ export interface Person extends PersonMetadata {
works: PersonWorks
}


export interface People {
__typename: String
totalCount: number
pageInfo: PageInfo
nodes: Person[]
}


interface Link {
name: string
url: string
Expand All @@ -253,8 +241,6 @@ interface PersonWorks extends Works {
openLicenseResourceTypes: Facet[]
}



// Repository types
export type RepositoryMetadata = {
id: string
Expand Down Expand Up @@ -293,8 +279,6 @@ export interface Repositories {
nodes: Repository[]
}



interface RepositoryWorks {
totalCount: number
languages: Facet[]
Expand All @@ -305,8 +289,6 @@ interface RepositoryWorks {
published: Facet[]
}



interface RepositoryFacet extends Facet {
name: string
}
Expand All @@ -319,9 +301,6 @@ type DefinedTerm = {
name: string
}




// Shared types
type Identifier = {
identifier: string
Expand Down

0 comments on commit 403926e

Please sign in to comment.