-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
766 add feature to download list of included papers as csv (#796)
* feat: added download button and logic to convert to bibtex * feat: added feature to download curation CSVs and bibtex files * feat: added window * feat: added testing * fix: remove unused imports * fix: failing cypress tests
- Loading branch information
Showing
27 changed files
with
615 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
compose/neurosynth-frontend/src/__mocks__/react-query/useIsFetching.ts
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
compose/neurosynth-frontend/src/__mocks__/react-query/useMutation.ts
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
compose/neurosynth-frontend/src/__mocks__/react-query/useQueryClient.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Style } from 'index'; | ||
|
||
const GlobalStyles: Style = { | ||
colorPulseAnimation: { | ||
animation: 'pulse 2s infinite', | ||
'@keyframes pulse': { | ||
'0%': { | ||
backgroundColor: 'success.light', | ||
}, | ||
'50%': { | ||
backgroundColor: 'white', | ||
}, | ||
'100%': { | ||
backgroundColor: 'success.light', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default GlobalStyles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
compose/neurosynth-frontend/src/hooks/external/useGetBibtexCitations.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import axios, { AxiosError } from 'axios'; | ||
import { stringToNumber } from 'helpers/utils'; | ||
import { ICurationStubStudy } from 'pages/Curation/Curation.types'; | ||
import { useMutation } from 'react-query'; | ||
|
||
const stringAsAuthorArray = (authors: string): IBibtex['author'] => { | ||
const authorsStringToArray = authors.split(', ').map((author) => { | ||
const nameAsArray = author.split(' '); | ||
if (nameAsArray.length === 0) { | ||
return { given: '', family: '' }; | ||
} else if (nameAsArray.length === 1) { | ||
return { given: nameAsArray[0], family: '' }; | ||
} else { | ||
const givenNames = nameAsArray.slice(0, nameAsArray.length - 1).join(' '); | ||
return { given: givenNames, family: nameAsArray[nameAsArray.length - 1] }; | ||
} | ||
}); | ||
return authorsStringToArray; | ||
}; | ||
|
||
const generateBibtexNote = (study: ICurationStubStudy) => { | ||
let bibtexNote = ''; | ||
if (study.pmid) bibtexNote = `PMID: ${study.pmid}`; | ||
if (study.pmcid) bibtexNote = `${bibtexNote}; PMCID: ${study.pmcid}`; | ||
if (study.neurostoreId) bibtexNote = `${bibtexNote}; Neurosynth ID: ${study.neurostoreId}`; | ||
if (study.identificationSource.label) { | ||
bibtexNote = `${bibtexNote}; Source: ${study.identificationSource.label}`; | ||
} | ||
if (study.tags.length > 0) { | ||
const tagString = study.tags.reduce( | ||
(prev, curr, index, arr) => | ||
`${prev}${curr.label}${index === arr.length - 1 ? '' : ','}`, | ||
'' | ||
); | ||
bibtexNote = `${bibtexNote}; Tags: ${tagString}`; | ||
} | ||
|
||
return bibtexNote; | ||
}; | ||
|
||
// this is not the complete Bibtex type. There are other other types | ||
// as described here: https://bibtex.eu/types/article/ however these are the most significant | ||
export interface IBibtex { | ||
author: { given: string; family: string }[]; | ||
title: string; | ||
DOI: string; | ||
note?: string; | ||
URL: string; | ||
abstract: string; | ||
issued: { | ||
'date-parts'?: [number, number, number][]; | ||
}; | ||
'container-title': string; // journal | ||
type: string; // article-journal for papers | ||
} | ||
|
||
// if we do not receive bibtex data from the api, then we create our own with the data we have | ||
export const generateBibtex = (study: ICurationStubStudy): IBibtex => { | ||
const { isValid, value } = stringToNumber(study.articleYear || ''); | ||
|
||
return { | ||
title: study.title, | ||
type: 'article-journal', | ||
DOI: study.doi || '', | ||
URL: study.articleLink || '', | ||
abstract: study.abstractText || '', | ||
note: generateBibtexNote(study), | ||
issued: { | ||
'date-parts': isValid ? [[value, 0, 0]] : undefined, | ||
}, | ||
'container-title': study.journal || '', | ||
author: stringAsAuthorArray(study.authors || ''), | ||
}; | ||
}; | ||
|
||
/** | ||
* NOTE: this is a get request but we use useMutation so that we can query the data imperatively. | ||
* This means that there is no smart refetching | ||
* https://github.com/TanStack/query/discussions/3675 | ||
*/ | ||
|
||
const useGetBibtexCitations = () => { | ||
return useMutation<IBibtex, AxiosError, ICurationStubStudy, unknown>(async (study) => { | ||
let res: IBibtex; | ||
try { | ||
res = ( | ||
await axios.get<{ message: IBibtex }>( | ||
`https://api.crossref.org/v1/works/${study.doi}` | ||
) | ||
).data.message; | ||
} catch (e) { | ||
res = generateBibtex(study); | ||
} | ||
// add a note with relevant neurosynth related data for provenance | ||
res.note = generateBibtexNote(study); | ||
return res; | ||
}); | ||
}; | ||
|
||
export default useGetBibtexCitations; |
9 changes: 9 additions & 0 deletions
9
compose/neurosynth-frontend/src/pages/Curation/Curation.helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const downloadFile = (filename: string, fileContents: BlobPart, contentType: string) => { | ||
const blob = new Blob([fileContents], { type: contentType }); | ||
const element = window.document.createElement('a'); | ||
element.href = window.URL.createObjectURL(blob); | ||
element.download = filename; | ||
window.document.body.appendChild(element); | ||
element.click(); | ||
window.document.body.removeChild(element); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.