Hi everyone,
I ran into an issue with undo / redo in a custom properties panel with extension elements. I saw this thread which suggests to use commands. I also found this example which uses modeling.updateProperties to set the extension elements and has working undo / redo.
However, when I tried to use updateProperties to set the extension elements I noticed that undo / redo do not work, although the details are confusing. Unfortunately, I am not at liberty to share most of our code, so I will try to show the relevant parts and explain what is happening. Maybe someone has an idea.
Behaviour
Undo is generally working
- Create an element that has custom properties → element is created
- Press Ctrl+Z → element is removed
But with my custom properties things get weird
- Create an element that has custom properties → element is created
- Write a custom property → property is correctly set in the bpmn when downloaded
- Press Ctrl+Z → nothing happens, property is incorrectly still set in the bpmn when downloaded
- Press Ctrl+Z again → the element is removed
It seems to me as if the Write-Property-Action is correctly added to the command (event?) stack. It also is popped off the stack when undoing. But the actual writing is not undone.
Code (sort of)
As mentioned I cannot share much of our code, but this is the code I use to write the extension elements as well as the objects it uses.
Code
const modeling = useService('modeling');
console.log(JSON.stringify(element))
console.log(JSON.stringify(extensionElements))
return modeling.updateProperties(element, {extensionElements});
element
{
"labels":[
],
"children":[
],
"id":"Activity_0s9re6u",
"width":105,
"height":55,
"name":"test",
"type":"bpmn:ServiceTask",
"di":{
"$type":"bpmndi:BPMNShape",
"bounds":{
"$type":"dc:Bounds",
"x":588,
"y":183,
"width":105,
"height":55
},
"id":"Activity_0s9re6u_di"
},
"x":588,
"y":183,
"order":{
"level":5
}
}
extensionElements
{
"$type":"bpmn:ExtensionElements",
"values":[
{
"$type":"activiti:Field",
"name":"to",
"string":{
"$type":"activiti:String",
"text":"asd"
}
},
{
"$type":"activiti:Field",
"name":"from",
"string":{
"$type":"activiti:String",
"text":"writingProperty"
}
},
{
"$type":"activiti:Field",
"name":"subject",
"string":{
"$type":"activiti:String",
"text":""
}
},
{
"$type":"activiti:Field",
"name":"cc",
"string":{
"$type":"activiti:String",
"text":""
}
},
{
"$type":"activiti:Field",
"name":"bcc",
"string":{
"$type":"activiti:String",
"text":""
}
},
{
"$type":"activiti:Field",
"name":"html",
"string":{
"$type":"activiti:String",
"text":""
}
},
{
"$type":"activiti:Field",
"name":"attachmentName",
"string":{
"$type":"activiti:String",
"text":""
}
},
{
"$type":"activiti:Field",
"name":"attachmentMimeType",
"string":{
"$type":"activiti:String",
"text":"text/plain"
}
},
{
"$type":"activiti:Field",
"name":"attachmentContent",
"string":{
"$type":"activiti:String",
"text":""
}
}
]
}