Skip to content

Commit f2e6d84

Browse files
authored
[ENH] add ids param on meta-analysis endpoint (#687)
* switch to main branch * update logic and test * update typescript libraries * switch from using a filter to a specific meta-analysis query * add new hook
1 parent 8383a85 commit f2e6d84

File tree

12 files changed

+90
-31
lines changed

12 files changed

+90
-31
lines changed

compose/neurosynth-frontend/src/components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationDetailsStep/CreateMetaAnalysisSpecificationDetailsStep.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Box, TextField } from '@mui/material';
22
import NavigationButtons, {
33
ENavigationButton,
44
} from 'components/Buttons/NavigationButtons/NavigationButtons';
5-
import { useGetMetaAnalysesByProjectId } from 'hooks';
6-
import { useProjectName } from 'pages/Projects/ProjectPage/ProjectStore';
5+
import { useGetMetaAnalysesByIds } from 'hooks';
6+
import { useProjectName, useProjectMetaAnalyses } from 'pages/Projects/ProjectPage/ProjectStore';
7+
import { MetaAnalysisReturn } from 'neurosynth-compose-typescript-sdk';
78
import { ChangeEvent, useEffect } from 'react';
8-
import { useParams } from 'react-router-dom';
99

1010
const CreateMetaAnalysisSpecificationDetailsStep: React.FC<{
1111
details: { name: string; description: string };
@@ -15,8 +15,18 @@ const CreateMetaAnalysisSpecificationDetailsStep: React.FC<{
1515
onUpdateDetails: (details: { name: string; description: string }) => void;
1616
onNavigate: (button: ENavigationButton) => void;
1717
}> = (props) => {
18-
const { projectId } = useParams<{ projectId: string | undefined }>();
19-
const { data } = useGetMetaAnalysesByProjectId(projectId);
18+
const projectMetaAnalyses = useProjectMetaAnalyses() || [];
19+
let metaAnalysisIds: string[] = [];
20+
if (projectMetaAnalyses.length > 0) {
21+
if (typeof projectMetaAnalyses[0] === 'string') {
22+
metaAnalysisIds = projectMetaAnalyses as string[];
23+
} else {
24+
metaAnalysisIds = (projectMetaAnalyses as MetaAnalysisReturn[])
25+
.map((metaAnalysis) => metaAnalysis.id)
26+
.filter((id): id is string => id !== undefined);
27+
}
28+
}
29+
const { data } = useGetMetaAnalysesByIds(metaAnalysisIds);
2030
const { details, selectionKey, algorithmName, correctorName, onUpdateDetails, onNavigate } =
2131
props;
2232
const projectName = useProjectName();

compose/neurosynth-frontend/src/components/ProjectComponents/ViewMetaAnalyses/ViewMetaAnalyses.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,31 @@ import { Add } from '@mui/icons-material';
22
import { Box, Button, Typography } from '@mui/material';
33
import CreateMetaAnalysisSpecificationDialogBase from 'components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationDialogBase';
44
import StateHandlerComponent from 'components/StateHandlerComponent/StateHandlerComponent';
5-
import { useGetMetaAnalysesByProjectId, useGuard } from 'hooks';
5+
import { useGetMetaAnalysesByIds, useGuard } from 'hooks';
66
import {
77
useProjectId,
8+
useProjectMetaAnalyses,
89
useProjectMetaAnalysisCanEdit,
910
} from 'pages/Projects/ProjectPage/ProjectStore';
11+
import { MetaAnalysisReturn } from 'neurosynth-compose-typescript-sdk';
1012
import { useState } from 'react';
1113
import { useParams } from 'react-router-dom';
1214
import ViewMetaAnalysis from './ViewMetaAnalysis';
1315

1416
const ViewMetaAnalyses: React.FC = () => {
1517
const { projectId }: { projectId: string } = useParams();
16-
const { data, isLoading, isError } = useGetMetaAnalysesByProjectId(projectId);
18+
const projectMetaAnalyses = useProjectMetaAnalyses() || [];
19+
let metaAnalysisIds: string[] = [];
20+
if (projectMetaAnalyses.length > 0) {
21+
if (typeof projectMetaAnalyses[0] === 'string') {
22+
metaAnalysisIds = projectMetaAnalyses as string[];
23+
} else {
24+
metaAnalysisIds = (projectMetaAnalyses as MetaAnalysisReturn[])
25+
.map((metaAnalysis) => metaAnalysis.id)
26+
.filter((id): id is string => id !== undefined);
27+
}
28+
}
29+
const { data, isLoading, isError } = useGetMetaAnalysesByIds(metaAnalysisIds);
1730
const canEditMetaAnalyses = useProjectMetaAnalysisCanEdit();
1831
const projectIdFromProject = useProjectId();
1932
const [createMetaAnalysisDialogIsOpen, setCreateMetaAnalysisDialogIsOpen] = useState(false);

compose/neurosynth-frontend/src/hooks/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import useGetTour from './useGetTour';
66
import useGetWindowHeight from './useGetWindowHeight';
77

88
import useCreateAlgorithmSpecification from './metaAnalyses/useCreateAlgorithmSpecification';
9-
import useGetMetaAnalysesByProjectId from './metaAnalyses/useGetMetaAnalysesByProjectId';
9+
import useGetMetaAnalysesByIds from './metaAnalyses/useGetMetaAnalysesByIds';
1010
import useGetMetaAnalysisById from './metaAnalyses/useGetMetaAnalysisById';
1111
import useGetAnnotationsByStudysetId from './analyses/useGetAnnotationsByStudysetId';
1212
import useCreatePoint from './analyses/useCreatePoint';
@@ -46,7 +46,7 @@ export {
4646
useCreateStudy,
4747
// META-ANALYSES
4848
useCreateAlgorithmSpecification,
49-
useGetMetaAnalysesByProjectId,
49+
useGetMetaAnalysesByIds,
5050
useGetMetaAnalysisById,
5151
// STUDYSETS
5252
useGetStudysets,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useQuery } from 'react-query';
2+
import API from 'utils/api';
3+
4+
const useGetMetaAnalysesByIds = (metaAnalysisIds: string[] | undefined) => {
5+
return useQuery(
6+
['meta-analyses', metaAnalysisIds],
7+
() =>
8+
API.NeurosynthServices.MetaAnalysisService.metaAnalysesGet(
9+
false,
10+
metaAnalysisIds || []
11+
),
12+
{
13+
select: (axiosResponse) => {
14+
const res = axiosResponse.data.results || [];
15+
return res;
16+
},
17+
}
18+
);
19+
};
20+
21+
export default useGetMetaAnalysesByIds;

compose/neurosynth-frontend/src/hooks/metaAnalyses/useGetMetaAnalysesByProjectId.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

compose/neurosynth-frontend/src/pages/MetaAnalyses/MetaAnalysesPage/MetaAnalysesPage.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@ import { Box, TableCell, TableRow, Typography } from '@mui/material';
22
import StateHandlerComponent from 'components/StateHandlerComponent/StateHandlerComponent';
33
import NeurosynthTable from 'components/Tables/NeurosynthTable/NeurosynthTable';
44
import NeurosynthTableStyles from 'components/Tables/NeurosynthTable/NeurosynthTable.styles';
5-
import { useGetMetaAnalysesByProjectId } from 'hooks';
5+
import { useGetMetaAnalysesByIds } from 'hooks';
6+
import { useProjectMetaAnalyses } from 'pages/Projects/ProjectPage/ProjectStore';
7+
import { MetaAnalysisReturn } from 'neurosynth-compose-typescript-sdk';
68
import { useHistory } from 'react-router-dom';
79

810
const MetaAnalysesPage: React.FC = (props) => {
911
const history = useHistory();
10-
const { data, isLoading, isError } = useGetMetaAnalysesByProjectId();
12+
const projectMetaAnalyses = useProjectMetaAnalyses() || [];
13+
let metaAnalysisIds: string[] = [];
14+
if (projectMetaAnalyses.length > 0) {
15+
if (typeof projectMetaAnalyses[0] === 'string') {
16+
metaAnalysisIds = projectMetaAnalyses as string[];
17+
} else {
18+
metaAnalysisIds = (projectMetaAnalyses as MetaAnalysisReturn[])
19+
.map((metaAnalysis) => metaAnalysis.id)
20+
.filter((id): id is string => id !== undefined);
21+
}
22+
}
23+
const { data, isLoading, isError } = useGetMetaAnalysesByIds(metaAnalysisIds);
1124

1225
return (
1326
<>

compose/neurosynth-frontend/src/pages/Projects/ProjectPage/ProjectStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ export const useUpdateProjectIsLoading = () =>
742742
useProjectStore((state) => state.metadata.updateProjectIsLoading);
743743
export const useProjectIsError = () => useProjectStore((state) => state.metadata.isError);
744744
export const useProjectUser = () => useProjectStore((state) => state.user);
745+
export const useProjectMetaAnalyses = () => useProjectStore((state) => state.meta_analyses);
745746

746747
// curation retrieval hooks
747748
export const useProjectCurationColumns = () =>

compose/neurosynth_compose/openapi

0 commit comments

Comments
 (0)