From a75437462e1d5282e87368f8865fd489f32a2792 Mon Sep 17 00:00:00 2001 From: Kevin Burnett <18027+burnettk@users.noreply.github.com> Date: Thu, 1 Aug 2024 18:19:16 +0000 Subject: [PATCH] remove empty pre and post script extension xml nodes (#115) Co-authored-by: burnettk --- .gitignore | 1 + .../propertiesPanel/SpiffScriptGroup.js | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6d8e019..63bd5cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ public/ .idea/ +.aider.* diff --git a/app/spiffworkflow/extensions/propertiesPanel/SpiffScriptGroup.js b/app/spiffworkflow/extensions/propertiesPanel/SpiffScriptGroup.js index a1c19f9..2d68a3d 100644 --- a/app/spiffworkflow/extensions/propertiesPanel/SpiffScriptGroup.js +++ b/app/spiffworkflow/extensions/propertiesPanel/SpiffScriptGroup.js @@ -95,6 +95,7 @@ function getScriptObject(element, scriptType) { if (!bizObj.extensionElements) { return null; } + return bizObj.extensionElements .get('values') .filter(function getInstanceOfType(e) { @@ -102,9 +103,35 @@ function getScriptObject(element, scriptType) { })[0]; } -export function updateScript(commandStack, moddle, element, scriptType, newValue) { +export function updateScript( + commandStack, + moddle, + element, + scriptType, + newValue +) { const { businessObject } = element; let scriptObj = getScriptObject(element, scriptType); + // If the pre or post script (when not SCRIPT_TYPE.bpmn) value is empty, remove the corresponding extension element rather than leaving an empty node + if (!newValue && scriptObj && scriptType !== SCRIPT_TYPE.bpmn) { + let { extensionElements } = businessObject; + if (!extensionElements) { + extensionElements = moddle.create('bpmn:ExtensionElements'); + } + if (extensionElements && extensionElements.get) { + const values = extensionElements + .get('values') + .filter((e) => e !== scriptObj); + extensionElements.values = values; + businessObject.extensionElements = extensionElements; + commandStack.execute('element.updateModdleProperties', { + element, + moddleElement: businessObject, + properties: {}, + }); + return; + } + } // Create the script object if needed. if (!scriptObj) { scriptObj = moddle.create(scriptType);