Skip to content

Commit

Permalink
feat: added version toggle to study view
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoalee committed Aug 22, 2023
1 parent 092e3cc commit 732afa8
Show file tree
Hide file tree
Showing 26 changed files with 215 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import NavigationButtons, {
ENavigationButton,
} from 'components/Buttons/NavigationButtons/NavigationButtons';
import IdentificationSourcePopup from 'components/CurationComponents/SelectorPopups/SourcePopup/SourcePopup';
import { ISource } from 'hooks/requests/useGetProjects';
import { ISource } from 'hooks/projects/useGetProjects';
import { ChangeEvent, useState } from 'react';
import CreateStubStudyStyles from './CreateStubStudy.styles';
import { v4 as uuidv4 } from 'uuid';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import SearchContainer from 'components/Search/SearchContainer/SearchContainer';
import StateHandlerComponent from 'components/StateHandlerComponent/StateHandlerComponent';
import NeurosynthTable from 'components/Tables/NeurosynthTable/NeurosynthTable';
import NeurosynthTableStyles from 'components/Tables/NeurosynthTable/NeurosynthTable.styles';
import { useGetStudies } from 'hooks';
import { NeurosynthStudyList } from 'hooks/studies/useGetStudies';
import { useGetBaseStudies } from 'hooks';
import { NeurosynthStudyList } from 'hooks/studies/useGetBaseStudies';
import { useProjectId } from 'pages/Projects/ProjectPage/ProjectStore';
import { SearchCriteria } from 'pages/Studies/StudiesPage/StudiesPage';
import {
Expand Down Expand Up @@ -45,7 +45,7 @@ const NeurostoreSearch: React.FC<IImportArgs> = (props) => {
* exists before loading is complete so we are guaranteed that the first query will run
* with the studysetOwner set (if logged in) and undefined otherwise
*/
const { data, isLoading, isError, isFetching } = useGetStudies(
const { data, isLoading, isError, isFetching } = useGetBaseStudies(
{ ...debouncedSearchCriteria, studysetOwner: user?.sub, flat: 'true' },
!authenticationIsLoading
);
Expand All @@ -55,7 +55,7 @@ const NeurostoreSearch: React.FC<IImportArgs> = (props) => {
isLoading: allDataForSearchIsLoading,
isError: allDataForSearchIsError,
isFetching: allDataForSearchIsFetching,
} = useGetStudies(
} = useGetBaseStudies(
{ ...debouncedSearchCriteria, studysetOwner: user?.sub, pageSize: 29999, flat: 'true' }, // backend checks for less than 30000
!authenticationIsLoading
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import NavigationButtons, {
import { ChangeEvent, useEffect, useState } from 'react';
import { ICurationStubStudy } from 'components/CurationComponents/CurationStubStudy/CurationStubStudyDraggableContainer';
import { v4 as uuidv4 } from 'uuid';
import { ISource } from 'hooks/requests/useGetProjects';
import { ISource } from 'hooks/projects/useGetProjects';
import IdentificationSourcePopup from 'components/CurationComponents/SelectorPopups/SourcePopup/SourcePopup';
import { ENeurosynthSourceIds } from 'pages/Projects/ProjectPage/ProjectStore.helpers';
const Cite = require('citation-js');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import NavigationButtons, {
} from 'components/Buttons/NavigationButtons/NavigationButtons';
import { ICurationStubStudy } from 'components/CurationComponents/CurationStubStudy/CurationStubStudyDraggableContainer';
import TagSelectorPopup from 'components/CurationComponents/SelectorPopups/TagSelectorPopup/TagSelectorPopup';
import { ITag } from 'hooks/requests/useGetProjects';
import { ITag } from 'hooks/projects/useGetProjects';
import {
useCreateNewCurationInfoTag,
useProjectCurationInfoTags,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Paper } from '@mui/material';
import { ISource, ITag } from 'hooks/requests/useGetProjects';
import { ISource, ITag } from 'hooks/projects/useGetProjects';
import React from 'react';
import CurationStubStudy from './CurationStubStudy';
import CurationStubStudyStyles from './CurationStubStudy.styles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText';
import { SystemStyleObject } from '@mui/system';
import { ISource } from 'hooks/requests/useGetProjects';
import { ISource } from 'hooks/projects/useGetProjects';
import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { v4 as uuidv4 } from 'uuid';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText';
import { SystemStyleObject } from '@mui/system';
import { ITag } from 'hooks/requests/useGetProjects';
import { ITag } from 'hooks/projects/useGetProjects';
import { useEffect, useState } from 'react';
import { v4 as uuidv4 } from 'uuid';
import { ENeurosynthTagIds } from 'pages/Projects/ProjectPage/ProjectStore.helpers';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import IdentificationSourcePopup from 'components/CurationComponents/SelectorPop
import TagSelectorPopup from 'components/CurationComponents/SelectorPopups/TagSelectorPopup/TagSelectorPopup';
import BaseDialog, { IDialog } from 'components/Dialogs/BaseDialog';
import CreateStubStudyDialogStyles from 'components/Dialogs/CreateStubStudyDialog/CreateStubStudyDialog.styles';
import { ISource, ITag } from 'hooks/requests/useGetProjects';
import { ISource, ITag } from 'hooks/projects/useGetProjects';
import { useAddNewCurationStubs } from 'pages/Projects/ProjectPage/ProjectStore';
import React, { ChangeEvent, useState } from 'react';
import { v4 as uuidv4 } from 'uuid';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import IdentificationSourcePopup from 'components/CurationComponents/SelectorPop
import ConfirmationDialog from 'components/Dialogs/ConfirmationDialog/ConfirmationDialog';
import FullTextLinkComponent from 'components/FullTextLinkComponent/FullTextLinkComponent';
import TextEdit from 'components/TextEdit/TextEdit';
import { ISource } from 'hooks/requests/useGetProjects';
import { ISource } from 'hooks/projects/useGetProjects';
import { PUBMED_ARTICLE_URL_PREFIX } from 'hooks/external/useGetPubMedIds';
import {
useDeleteStub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import LoadingButton from 'components/Buttons/LoadingButton/LoadingButton';
import ExclusionSelectorPopup from 'components/CurationComponents/SelectorPopups/ExclusionSelectorPopup/ExclusionSelectorPopup';
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline';
import { ITag } from 'hooks/requests/useGetProjects';
import { ITag } from 'hooks/projects/useGetProjects';
import { useRef, useState } from 'react';
import { ENeurosynthTagIds } from 'pages/Projects/ProjectPage/ProjectStore.helpers';
import NeurosynthPopper from 'components/NeurosynthPopper/NeurosynthPopper';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { Box } from '@mui/material';
import DisplayAnalysesList from './DisplayAnalysesList/DisplayAnalysesList';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import DisplayAnalysis from './DisplayAnalysis/DisplayAnalysis';
import { IStoreAnalysis } from 'pages/Studies/StudyStore.helpers';

const DisplayAnalyses: React.FC<{
id: string | undefined;
analyses: IStoreAnalysis[];
}> = (props) => {
const [selectedAnalysisIndex, setSelectedAnalysisIndex] = useState(0);

useEffect(() => {
setSelectedAnalysisIndex(0);
}, [props.id]);

const handleSelectAnalysis = (index: number) => {
setSelectedAnalysisIndex(index);
if (props.analyses[index]) {
setSelectedAnalysisIndex(index);
} else {
setSelectedAnalysisIndex(0);
}
};

const selectedAnalysis = props.analyses[selectedAnalysisIndex];
Expand Down
174 changes: 101 additions & 73 deletions compose/neurosynth-frontend/src/components/DisplayStudy/DisplayStudy.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Box, Divider, Link, TableCell, TableRow, Typography } from '@mui/material';
import { Box, Chip, Divider, Link, TableCell, TableRow, Typography } from '@mui/material';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import { getType } from 'components/EditMetadata';
import { sortMetadataArrayFn } from 'components/EditStudyComponents/EditStudyMetadata/EditStudyMetadata';
import NeurosynthAccordion from 'components/NeurosynthAccordion/NeurosynthAccordion';
Expand All @@ -10,18 +11,24 @@ import DisplayStudyStyles from './DisplayStudy.styles';
import { PUBMED_ARTICLE_URL_PREFIX } from 'hooks/external/useGetPubMedIds';
import FullTextLinkComponent from 'components/FullTextLinkComponent/FullTextLinkComponent';
import { IStoreStudy } from 'pages/Studies/StudyStore.helpers';
import { Optional } from 'utils/utilitytypes';
import useGetFullText from 'hooks/external/useGetFullText';

const DisplayStudy: React.FC<IStoreStudy> = (props) => {
const DisplayStudy: React.FC<Optional<IStoreStudy, 'metadata'>> = (props) => {
const {
id,
name,
description,
doi,
pmid,
authors,
publication,
metadata = [],
metadata,
analyses = [],
} = props;
const { data: fullTextURL, isLoading, isError } = useGetFullText(name || '');

const hasFullText = !!fullTextURL && !isLoading && !isError;

return (
<Box>
Expand All @@ -33,87 +40,108 @@ const DisplayStudy: React.FC<IStoreStudy> = (props) => {
</Box>
<Typography>{authors}</Typography>
<Box>
<Typography>{publication}</Typography>
<FullTextLinkComponent
paperTitle={name || ''}
text="View Full Text For This Study"
/>
{doi && (
<Link
sx={{ display: 'block', margin: '5px 0' }}
<Typography gutterBottom>{publication}</Typography>
{hasFullText && (
<Chip
icon={<OpenInNewIcon />}
color="primary"
label="Full Text"
component="a"
href={fullTextURL}
target="_blank"
clickable
sx={{ width: '200px', marginRight: '15px' }}
variant="outlined"
/>
)}
{doi && (
<Chip
icon={<OpenInNewIcon />}
color="primary"
label={`DOI: ${doi}`}
component="a"
href={`https://doi.org/${doi}`}
underline="hover"
>
DOI: {doi}
</Link>
target="_blank"
clickable
sx={{ width: '200px', marginRight: '15px' }}
variant="outlined"
/>
)}
{pmid && (
<Link
sx={{ display: 'block', margin: '5px 0' }}
target="_blank"
<Chip
icon={<OpenInNewIcon />}
color="primary"
label={`PubMed: ${pmid}`}
component="a"
href={`${PUBMED_ARTICLE_URL_PREFIX}${pmid}`}
underline="hover"
>
PMID: {pmid}
</Link>
target="_blank"
clickable
sx={{ width: '200px' }}
variant="outlined"
/>
)}
</Box>
<TextExpansion
text={description || ''}
sx={{ ...DisplayStudyStyles.spaceBelow, whiteSpace: 'pre-wrap' }}
/>
</Box>
<Box data-tour="StudyPage-2" sx={{ margin: '15px' }}>
<NeurosynthAccordion
elevation={0}
expandIconColor={'primary.main'}
sx={{
border: '1px solid',
borderColor: 'primary.main',
}}
accordionSummarySx={{
':hover': {
backgroundColor: '#f2f2f2',
},
}}
TitleElement={<Typography sx={{ color: 'primary.main' }}>Metadata</Typography>}
>
<Box sx={DisplayStudyStyles.metadataContainer}>
<NeurosynthTable
tableConfig={{
noDataDisplay: (
<Typography sx={{ color: 'warning.dark', margin: '1rem' }}>
No metadata
</Typography>
),
tableHeaderBackgroundColor: 'white',
tableElevation: 0,
}}
headerCells={[
{ text: 'Name', key: 'name', styles: { fontWeight: 'bold' } },
{ text: 'Value', key: 'value', styles: { fontWeight: 'bold' } },
]}
rows={metadata
.sort((a, b) => sortMetadataArrayFn(a.metadataKey, b.metadataKey))
.map(({ metadataKey, metadataValue }) => (
<TableRow key={metadataKey}>
<TableCell>{metadataKey}</TableCell>
<TableCell
sx={{
color: NeurosynthTableStyles[
getType(metadataValue)
],
}}
>
{getValue(metadataValue)}
</TableCell>
</TableRow>
))}
/>
</Box>
</NeurosynthAccordion>
</Box>
{metadata && (
<Box data-tour="StudyPage-2" sx={{ margin: '15px' }}>
<NeurosynthAccordion
elevation={0}
expandIconColor={'primary.main'}
sx={{
border: '1px solid',
borderColor: 'primary.main',
}}
accordionSummarySx={{
':hover': {
backgroundColor: '#f2f2f2',
},
}}
TitleElement={
<Typography sx={{ color: 'primary.main' }}>Metadata</Typography>
}
>
<Box sx={DisplayStudyStyles.metadataContainer}>
<NeurosynthTable
tableConfig={{
noDataDisplay: (
<Typography sx={{ color: 'warning.dark', margin: '1rem' }}>
No metadata
</Typography>
),
tableHeaderBackgroundColor: 'white',
tableElevation: 0,
}}
headerCells={[
{ text: 'Name', key: 'name', styles: { fontWeight: 'bold' } },
{ text: 'Value', key: 'value', styles: { fontWeight: 'bold' } },
]}
rows={metadata
.sort((a, b) =>
sortMetadataArrayFn(a.metadataKey, b.metadataKey)
)
.map(({ metadataKey, metadataValue }) => (
<TableRow key={metadataKey}>
<TableCell>{metadataKey}</TableCell>
<TableCell
sx={{
color: NeurosynthTableStyles[
getType(metadataValue)
],
}}
>
{getValue(metadataValue)}
</TableCell>
</TableRow>
))}
/>
</Box>
</NeurosynthAccordion>
</Box>
)}

<Box>
<Typography
Expand All @@ -137,7 +165,7 @@ const DisplayStudy: React.FC<IStoreStudy> = (props) => {
<>
<Box sx={{ marginBottom: '1rem', padding: '0 1rem' }}>
<Divider />
<DisplayAnalyses analyses={analyses} />
<DisplayAnalyses id={id} analyses={analyses} />
</Box>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Box } from '@mui/material';
import ReactFlow from 'reactflow';
import 'reactflow/dist/style.css';
import NeurosynthNode from './NeurosynthNode';
import { INeurosynthProject } from 'hooks/requests/useGetProjects';
import { INeurosynthProject } from 'hooks/projects/useGetProjects';
import { useEffect, useState } from 'react';
import NeurosynthPRISMAHelper, { IPrismaGroup } from './PrismaHelpers';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { INeurosynthNodeData } from 'components/PrismaComponent/NeurosynthNode';
import { ENeurosynthTagIds } from 'pages/Projects/ProjectPage/ProjectStore.helpers';
import { CSSProperties } from 'react';
import { Edge, MarkerType, Node } from 'reactflow';
import { IProvenance, ISource, ITag } from 'hooks/requests/useGetProjects';
import { IProvenance, ISource, ITag } from 'hooks/projects/useGetProjects';

type IPRISMAExclusion = ITag & { numRecords: number };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ISemanticScholarResponse {
}[];
}

const useGetFullText = (paperTitle: string) => {
const useGetFullText = (paperTitle?: string) => {
return useQuery(
[paperTitle],
() =>
Expand All @@ -41,6 +41,7 @@ const useGetFullText = (paperTitle: string) => {
return paperList[0].openAccessPdf.url;
}
},
enabled: !!paperTitle,
}
);
};
Expand Down
Loading

0 comments on commit 732afa8

Please sign in to comment.