11import { Box } from '@mui/material' ;
22import 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' ;
94import { useSnackbar } from 'notistack' ;
105import {
116 useProjectExtractionAnnotationId ,
@@ -19,7 +14,6 @@ import {
1914 useCreateStudy ,
2015 useGetStudysetById ,
2116 useUpdateAnnotationById ,
22- useUpdateStudy ,
2317 useUpdateStudyset ,
2418} from 'hooks' ;
2519import 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 ;
0 commit comments