Skip to content

Commit e73914c

Browse files
author
Ives van Hoorne
committed
Validate module saving compared to server
1 parent 4832886 commit e73914c

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/app/store/entities/sandboxes/actions/files.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { values } from 'lodash';
33

44
import type { Module, Directory } from 'common/types';
5+
import logError from 'app/utils/error';
56

67
import { createAPIActions, doRequest } from '../../../api/actions';
78
import moduleEntity from '../modules/entity';
@@ -391,7 +392,7 @@ const saveModuleCode = (id: string, moduleId: string) => async (
391392
dispatch(moduleActions.setCode(newModule.id, module.code));
392393

393394
try {
394-
await dispatch(
395+
const { data } = await dispatch(
395396
doRequest(
396397
SAVE_MODULE_CODE_API_ACTIONS,
397398
`sandboxes/${sandboxId}/modules/${module.shortid}`,
@@ -401,14 +402,33 @@ const saveModuleCode = (id: string, moduleId: string) => async (
401402
},
402403
),
403404
);
404-
dispatch(moduleActions.setModuleSynced(newModule.id));
405+
406+
if (data.code !== newModule.code) {
407+
dispatch(
408+
notificationActions.addNotification(
409+
'Something went wrong while saving the module, please try again.',
410+
'error',
411+
),
412+
);
413+
414+
logError(
415+
new Error(
416+
`Saving module went wrong, mismatch:\n\n${data.code}\n\nvs\n\n ${newModule.code}`,
417+
),
418+
);
419+
} else {
420+
dispatch(moduleActions.setModuleSynced(newModule.id));
421+
}
422+
return data;
405423
} catch (e) {
406424
dispatch(
407425
notificationActions.addNotification(
408426
'Could not save the module, please try again.',
409427
'error',
410428
),
411429
);
430+
e.message = `Could not save module: ${e.message}`;
431+
logError(e);
412432
}
413433
};
414434
/**
@@ -439,7 +459,7 @@ const massUpdateModules = (id: string) => async (
439459
},
440460
),
441461
);
442-
462+
// TODO validate return values from server
443463
modulesNotInSyncInSandbox.forEach(m =>
444464
dispatch(moduleActions.setModuleSynced(m.id)),
445465
);

src/app/store/entities/sandboxes/modules/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export default {
1616
id,
1717
directoryShortid,
1818
}),
19-
setCode: (id: string, code: string) => ({
19+
setCode: (id: string, code: string, isNotSynced = true) => ({
2020
type: SET_CODE,
2121
id,
2222
code,
23-
isNotSynced: true,
23+
isNotSynced,
2424
}),
2525
setModuleSynced: (id: string) => ({
2626
type: SET_MODULE_SYNCED,

0 commit comments

Comments
 (0)