From 9882643912210a2d229f9b07e54dc93ce6a1bc07 Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Wed, 20 Nov 2024 14:25:42 +0100 Subject: [PATCH] prepare use of latest arena-core --- core/survey/_survey/surveyNodeDefsIndex.js | 5 +++ core/survey/survey.js | 9 ++++-- webapp/store/survey/nodeDefsIndex/reducer.js | 33 ++++++++++---------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/core/survey/_survey/surveyNodeDefsIndex.js b/core/survey/_survey/surveyNodeDefsIndex.js index a6006dd2e3..059de8e079 100644 --- a/core/survey/_survey/surveyNodeDefsIndex.js +++ b/core/survey/_survey/surveyNodeDefsIndex.js @@ -21,6 +21,11 @@ export const addNodeDefToIndex = ({ nodeDefsIndex, nodeDef }) => { return getNodeDefsIndex(surveyUpdated) } +export const updateNodeDefUuidByNameIndex = ({ nodeDefsIndex, nodeDef, nodeDefPrevious }) => { + const surveyUpdated = Surveys.updateNodeDefUuidByNameIndex(nodeDef, nodeDefPrevious)({ nodeDefsIndex }) + return getNodeDefsIndex(surveyUpdated) +} + // ==== DELETE export const deleteNodeDefIndex = ({ nodeDefsIndex, nodeDef }) => { diff --git a/core/survey/survey.js b/core/survey/survey.js index 7d3e1caf84..37dc7a2717 100644 --- a/core/survey/survey.js +++ b/core/survey/survey.js @@ -249,8 +249,13 @@ export const { assocDependencyGraph } = SurveyDependencies export const buildDependencyGraph = SurveyDependencies.buildGraph export const { buildAndAssocDependencyGraph } = SurveyDependencies -export const { addNodeDefToIndex, deleteNodeDefIndex, initNodeDefsIndex, initAndAssocNodeDefsIndex } = - SurveyNodeDefsIndex +export const { + addNodeDefToIndex, + updateNodeDefUuidByNameIndex, + deleteNodeDefIndex, + initNodeDefsIndex, + initAndAssocNodeDefsIndex, +} = SurveyNodeDefsIndex // ====== NodeDefsValidation export const { getNodeDefsValidation, assocNodeDefsValidation, getNodeDefValidation } = SurveyNodeDefsValidation diff --git a/webapp/store/survey/nodeDefsIndex/reducer.js b/webapp/store/survey/nodeDefsIndex/reducer.js index ce0ce86f7d..08b5c4f778 100644 --- a/webapp/store/survey/nodeDefsIndex/reducer.js +++ b/webapp/store/survey/nodeDefsIndex/reducer.js @@ -23,23 +23,22 @@ const actionHandlers = { [NodeDefsActions.nodeDefCreate]: (state, { nodeDef }) => Survey.addNodeDefToIndex({ nodeDefsIndex: state, nodeDef }), [NodeDefsActions.nodeDefDelete]: (state, { nodeDef }) => Survey.deleteNodeDefIndex({ nodeDefsIndex: state, nodeDef }), - [NodeDefsActions.nodeDefUpdate]: (state, { nodeDef, prevNodeDef = null }) => { - let stateUpdated = state - if (prevNodeDef) { - stateUpdated = Survey.deleteNodeDefIndex({ nodeDefsIndex: stateUpdated, nodeDef: prevNodeDef }) - } - stateUpdated = Survey.addNodeDefToIndex({ nodeDefsIndex: stateUpdated, nodeDef }) - return stateUpdated - }, - - [NodeDefsActions.nodeDefPropsUpdateCancel]: (state, { nodeDef, nodeDefOriginal, isNodeDefNew }) => { - let stateUpdated = Survey.deleteNodeDefIndex({ nodeDefsIndex: state, nodeDef }) - if (isNodeDefNew) { - return stateUpdated - } - stateUpdated = Survey.addNodeDefToIndex({ nodeDefsIndex: stateUpdated, nodeDef: nodeDefOriginal }) - return stateUpdated - }, + [NodeDefsActions.nodeDefUpdate]: (state, { nodeDef, prevNodeDef = null }) => + Survey.updateNodeDefUuidByNameIndex({ + nodeDefsIndex: state, + nodeDef, + nodeDefPrevious: prevNodeDef, + }), + + [NodeDefsActions.nodeDefPropsUpdateCancel]: (state, { nodeDef, nodeDefOriginal, isNodeDefNew }) => + isNodeDefNew + ? Survey.deleteNodeDefIndex({ nodeDefsIndex: state, nodeDef }) + : // restore node defs index using the original node def name + Survey.updateNodeDefUuidByNameIndex({ + nodeDefsIndex: state, + nodeDef: nodeDefOriginal, + nodeDefPrevious: nodeDef, + }), } export default exportReducer(actionHandlers)