Skip to content

Commit

Permalink
fix: added flag to optionally add extra point if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoalee committed Jan 23, 2025
1 parent 3199dda commit 92c09a6
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 169 deletions.
9 changes: 1 addition & 8 deletions compose/neurosynth-frontend/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
{
"singleQuote": true,
"semi": true,
"trailingComma": "es5",
"tabWidth": 4,
"tabs": false,
"printWidth": 120
}
{}
8 changes: 6 additions & 2 deletions compose/neurosynth-frontend/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import eslint from '@eslint/js';
import teslint from 'typescript-eslint';
import eslintHooks from 'eslint-plugin-react-hooks';
import eslintCypress from 'eslint-plugin-cypress/flat';
import eslintPrettier from 'eslint-plugin-prettier/recommended';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import eslintConfigPrettier from 'eslint-config-prettier';
import globals from 'globals';
import eslintReactRefresh from 'eslint-plugin-react-refresh';

export default [
eslint.configs.recommended,
...teslint.configs.recommended,
eslintCypress.configs.recommended,
eslintPrettier,
eslintConfigPrettier,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
Expand All @@ -33,6 +35,8 @@ export default [
rules: {
...eslintHooks.configs.recommended.rules,
'react-refresh/only-export-components': 'warn',
// to override prettier settings, set it here
// "prettier/prettier": ["error", { printWidth: 20, tabWidth: 4, singleQuote: true }],
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const DisplayMetaAnalysisResult: React.FC<{
);

const { points, analysisSpace, analysisMap } = studyPointsToStorePoints(
(data?.points || []) as PointReturn[]
(data?.points || []) as PointReturn[],
false
);

const neurovaultLink = props.metaAnalysisResult?.neurovault_collection?.url || '';
Expand All @@ -33,9 +34,7 @@ const DisplayMetaAnalysisResult: React.FC<{
{resultStatus.color === 'error' && (
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<ErrorOutlineIcon color="error" sx={{ marginRight: '10px' }} />
<Typography sx={{ color: 'error.main' }}>
{resultStatus.statusText}
</Typography>
<Typography sx={{ color: 'error.main' }}>{resultStatus.statusText}</Typography>
</Box>
)}
</Box>
Expand All @@ -48,11 +47,7 @@ const DisplayMetaAnalysisResult: React.FC<{
underline="hover"
target="_blank"
rel="noreferrer"
href={
neurovaultLink.includes('/api')
? neurovaultLink.replace(/\/api/, '')
: neurovaultLink
}
href={neurovaultLink.includes('/api') ? neurovaultLink.replace(/\/api/, '') : neurovaultLink}
>
Neurovault Collection Link
</Link>
Expand Down
15 changes: 3 additions & 12 deletions compose/neurosynth-frontend/src/pages/Study/BaseStudyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ const BaseStudyPage: React.FC = (props) => {

// if studyVersionId doesnt exist, then it will not be queried.
// In the second useEffect hook below, we keep trying to set the studyVersionId
const {
data: study,
isLoading: studyIsLoading,
isError: studyIsError,
} = useGetStudyById(studyVersionId || '');
const { data: study, isLoading: studyIsLoading, isError: studyIsError } = useGetStudyById(studyVersionId || '');

// init the study store with the given version when a new one is set
useEffect(() => {
Expand All @@ -42,10 +38,7 @@ const BaseStudyPage: React.FC = (props) => {
// on initial load, we keep trying to set the URL with the study version until one is set
useEffect(() => {
if (baseStudy && baseStudy.versions && baseStudy.versions.length > 0 && !studyVersionId) {
navigate(
`/base-studies/${baseStudyId}/${(baseStudy.versions as StudyReturn[])[0].id}`,
{ replace: true }
);
navigate(`/base-studies/${baseStudyId}/${(baseStudy.versions as StudyReturn[])[0].id}`, { replace: true });
}
}, [baseStudy, baseStudyId, navigate, studyVersionId]);

Expand All @@ -69,9 +62,7 @@ const BaseStudyPage: React.FC = (props) => {
>
{((baseStudy?.versions || []) as StudyReturn[]).map((version, index) => {
// we want the date last "touched", prefer updated_at over created_at
const parsedDate = new Date(
version?.updated_at || version?.created_at || ''
);
const parsedDate = new Date(version?.updated_at || version?.created_at || '');

const dateStr = `${
parsedDate.getMonth() + 1
Expand Down
28 changes: 6 additions & 22 deletions compose/neurosynth-frontend/src/pages/Study/components/Study.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ import { IStoreStudy } from 'pages/Study/store/StudyStore.helpers';
import { Optional } from 'utils/utilitytypes';
import StudyAnalyses from './StudyAnalyses';
import StudyStyles from './Study.styles';
import DisplayStudyChipLinks from '../../../components/DisplayStudyChipLinks/DisplayStudyChipLinks';
import DisplayStudyChipLinks from 'components/DisplayStudyChipLinks/DisplayStudyChipLinks';

const Study: React.FC<Optional<IStoreStudy, 'metadata'>> = (props) => {
const {
id,
name,
description,
doi,
pmid,
authors,
publication: journal,
metadata,
analyses = [],
} = props;
const { id, name, description, doi, pmid, authors, publication: journal, metadata, analyses = [] } = props;
return (
<Box>
<Box data-tour="StudyPage-1">
Expand All @@ -33,7 +23,7 @@ const Study: React.FC<Optional<IStoreStudy, 'metadata'>> = (props) => {
color="primary"
sx={{ marginRight: '5px', borderRadius: '8px', marginBottom: '0.5rem' }}
size="medium"
label={`Version: ${id}` || ''}
label={id ? `Version: ${id}` : ''}
/>
)}
<Typography variant="h6">
Expand Down Expand Up @@ -68,9 +58,7 @@ const Study: React.FC<Optional<IStoreStudy, 'metadata'>> = (props) => {
backgroundColor: '#f2f2f2',
},
}}
TitleElement={
<Typography sx={{ color: 'primary.main' }}>Metadata</Typography>
}
TitleElement={<Typography sx={{ color: 'primary.main' }}>Metadata</Typography>}
>
<Box sx={StudyStyles.metadataContainer}>
<NeurosynthTable
Expand All @@ -88,17 +76,13 @@ const Study: React.FC<Optional<IStoreStudy, 'metadata'>> = (props) => {
{ text: 'Value', key: 'value', styles: { fontWeight: 'bold' } },
]}
rows={metadata
.sort((a, b) =>
sortMetadataArrayFn(a.metadataKey, b.metadataKey)
)
.sort((a, b) => sortMetadataArrayFn(a.metadataKey, b.metadataKey))
.map(({ metadataKey, metadataValue }) => (
<TableRow key={metadataKey}>
<TableCell>{metadataKey}</TableCell>
<TableCell
sx={{
color: NeurosynthTableStyles[
getType(metadataValue)
],
color: NeurosynthTableStyles[getType(metadataValue)],
}}
>
{getValue(metadataValue)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,20 @@ const StudyPoints: React.FC<{
>
<Box>
<Typography sx={{ display: 'inline' }}>Statistic: </Typography>
<Typography
sx={{ color: props.statistic ? '' : 'warning.dark', display: 'inline' }}
>
<Typography sx={{ color: props.statistic ? '' : 'warning.dark', display: 'inline' }}>
{props.statistic?.label || 'No Statistic selected'}
</Typography>
</Box>
<Box>
<Typography sx={{ display: 'inline' }}>Space: </Typography>
<Typography
sx={{ color: props.space ? '' : 'warning.dark', display: 'inline' }}
>
<Typography sx={{ color: props.space ? '' : 'warning.dark', display: 'inline' }}>
{props.space?.label || 'No space selected'}
</Typography>
</Box>
</Box>
<Box sx={{ width: '100%' }}>
{hotData.length === 0 ? (
<Typography sx={{ color: 'warning.dark' }}>
No coordinates have been added yet
</Typography>
<Typography sx={{ color: 'warning.dark' }}>No coordinates have been added yet</Typography>
) : (
<div style={{ width: '100%', height: '100%' }}>
<HotTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export type StudyDetails = Pick<
export type IStudyVersion = Pick<StudyReturn, 'user' | 'id'>;

export const studyPointsToStorePoints = (
points: PointReturn[]
points: PointReturn[],
initPointIfEmpty: boolean
): {
analysisSpace: MapOrSpaceType | undefined;
analysisMap: MapOrSpaceType | undefined;
Expand All @@ -130,20 +131,29 @@ export const studyPointsToStorePoints = (
let analysisMap: MapOrSpaceType | undefined;

let storePoints: IStorePoint[] = [];
if (points.length > 0) {
if (points.length === 0 && initPointIfEmpty) {
storePoints = [
{
cluster_size: undefined,
id: uuid(),
isNew: true,
value: undefined,
subpeak: undefined,
x: undefined,
y: undefined,
z: undefined,
},
];
} else {
storePoints = ((points || []) as Array<PointReturn>)
.map(({ entities, space, subpeak, cluster_size, values, kind, label_id, ...args }) => {
const typedValues = values as Array<PointValue> | undefined;
if (!analysisSpace && !!space) {
analysisSpace = DefaultSpaceTypes[space]
? DefaultSpaceTypes[space]
: DefaultSpaceTypes.OTHER;
analysisSpace = DefaultSpaceTypes[space] ? DefaultSpaceTypes[space] : DefaultSpaceTypes.OTHER;
}
if (!analysisMap && typedValues && typedValues.length > 0 && typedValues[0].kind) {
const kind = typedValues[0].kind || '';
analysisMap = DefaultMapTypes[kind]
? DefaultMapTypes[kind]
: DefaultMapTypes.OTHER;
analysisMap = DefaultMapTypes[kind] ? DefaultMapTypes[kind] : DefaultMapTypes.OTHER;
}

let value = undefined;
Expand All @@ -165,19 +175,6 @@ export const studyPointsToStorePoints = (
.sort((a, b) => {
return (a.order as number) - (b.order as number);
});
} else {
storePoints = [
{
cluster_size: undefined,
id: uuid(),
isNew: true,
value: undefined,
subpeak: undefined,
x: undefined,
y: undefined,
z: undefined,
},
];
}

return {
Expand All @@ -187,22 +184,26 @@ export const studyPointsToStorePoints = (
};
};

export const studyAnalysesToStoreAnalyses = (analyses?: AnalysisReturn[]): IStoreAnalysis[] => {
export const studyAnalysesToStoreAnalyses = (
analyses?: AnalysisReturn[],
initPointIfEmpty?: boolean = false
): IStoreAnalysis[] => {
const studyAnalyses: IStoreAnalysis[] = (analyses || []).map((analysis) => {
const { entities, ...analysisProps } = analysis;
const parsedAnalysis = {
...analysisProps,
};

const parsedConditions: IStoreCondition[] = (
(parsedAnalysis.conditions || []) as ConditionReturn[]
).map((condition) => ({
...condition,
isNew: false,
}));
const parsedConditions: IStoreCondition[] = ((parsedAnalysis.conditions || []) as ConditionReturn[]).map(
(condition) => ({
...condition,
isNew: false,
})
);

const { analysisMap, analysisSpace, points } = studyPointsToStorePoints(
(analysis.points || []) as PointReturn[]
(analysis.points || []) as PointReturn[],
initPointIfEmpty
);

return {
Expand Down
Loading

0 comments on commit 92c09a6

Please sign in to comment.