remove empty pre and post script extension xml nodes (#115)
Co-authored-by: burnettk <burnettk@users.noreply.github.com>
This commit is contained in:
parent
cfb8fb1a3f
commit
a75437462e
|
@ -1,3 +1,4 @@
|
|||
node_modules/
|
||||
public/
|
||||
.idea/
|
||||
.aider.*
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue