Skip to content

Commit

Permalink
prepare use of latest arena-core
Browse files Browse the repository at this point in the history
  • Loading branch information
SteRiccio committed Nov 20, 2024
1 parent b6be3e1 commit 9882643
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
5 changes: 5 additions & 0 deletions core/survey/_survey/surveyNodeDefsIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
9 changes: 7 additions & 2 deletions core/survey/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 16 additions & 17 deletions webapp/store/survey/nodeDefsIndex/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 9882643

Please sign in to comment.