-
Notifications
You must be signed in to change notification settings - Fork 3
Transition DOI related works to REST API #548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1e76cec
c3fe7b5
fc2b180
89f7c5f
4000c26
ce03ff0
f34f3a4
64e55c8
6b003c7
296b98f
bfb83a9
3485070
95e408c
693e2b8
6191795
f860b33
8f3e3d7
ffdc42c
2b615c9
36b1345
ad8b937
7c40b23
09a1875
b039ce3
3493c57
2f5ed11
49d6a60
72cb9d5
e54d997
3f56d08
257728c
517c28b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,34 +1,34 @@ | ||||||||||||||||||||||||||||||||||||||
| 'use client' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import React from 'react' | ||||||||||||||||||||||||||||||||||||||
| import { useParams, useSearchParams } from 'next/navigation' | ||||||||||||||||||||||||||||||||||||||
| import { useSearchParams } from 'next/navigation' | ||||||||||||||||||||||||||||||||||||||
| import Container from 'react-bootstrap/Container' | ||||||||||||||||||||||||||||||||||||||
| import Col from 'react-bootstrap/Col' | ||||||||||||||||||||||||||||||||||||||
| import Row from 'react-bootstrap/Row' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import Loading from 'src/components/Loading/Loading' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import { useDoiRelatedContentQuery } from 'src/data/queries/doiRelatedContentQuery' | ||||||||||||||||||||||||||||||||||||||
| import { Works } from 'src/data/types' | ||||||||||||||||||||||||||||||||||||||
| import { Work, Works } from 'src/data/types' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import Error from 'src/components/Error/Error' | ||||||||||||||||||||||||||||||||||||||
| import WorksListing from 'src/components/WorksListing/WorksListing' | ||||||||||||||||||||||||||||||||||||||
| import mapSearchparams from './mapSearchParams' | ||||||||||||||||||||||||||||||||||||||
| import { isDMP, isProject } from 'src/utils/helpers' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| interface Props { | ||||||||||||||||||||||||||||||||||||||
| work: Work, | ||||||||||||||||||||||||||||||||||||||
| relatedDois: string[], | ||||||||||||||||||||||||||||||||||||||
| isBot?: boolean | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export default function RelatedContent(props: Props) { | ||||||||||||||||||||||||||||||||||||||
| const { isBot = false } = props | ||||||||||||||||||||||||||||||||||||||
| const doiParams = useParams().doi as string[] | ||||||||||||||||||||||||||||||||||||||
| const doi = decodeURIComponent(doiParams.join('/')) | ||||||||||||||||||||||||||||||||||||||
| const { isBot = false, work, relatedDois } = props | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const searchParams = useSearchParams() | ||||||||||||||||||||||||||||||||||||||
| const { variables, connectionType } = mapSearchparams(Object.fromEntries(searchParams.entries()) as any) | ||||||||||||||||||||||||||||||||||||||
| const { variables } = mapSearchparams(Object.fromEntries(searchParams.entries()) as any) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const vars = { id: doi, ...variables } | ||||||||||||||||||||||||||||||||||||||
| const vars = { relatedToDoi: work.doi, relatedDois, ...variables } | ||||||||||||||||||||||||||||||||||||||
| const { loading, data, error } = useDoiRelatedContentQuery(vars) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (isBot) return null | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -42,55 +42,31 @@ export default function RelatedContent(props: Props) { | |||||||||||||||||||||||||||||||||||||
| </Col> | ||||||||||||||||||||||||||||||||||||||
| </Row> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (!data) return | ||||||||||||||||||||||||||||||||||||||
| if ((!data || data.works.totalCount === 0) && !searchParams) return | ||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The
If the intent is to return early when there are no search parameters set, use 🔎 Proposed fix- if ((!data || data.works.totalCount === 0) && !searchParams) return
+ if ((!data || data.works.totalCount === 0) && searchParams.size === 0) returnOr if the searchParams check is not needed: - if ((!data || data.works.totalCount === 0) && !searchParams) return
+ if (!data || data.works.totalCount === 0) return null📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const showSankey = isDMP(data.work) || isProject(data.work) | ||||||||||||||||||||||||||||||||||||||
| const relatedWorks = data.work | ||||||||||||||||||||||||||||||||||||||
| const relatedWorks = (data?.works ?? { | ||||||||||||||||||||||||||||||||||||||
| nodes: [], | ||||||||||||||||||||||||||||||||||||||
| totalCount: 0, | ||||||||||||||||||||||||||||||||||||||
| pageInfo: { endCursor: '', hasNextPage: false } | ||||||||||||||||||||||||||||||||||||||
| }) as Works | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const showSankey = isDMP(work) || isProject(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 | ||||||||||||||||||||||||||||||||||||||
| const partOfCount = relatedWorks.partOf?.totalCount || 0 | ||||||||||||||||||||||||||||||||||||||
| const otherRelatedCount = relatedWorks.otherRelated?.totalCount || 0 | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (referenceCount + citationCount + partCount + partOfCount + otherRelatedCount === 0) return '' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const url = '/doi.org/' + relatedWorks.doi + '/?' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const connectionTypeCounts = { | ||||||||||||||||||||||||||||||||||||||
| allRelated: allRelatedCount, | ||||||||||||||||||||||||||||||||||||||
| references: referenceCount, | ||||||||||||||||||||||||||||||||||||||
| citations: citationCount, | ||||||||||||||||||||||||||||||||||||||
| parts: partCount, | ||||||||||||||||||||||||||||||||||||||
| partOf: partOfCount, | ||||||||||||||||||||||||||||||||||||||
| otherRelated: otherRelatedCount | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const defaultConnectionType = | ||||||||||||||||||||||||||||||||||||||
| allRelatedCount > 0 ? 'allRelated' : | ||||||||||||||||||||||||||||||||||||||
| referenceCount > 0 ? 'references' : | ||||||||||||||||||||||||||||||||||||||
| citationCount > 0 ? 'citations' : | ||||||||||||||||||||||||||||||||||||||
| partCount > 0 ? 'parts' : | ||||||||||||||||||||||||||||||||||||||
| partOfCount > 0 ? 'partOf' : 'otherRelated' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const displayedConnectionType = connectionType ? connectionType : defaultConnectionType | ||||||||||||||||||||||||||||||||||||||
| const defaultConnectionType = 'allRelated' | ||||||||||||||||||||||||||||||||||||||
| const connectionType = searchParams.get('connection-type') || 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()) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| connectionType === 'allRelated' ? 'All Related Works' : | ||||||||||||||||||||||||||||||||||||||
| connectionType === 'otherRelated' ? 'Other Works' : | ||||||||||||||||||||||||||||||||||||||
| connectionType.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase()) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
57
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in comment: "Wokrs" should be "Works". 🔎 Proposed fix //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
+ //convert connectionType to title, allRelated becomes All Related Works, references becomes References, citations becomes Citations, parts becomes Parts, partOf becomes Part Of, and otherRelated becomes Other Works📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const works: Works = displayedConnectionType in relatedWorks ? | ||||||||||||||||||||||||||||||||||||||
| relatedWorks[displayedConnectionType] : | ||||||||||||||||||||||||||||||||||||||
| { totalCount: 0, nodes: [] } | ||||||||||||||||||||||||||||||||||||||
| const url = '/doi.org/' + work.doi + '/?' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const hasNextPage = works.pageInfo ? works.pageInfo.hasNextPage : false | ||||||||||||||||||||||||||||||||||||||
| const endCursor = works.pageInfo ? works.pageInfo.endCursor : '' | ||||||||||||||||||||||||||||||||||||||
| const hasNextPage = relatedWorks.pageInfo.hasNextPage | ||||||||||||||||||||||||||||||||||||||
| const endCursor = relatedWorks.pageInfo | ||||||||||||||||||||||||||||||||||||||
| ? relatedWorks.pageInfo.endCursor | ||||||||||||||||||||||||||||||||||||||
| : '' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||
| <Container fluid> | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -101,14 +77,14 @@ export default function RelatedContent(props: Props) { | |||||||||||||||||||||||||||||||||||||
| </Row> | ||||||||||||||||||||||||||||||||||||||
| <Row> | ||||||||||||||||||||||||||||||||||||||
| <WorksListing | ||||||||||||||||||||||||||||||||||||||
| works={works} | ||||||||||||||||||||||||||||||||||||||
| works={relatedWorks} | ||||||||||||||||||||||||||||||||||||||
| loading={loading} | ||||||||||||||||||||||||||||||||||||||
| connectionTypesCounts={connectionTypeCounts} | ||||||||||||||||||||||||||||||||||||||
| vars={vars} | ||||||||||||||||||||||||||||||||||||||
| showAnalytics={true} | ||||||||||||||||||||||||||||||||||||||
| showSankey={showSankey} | ||||||||||||||||||||||||||||||||||||||
| sankeyTitle={`Contributions to ${displayedConnectionTitle}`} | ||||||||||||||||||||||||||||||||||||||
| showClaimStatus={true} | ||||||||||||||||||||||||||||||||||||||
| hasPagination={works.totalCount > 25} | ||||||||||||||||||||||||||||||||||||||
| hasPagination={relatedWorks.totalCount > 25} | ||||||||||||||||||||||||||||||||||||||
| hasNextPage={hasNextPage} | ||||||||||||||||||||||||||||||||||||||
| model={'doi'} | ||||||||||||||||||||||||||||||||||||||
| url={url} | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the imported
Errorcomponent to avoid shadowing the global.The import shadows the global
Errorconstructor, which can cause confusion and unexpected behavior if the globalErroris needed elsewhere in this file.🔎 Proposed fix
And update the usage at line 41:
🧰 Tools
🪛 Biome (2.1.2)
[error] 14-14: Do not shadow the global "Error" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
🤖 Prompt for AI Agents