From 24397b2451a63f7cf265cd4de9e52073feab0b1b Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Thu, 6 Jun 2019 17:10:11 +0530 Subject: [PATCH 1/2] Handling the situation where we have multiple questions, which have same field name. in the template. This might be needed for situation where we specify different texts and options for the same field based on some other conditions. In such cases, it is removing the value of the field if any one of such questions is hidden by conditions which is normal use case in case of multiple questions having same field name situations. After this fix it does not remove the field value from the project, if any one of the questions is visible by its conditions. --- src/helpers/wizardHelper.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/helpers/wizardHelper.js b/src/helpers/wizardHelper.js index 8f2ebd86d..0478d7d14 100644 --- a/src/helpers/wizardHelper.js +++ b/src/helpers/wizardHelper.js @@ -1004,13 +1004,32 @@ export const updateNodesByConditions = (template, project, productTemplates) => export const removeValuesOfHiddenNodes = (template, project) => { let updatedProject = project + const fieldMap = {} + // iterates over all nodes to find out nodes with same fieldName + forEachNode(template, (nodeObject, node) => { + if (nodeObject.fieldName ) { + if (!fieldMap[nodeObject.fieldName]) { + fieldMap[nodeObject.fieldName] = [] + } + fieldMap[nodeObject.fieldName].push(nodeObject) + } + }) + forEachNode(template, (nodeObject, node) => { const level = getNodeLevel(node) + let hasVisbleNodeWithSameCond = false + if (nodeObject.fieldName) { + fieldMap[nodeObject.fieldName].forEach((no) => { + if (!_.get(no, '__wizard.hiddenByCondition')) { + hasVisbleNodeWithSameCond = true + } + }) + } switch(level) { // if some question is hidden, we remove it's value from the project data case LEVEL.QUESTION: - if (_.get(nodeObject, '__wizard.hiddenByCondition') && _.get(updatedProject, nodeObject.fieldName)) { + if (_.get(nodeObject, '__wizard.hiddenByCondition') && !hasVisbleNodeWithSameCond && _.get(updatedProject, nodeObject.fieldName)) { updatedProject = update(updatedProject, unflatten({ [nodeObject.fieldName]: { $set: undefined } })) From c0f7fde90afc4ca375778b0503d8d67ade6417b8 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Thu, 6 Jun 2019 17:35:42 +0530 Subject: [PATCH 2/2] Lint fix --- src/helpers/wizardHelper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/wizardHelper.js b/src/helpers/wizardHelper.js index 0478d7d14..d33dbc52f 100644 --- a/src/helpers/wizardHelper.js +++ b/src/helpers/wizardHelper.js @@ -1006,7 +1006,7 @@ export const removeValuesOfHiddenNodes = (template, project) => { const fieldMap = {} // iterates over all nodes to find out nodes with same fieldName - forEachNode(template, (nodeObject, node) => { + forEachNode(template, (nodeObject, node) => { // eslint-disable-line no-unused-vars if (nodeObject.fieldName ) { if (!fieldMap[nodeObject.fieldName]) { fieldMap[nodeObject.fieldName] = []