Skip to content

Commit 8465093

Browse files
authored
Fix/switch study (#697)
* use info true and flat false when getting a basestudy * remove the put and pass data through request
1 parent e218e11 commit 8465093

File tree

2 files changed

+14
-37
lines changed

2 files changed

+14
-37
lines changed

compose/neurosynth-frontend/src/components/EditStudyComponents/EditStudySaveButton/EditStudySaveButton.tsx

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { Box } from '@mui/material';
22
import LoadingButton from 'components/Buttons/LoadingButton/LoadingButton';
3-
import {
4-
AnalysisReturn,
5-
ConditionRequest,
6-
PointRequest,
7-
StudyRequest,
8-
} from 'neurostore-typescript-sdk';
3+
import { AnalysisReturn, StudyRequest } from 'neurostore-typescript-sdk';
94
import { useSnackbar } from 'notistack';
105
import {
116
useProjectExtractionAnnotationId,
@@ -19,7 +14,6 @@ import {
1914
useCreateStudy,
2015
useGetStudysetById,
2116
useUpdateAnnotationById,
22-
useUpdateStudy,
2317
useUpdateStudyset,
2418
} from 'hooks';
2519
import EditStudyPageStyles from 'pages/Studies/EditStudyPage/EditStudyPage.styles';
@@ -77,7 +71,6 @@ const EditStudySaveButton: React.FC = React.memo((props) => {
7771
const { data: studyset } = useGetStudysetById(studysetId || undefined, false);
7872
const { mutateAsync: updateStudyset } = useUpdateStudyset();
7973
const { mutateAsync: createStudy } = useCreateStudy();
80-
const { mutateAsync: updateStudy } = useUpdateStudy();
8174
const { mutateAsync: updateAnnotation } = useUpdateAnnotationById(annotationId);
8275

8376
const [isCloning, setIsCloning] = useState(false);
@@ -163,21 +156,7 @@ const EditStudySaveButton: React.FC = React.memo((props) => {
163156
publication: storeStudy.publication,
164157
authors: storeStudy.authors,
165158
year: storeStudy.year,
166-
analyses: storeAnalysesToStudyAnalyses(storeStudy.analyses).map((analysis) => {
167-
const scrubbedAnalysis = { ...analysis };
168-
((scrubbedAnalysis.points || []) as PointRequest[]).forEach((point) => {
169-
delete point.id;
170-
delete point.analysis;
171-
});
172-
((scrubbedAnalysis.conditions || []) as ConditionRequest[]).forEach((condition) => {
173-
delete condition.id;
174-
});
175-
176-
delete scrubbedAnalysis.id;
177-
delete scrubbedAnalysis.study;
178-
179-
return scrubbedAnalysis;
180-
}),
159+
analyses: storeAnalysesToStudyAnalyses(storeStudy.analyses),
181160
};
182161

183162
return updatedStudy;
@@ -202,19 +181,12 @@ const EditStudySaveButton: React.FC = React.memo((props) => {
202181
if (currentStudyBeingEditedIndex < 0) throw new Error('study not found in studyset');
203182

204183
// 1. clone the study
205-
const clonedStudy = (await createStudy(storeStudy.id)).data;
184+
const clonedStudy = (
185+
await createStudy({ sourceId: storeStudy.id, data: getNewScrubbedStudyFromStore() })
186+
).data;
206187
const clonedStudyId = clonedStudy.id;
207188
if (!clonedStudyId) throw new Error('study not cloned correctly');
208189

209-
// 2. update the clone with our latest updates
210-
await updateStudy({
211-
studyId: clonedStudyId,
212-
study: {
213-
...getNewScrubbedStudyFromStore(),
214-
id: clonedStudyId,
215-
},
216-
});
217-
218190
const updatedClone = (
219191
await API.NeurostoreServices.StudiesService.studiesIdGet(clonedStudyId, true)
220192
).data;

compose/neurosynth-frontend/src/hooks/studies/useCreateStudy.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { AxiosError, AxiosResponse } from 'axios';
2-
import { StudyReturn } from 'neurostore-typescript-sdk';
2+
import { StudyReturn, StudyRequest } from 'neurostore-typescript-sdk';
33
import { useSnackbar } from 'notistack';
44
import { useMutation, useQueryClient } from 'react-query';
55
import API from 'utils/api';
66

77
const useCreateStudy = () => {
88
const queryClient = useQueryClient();
99
const { enqueueSnackbar } = useSnackbar();
10-
return useMutation<AxiosResponse<StudyReturn>, AxiosError, string, unknown>(
11-
(studyId) =>
12-
API.NeurostoreServices.StudiesService.studiesPost(undefined, studyId, undefined),
10+
return useMutation<
11+
AxiosResponse<StudyReturn>,
12+
AxiosError,
13+
{ sourceId: string; data: StudyRequest },
14+
unknown
15+
>(
16+
({ sourceId, data }) =>
17+
API.NeurostoreServices.StudiesService.studiesPost(undefined, sourceId, data),
1318
{
1419
onSuccess: () => {
1520
queryClient.invalidateQueries('studies');

0 commit comments

Comments
 (0)