From 5cfe31a763a9d1606195626fbbc75f7aa45c2f3f Mon Sep 17 00:00:00 2001 From: Jerin George Date: Mon, 2 Dec 2024 11:47:47 +0530 Subject: [PATCH 1/4] #2248 After table row is deleted, propertyListener callback has same previousValue and value-fixing Signed-off-by: Jerin George --- .../src/common-properties/properties-controller.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/canvas_modules/common-canvas/src/common-properties/properties-controller.js b/canvas_modules/common-canvas/src/common-properties/properties-controller.js index 48e8e35f01..03c3abe09b 100644 --- a/canvas_modules/common-canvas/src/common-properties/properties-controller.js +++ b/canvas_modules/common-canvas/src/common-properties/properties-controller.js @@ -542,8 +542,8 @@ export default class PropertiesController { } else if (subControl.valueDef.propType === "enum") { val = subControl.values[0]; } else if (subControl.valueDef.propType === "integer" || - subControl.valueDef.propType === "long" || - subControl.valueDef.propType === "double") { + subControl.valueDef.propType === "long" || + subControl.valueDef.propType === "double") { val = 0; } else if (subControl.valueDef.propType === "structure") { val = {}; @@ -1115,6 +1115,8 @@ export default class PropertiesController { getPropertyValue(inPropertyId, options, defaultValue) { const propertyId = this.convertPropertyId(inPropertyId); const propertyValue = this.propertiesStore.getPropertyValue(propertyId); + // Parsing propertyValue + const parsedValue = propertyValue ? JSON.parse(JSON.stringify(propertyValue)) : propertyValue; let filteredValue = defaultValue; // don't return hidden/disabled values @@ -1166,7 +1168,7 @@ export default class PropertiesController { if (options && options.applyProperties === true) { return this._convertObjectStructure(propertyId, propertyValue); } - return propertyValue; + return parsedValue; } removePropertyValue(inPropertyId) { @@ -1279,7 +1281,7 @@ export default class PropertiesController { const control = this.getControl({ name: parameterRef }); if (PropertyUtils.isSubControlStructureObjectType(control)) { conditionalDefaultValues[parameterRef] = - PropertyUtils.convertObjectStructureToArray(control.valueDef.isList, control.subControls, conditionalDefaultValues[parameterRef]); + PropertyUtils.convertObjectStructureToArray(control.valueDef.isList, control.subControls, conditionalDefaultValues[parameterRef]); } this.propertiesStore.updatePropertyValue({ name: parameterRef }, conditionalDefaultValues[parameterRef]); } @@ -2045,7 +2047,7 @@ export default class PropertiesController { }); const isDifference = consecutiveAry.every((value) => value === 1); if (isDifference && ((staticRows.includes(0) && !staticRows.includes(controlValue.length - 1)) || - (!staticRows.includes(0) && staticRows.includes(controlValue.length - 1)))) { + (!staticRows.includes(0) && staticRows.includes(controlValue.length - 1)))) { isValid = true; } else { isValid = false; From 8f2d1760c425c9d5028729fa0a832766fec58278 Mon Sep 17 00:00:00 2001 From: Jerin George Date: Mon, 2 Dec 2024 12:52:30 +0530 Subject: [PATCH 2/4] #2248 After table row is deleted, propertyListener callback has same previousValue and value-fixing-final Signed-off-by: Jerin George --- .../src/common-properties/properties-controller.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/canvas_modules/common-canvas/src/common-properties/properties-controller.js b/canvas_modules/common-canvas/src/common-properties/properties-controller.js index 03c3abe09b..d29b031113 100644 --- a/canvas_modules/common-canvas/src/common-properties/properties-controller.js +++ b/canvas_modules/common-canvas/src/common-properties/properties-controller.js @@ -1099,6 +1099,7 @@ export default class PropertiesController { if (typeof type !== "undefined") { data.type = type; } + console.log(data); this.handlers.propertyListener(data); } } @@ -1116,7 +1117,16 @@ export default class PropertiesController { const propertyId = this.convertPropertyId(inPropertyId); const propertyValue = this.propertiesStore.getPropertyValue(propertyId); // Parsing propertyValue - const parsedValue = propertyValue ? JSON.parse(JSON.stringify(propertyValue)) : propertyValue; + let parsedValue; + if (Array.isArray(propertyValue)) { + // Use map to preserve sparse arrays and maintain structure + parsedValue = propertyValue.map((itm) => itm); + } else if (propertyValue && typeof propertyValue === "object") { + // Shallow copy for objects + parsedValue = { ...propertyValue }; + } else { + parsedValue = typeof propertyValue !== "undefined" ? propertyValue : defaultValue; + } let filteredValue = defaultValue; // don't return hidden/disabled values From cecf88211192acbc4e53c7fffcaae6d65231fcab Mon Sep 17 00:00:00 2001 From: Jerin George Date: Mon, 2 Dec 2024 13:11:15 +0530 Subject: [PATCH 3/4] #2248 After table row is deleted, propertyListener callback has same previousValue and value-fixing-unit tests Signed-off-by: Jerin George --- .../src/common-properties/properties-controller.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/canvas_modules/common-canvas/src/common-properties/properties-controller.js b/canvas_modules/common-canvas/src/common-properties/properties-controller.js index d29b031113..e9090f77cb 100644 --- a/canvas_modules/common-canvas/src/common-properties/properties-controller.js +++ b/canvas_modules/common-canvas/src/common-properties/properties-controller.js @@ -1116,16 +1116,14 @@ export default class PropertiesController { getPropertyValue(inPropertyId, options, defaultValue) { const propertyId = this.convertPropertyId(inPropertyId); const propertyValue = this.propertiesStore.getPropertyValue(propertyId); - // Parsing propertyValue let parsedValue; if (Array.isArray(propertyValue)) { - // Use map to preserve sparse arrays and maintain structure parsedValue = propertyValue.map((itm) => itm); } else if (propertyValue && typeof propertyValue === "object") { // Shallow copy for objects parsedValue = { ...propertyValue }; } else { - parsedValue = typeof propertyValue !== "undefined" ? propertyValue : defaultValue; + parsedValue = propertyValue; } let filteredValue = defaultValue; From ca2f10d1f5d9b2994a5df7b1723a0a528bee60c6 Mon Sep 17 00:00:00 2001 From: Jerin George Date: Tue, 3 Dec 2024 07:20:45 +0530 Subject: [PATCH 4/4] #2248 After table row is deleted, propertyListener callback has same previousValue and value-fixing-removing log statement Signed-off-by: Jerin George --- .../common-canvas/src/common-properties/properties-controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/canvas_modules/common-canvas/src/common-properties/properties-controller.js b/canvas_modules/common-canvas/src/common-properties/properties-controller.js index e9090f77cb..e4623fe3c0 100644 --- a/canvas_modules/common-canvas/src/common-properties/properties-controller.js +++ b/canvas_modules/common-canvas/src/common-properties/properties-controller.js @@ -1099,7 +1099,6 @@ export default class PropertiesController { if (typeof type !== "undefined") { data.type = type; } - console.log(data); this.handlers.propertyListener(data); } }