@@ -25,8 +25,12 @@ import { base_url, URLS } from '../../routes/constants';
25
25
import { resetCurrentSnapshot , setCurrentSnapshot , setForceCreateProject } from '../../projects/redux/actions' ;
26
26
import { selectFirstMolGroup } from '../../preview/moleculeGroups/redux/dispatchActions' ;
27
27
import { reloadDatasetsReducer } from '../../datasets/redux/actions' ;
28
- import { saveCurrentActionsList } from '../../../reducers/tracking/dispatchActions' ;
29
- import { sendTrackingActionsByProjectId , manageSendTrackingActions } from '../../../reducers/tracking/dispatchActions' ;
28
+ import {
29
+ saveCurrentActionsList ,
30
+ addCurrentActionsListToSnapshot ,
31
+ sendTrackingActionsByProjectId ,
32
+ manageSendTrackingActions
33
+ } from '../../../reducers/tracking/dispatchActions' ;
30
34
import { captureScreenOfSnapshot } from '../../userFeedback/browserApi' ;
31
35
32
36
export const getListOfSnapshots = ( ) => ( dispatch , getState ) => {
@@ -179,71 +183,95 @@ export const createInitSnapshotFromCopy = ({
179
183
return Promise . reject ( 'ProjectID is missing' ) ;
180
184
} ;
181
185
182
- export const createNewSnapshot = ( { title, description, type, author, parent, session_project, nglViewList } ) => (
183
- dispatch ,
184
- getState
185
- ) => {
186
+ export const createNewSnapshot = ( {
187
+ title,
188
+ description,
189
+ type,
190
+ author,
191
+ parent,
192
+ session_project,
193
+ nglViewList,
194
+ overwriteSnapshot
195
+ } ) => ( dispatch , getState ) => {
186
196
const state = getState ( ) ;
187
197
const selectedSnapshotToSwitch = state . snapshotReducers . selectedSnapshotToSwitch ;
188
198
const disableRedirect = state . snapshotReducers . disableRedirect ;
199
+ const currentSnapshot = state . projectReducers . currentSnapshot ;
200
+ const currentSnapshotId = currentSnapshot && currentSnapshot . id ;
189
201
190
202
if ( ! session_project ) {
191
203
return Promise . reject ( 'Project ID is missing!' ) ;
192
204
}
193
205
194
- let newType = type ;
195
-
196
- return Promise . all ( [
197
- dispatch ( setIsLoadingSnapshotDialog ( true ) ) ,
198
- api ( { url : `${ base_url } /api/snapshots/?session_project=${ session_project } &type=INIT` } ) . then ( response => {
199
- if ( response . data . count === 0 ) {
200
- newType = SnapshotType . INIT ;
206
+ if ( overwriteSnapshot === true && currentSnapshotId ) {
207
+ dispatch ( setIsLoadingSnapshotDialog ( true ) ) ;
208
+ let project = { projectID : session_project , authorID : author } ;
209
+
210
+ return Promise . resolve ( dispatch ( addCurrentActionsListToSnapshot ( currentSnapshot , project , nglViewList ) ) ) . then (
211
+ ( ) => {
212
+ if ( disableRedirect === false && selectedSnapshotToSwitch != null ) {
213
+ window . location . replace ( `${ URLS . projects } ${ session_project } /${ selectedSnapshotToSwitch } ` ) ;
214
+ } else {
215
+ dispatch ( setIsLoadingSnapshotDialog ( false ) ) ;
216
+ dispatch ( setOpenSnapshotSavingDialog ( false ) ) ;
217
+ }
201
218
}
219
+ ) ;
220
+ } else {
221
+ let newType = type ;
202
222
203
- return api ( {
204
- url : `${ base_url } /api/snapshots/` ,
205
- data : {
206
- title,
207
- description,
208
- type : newType ,
209
- author,
210
- parent,
211
- session_project,
212
- data : '[]' ,
213
- children : [ ]
214
- } ,
215
- method : METHOD . POST
216
- } ) . then ( res => {
217
- // redirect to project with newest created snapshot /:projectID/:snapshotID
218
- if ( res . data . id && session_project ) {
219
- let snapshot = { id : res . data . id , title : title } ;
220
- let project = { projectID : session_project , authorID : author } ;
221
-
222
- Promise . resolve ( dispatch ( saveCurrentActionsList ( snapshot , project , nglViewList ) ) ) . then ( ( ) => {
223
- if ( disableRedirect === false ) {
224
- // Really bad usage or redirection. Hint for everybody in this line ignore it, but in other parts of code
225
- // use react-router !
226
- window . location . replace (
227
- `${ URLS . projects } ${ session_project } /${
228
- selectedSnapshotToSwitch === null ? res . data . id : selectedSnapshotToSwitch
229
- } `
230
- ) ;
231
- } else {
232
- dispatch ( setOpenSnapshotSavingDialog ( false ) ) ;
233
- dispatch ( setIsLoadingSnapshotDialog ( false ) ) ;
234
- dispatch (
235
- setSharedSnapshot ( {
236
- title,
237
- description,
238
- url : `${ base_url } ${ URLS . projects } ${ session_project } /${ res . data . id } `
239
- } )
240
- ) ;
241
- }
242
- } ) ;
223
+ return Promise . all ( [
224
+ dispatch ( setIsLoadingSnapshotDialog ( true ) ) ,
225
+ api ( { url : `${ base_url } /api/snapshots/?session_project=${ session_project } &type=INIT` } ) . then ( response => {
226
+ if ( response . data . count === 0 ) {
227
+ newType = SnapshotType . INIT ;
243
228
}
244
- } ) ;
245
- } )
246
- ] ) ;
229
+
230
+ return api ( {
231
+ url : `${ base_url } /api/snapshots/` ,
232
+ data : {
233
+ title,
234
+ description,
235
+ type : newType ,
236
+ author,
237
+ parent,
238
+ session_project,
239
+ data : '[]' ,
240
+ children : [ ]
241
+ } ,
242
+ method : METHOD . POST
243
+ } ) . then ( res => {
244
+ // redirect to project with newest created snapshot /:projectID/:snapshotID
245
+ if ( res . data . id && session_project ) {
246
+ let snapshot = { id : res . data . id , title : title } ;
247
+ let project = { projectID : session_project , authorID : author } ;
248
+
249
+ Promise . resolve ( dispatch ( saveCurrentActionsList ( snapshot , project , nglViewList ) ) ) . then ( ( ) => {
250
+ if ( disableRedirect === false ) {
251
+ // Really bad usage or redirection. Hint for everybody in this line ignore it, but in other parts of code
252
+ // use react-router !
253
+ window . location . replace (
254
+ `${ URLS . projects } ${ session_project } /${
255
+ selectedSnapshotToSwitch === null ? res . data . id : selectedSnapshotToSwitch
256
+ } `
257
+ ) ;
258
+ } else {
259
+ dispatch ( setOpenSnapshotSavingDialog ( false ) ) ;
260
+ dispatch ( setIsLoadingSnapshotDialog ( false ) ) ;
261
+ dispatch (
262
+ setSharedSnapshot ( {
263
+ title,
264
+ description,
265
+ url : `${ base_url } ${ URLS . projects } ${ session_project } /${ res . data . id } `
266
+ } )
267
+ ) ;
268
+ }
269
+ } ) ;
270
+ }
271
+ } ) ;
272
+ } )
273
+ ] ) ;
274
+ }
247
275
} ;
248
276
249
277
export const activateSnapshotDialog = ( loggedInUserID = undefined , finallyShareSnapshot = false ) => (
@@ -329,7 +357,7 @@ export const createNewSnapshotWithoutStateModification = ({
329
357
330
358
let snapshot = { id : res . data . id , title : title } ;
331
359
let project = { projectID : session_project , authorID : author } ;
332
- dispatch ( saveCurrentActionsList ( snapshot , project , nglViewList ) ) ;
360
+ dispatch ( saveCurrentActionsList ( snapshot , project , nglViewList , true ) ) ;
333
361
}
334
362
} ) ;
335
363
} ) ;
0 commit comments