Skip to content

Commit

Permalink
Fix/switch study (#697)
Browse files Browse the repository at this point in the history
* use info true and flat false when getting a basestudy

* remove the put and pass data through request
  • Loading branch information
jdkent authored Feb 2, 2024
1 parent e218e11 commit 8465093
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Box } from '@mui/material';
import LoadingButton from 'components/Buttons/LoadingButton/LoadingButton';
import {
AnalysisReturn,
ConditionRequest,
PointRequest,
StudyRequest,
} from 'neurostore-typescript-sdk';
import { AnalysisReturn, StudyRequest } from 'neurostore-typescript-sdk';
import { useSnackbar } from 'notistack';
import {
useProjectExtractionAnnotationId,
Expand All @@ -19,7 +14,6 @@ import {
useCreateStudy,
useGetStudysetById,
useUpdateAnnotationById,
useUpdateStudy,
useUpdateStudyset,
} from 'hooks';
import EditStudyPageStyles from 'pages/Studies/EditStudyPage/EditStudyPage.styles';
Expand Down Expand Up @@ -77,7 +71,6 @@ const EditStudySaveButton: React.FC = React.memo((props) => {
const { data: studyset } = useGetStudysetById(studysetId || undefined, false);
const { mutateAsync: updateStudyset } = useUpdateStudyset();
const { mutateAsync: createStudy } = useCreateStudy();
const { mutateAsync: updateStudy } = useUpdateStudy();
const { mutateAsync: updateAnnotation } = useUpdateAnnotationById(annotationId);

const [isCloning, setIsCloning] = useState(false);
Expand Down Expand Up @@ -163,21 +156,7 @@ const EditStudySaveButton: React.FC = React.memo((props) => {
publication: storeStudy.publication,
authors: storeStudy.authors,
year: storeStudy.year,
analyses: storeAnalysesToStudyAnalyses(storeStudy.analyses).map((analysis) => {
const scrubbedAnalysis = { ...analysis };
((scrubbedAnalysis.points || []) as PointRequest[]).forEach((point) => {
delete point.id;
delete point.analysis;
});
((scrubbedAnalysis.conditions || []) as ConditionRequest[]).forEach((condition) => {
delete condition.id;
});

delete scrubbedAnalysis.id;
delete scrubbedAnalysis.study;

return scrubbedAnalysis;
}),
analyses: storeAnalysesToStudyAnalyses(storeStudy.analyses),
};

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

// 1. clone the study
const clonedStudy = (await createStudy(storeStudy.id)).data;
const clonedStudy = (
await createStudy({ sourceId: storeStudy.id, data: getNewScrubbedStudyFromStore() })
).data;
const clonedStudyId = clonedStudy.id;
if (!clonedStudyId) throw new Error('study not cloned correctly');

// 2. update the clone with our latest updates
await updateStudy({
studyId: clonedStudyId,
study: {
...getNewScrubbedStudyFromStore(),
id: clonedStudyId,
},
});

const updatedClone = (
await API.NeurostoreServices.StudiesService.studiesIdGet(clonedStudyId, true)
).data;
Expand Down
13 changes: 9 additions & 4 deletions compose/neurosynth-frontend/src/hooks/studies/useCreateStudy.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { AxiosError, AxiosResponse } from 'axios';
import { StudyReturn } from 'neurostore-typescript-sdk';
import { StudyReturn, StudyRequest } from 'neurostore-typescript-sdk';
import { useSnackbar } from 'notistack';
import { useMutation, useQueryClient } from 'react-query';
import API from 'utils/api';

const useCreateStudy = () => {
const queryClient = useQueryClient();
const { enqueueSnackbar } = useSnackbar();
return useMutation<AxiosResponse<StudyReturn>, AxiosError, string, unknown>(
(studyId) =>
API.NeurostoreServices.StudiesService.studiesPost(undefined, studyId, undefined),
return useMutation<
AxiosResponse<StudyReturn>,
AxiosError,
{ sourceId: string; data: StudyRequest },
unknown
>(
({ sourceId, data }) =>
API.NeurostoreServices.StudiesService.studiesPost(undefined, sourceId, data),
{
onSuccess: () => {
queryClient.invalidateQueries('studies');
Expand Down

0 comments on commit 8465093

Please sign in to comment.