Merge pull request #35 from sartography/bug/data_objects_in_pools

Data objects in pools could not be changed to reference other data objects within the same pool
This commit is contained in:
Dan Funk 2023-06-30 10:33:57 -04:00 committed by GitHub
commit 8e0f84fbeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 143 additions and 12 deletions

View File

@ -20,6 +20,7 @@ let bpmnModeler;
try {
bpmnModeler = new BpmnModeler({
container: modelerEl,
keyboard: { bindTo: document },
propertiesPanel: {
parent: panelEl,
},

View File

@ -36,6 +36,9 @@ export function findDataObject(process, id) {
}
export function findDataObjectReferences(children, dataObjectId) {
if (children == null) {
return [];
}
return children.flatMap((child) => {
if (child.$type == 'bpmn:DataObjectReference' && child.dataObjectRef.id == dataObjectId)
return [child];
@ -58,7 +61,7 @@ export function findDataObjectReferenceShapes(children, dataObjectId) {
}
export function idToHumanReadableName(id) {
const words = id.match(/[A-Za-z][a-z]*/g) || [id];
const words = id.match(/[A-Za-z][a-z]*|[0-9]+/g) || [id];
return words.map(capitalize).join(' ');
function capitalize(word) {

View File

@ -42,7 +42,10 @@ export default class DataObjectInterceptor extends CommandInterceptor {
// when the shape is deleted, but not interested in refactoring at the moment.
if (realParent != null) {
const flowElements = realParent.get('flowElements');
flowElements.push(businessObject);
const existingElement = flowElements.find(i => i.id === 1);
if (!existingElement) {
flowElements.push(businessObject);
}
}
} else if (is(businessObject, 'bpmn:DataObject')) {
// For data objects, only update the flowElements for new data objects, and set the parent so it doesn't get moved.
@ -120,12 +123,17 @@ export default class DataObjectInterceptor extends CommandInterceptor {
const { shape } = context;
if (is(shape, 'bpmn:DataObjectReference') && shape.type !== 'label') {
const dataObject = shape.businessObject.dataObjectRef;
let flowElements = shape.businessObject.$parent.get('flowElements');
let parent = shape.businessObject.$parent;
if (parent.processRef) {
// Our immediate parent may be a pool, so we need to get the process
parent = parent.processRef;
}
const flowElements = parent.get('flowElements');
collectionRemove(flowElements, shape.businessObject);
let references = findDataObjectReferences(flowElements, dataObject.id);
const references = findDataObjectReferences(flowElements, dataObject.id);
if (references.length === 0) {
let flowElements = dataObject.$parent.get('flowElements');
collectionRemove(flowElements, dataObject);
const dataFlowElements = dataObject.$parent.get('flowElements');
collectionRemove(dataFlowElements, dataObject);
}
}
});

View File

@ -31,7 +31,8 @@ export function DataObjectSelect(props) {
const setValue = value => {
const businessObject = element.businessObject;
for (const flowElem of businessObject.$parent.flowElements) {
const dataObjects = findDataObjects(businessObject.$parent)
for (const flowElem of dataObjects) {
if (flowElem.$type === 'bpmn:DataObject' && flowElem.id === value) {
commandStack.execute('element.updateModdleProperties', {
element,

View File

@ -28,7 +28,6 @@ export function SpiffExtensionLaunchButton(props) {
const { commandStack, moddle } = props;
// Listen for a response, to update the script.
eventBus.once(listenEvent, (response) => {
console.log("Calling Update!")
setExtensionValue(element, name, response.value, moddle, commandStack);
});
}

View File

@ -40,7 +40,6 @@ export function SpiffExtensionSelect(props) {
};
const setValue = (value) => {
console.log(`Set Value called with ${ value}`);
setExtensionValue(element, name, value, moddle, commandStack);
};

View File

@ -0,0 +1,66 @@
import {
BpmnPropertiesPanelModule,
BpmnPropertiesProviderModule,
} from 'bpmn-js-properties-panel';
import TestContainer from 'mocha-test-container-support';
import {
bootstrapPropertiesPanel,
changeInput,
expectSelected,
findEntry,
findSelect,
} from './helpers';
import spiffModdleExtension from '../../app/spiffworkflow/moddle/spiffworkflow.json';
import DataObject from '../../app/spiffworkflow/DataObject';
describe('Properties Panel for Data Objects', function () {
const xml = require('./bpmn/data_objects_in_pools.bpmn').default;
let container;
beforeEach(function () {
container = TestContainer.get(this);
});
beforeEach(
bootstrapPropertiesPanel(xml, {
container,
debounceInput: false,
additionalModules: [
DataObject,
BpmnPropertiesPanelModule,
BpmnPropertiesProviderModule,
],
moddleExtensions: {
spiffworkflow: spiffModdleExtension,
},
})
);
it('should allow you to select other data objects within the same participant', async function () {
// IF - a data object reference is selected
const doREF = await expectSelected('pool1Do1_REF');
expect(doREF).to.exist;
// THEN - a select Data Object section should appear in the properties panel
const entry = findEntry('selectDataObject', container);
const selector = findSelect(entry);
changeInput(selector, 'pool1Do2');
// then this data reference object now references that data object.
const { businessObject } = doREF;
expect(businessObject.get('dataObjectRef').id).to.equal('pool1Do2');
});
it('should NOT allow you to select data objects within other participants', async function () {
// IF - a data object reference is selected
const doREF = await expectSelected('pool1Do1_REF');
expect(doREF).to.exist;
// THEN - a select Data Object section should appear in the properties panel but pool2Do1 should not be an option
const entry = findEntry('selectDataObject', container);
const selector = findSelect(entry);
expect(selector.length).to.equal(2);
expect(selector[0].value === 'pool1Do2');
expect(selector[1].value === 'pool1Do1');
});
});

View File

@ -6,9 +6,6 @@ import {
import { BpmnPropertiesPanelModule, BpmnPropertiesProviderModule } from 'bpmn-js-properties-panel';
import spiffModdleExtension from '../../app/spiffworkflow/moddle/spiffworkflow.json';
import TestContainer from 'mocha-test-container-support';
import DataObjectPropertiesProvider
from '../../app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider';
import spiffworkflow from '../../app/spiffworkflow';
import DataObject from '../../app/spiffworkflow/DataObject';
describe('Properties Panel for Data Objects', function() {
@ -78,4 +75,17 @@ describe('Properties Panel for Data Objects', function() {
expect(my_data_ref_1.businessObject.name).to.equal('My Nifty New Name');
});
it('renaming a data object creates a lable without losing the numbers', async function() {
// IF - a process is selected, and the name of a data object is changed.
let entry = findEntry('ProcessTest-dataObj-2-id', container);
let textInput = findInput('text', entry);
changeInput(textInput, 'MyObject1');
let my_data_ref_1 = await expectSelected('my_data_ref_1');
// THEN - both the data object itself, and the label of any references are updated.
expect(my_data_ref_1.businessObject.dataObjectRef.id).to.equal('MyObject1');
expect(my_data_ref_1.businessObject.name).to.equal('My Object 1');
});
});

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_19o7vxg" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.0.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.17.0">
<bpmn:collaboration id="Collaboration_0jmlu5k">
<bpmn:participant id="Participant_11j98s8" processRef="ProcessTest" />
<bpmn:participant id="Participant_1d4d2vr" processRef="Process_1y9rx5q" />
</bpmn:collaboration>
<bpmn:process id="ProcessTest" name="Process Test" isExecutable="true">
<bpmn:dataObjectReference id="pool1Do2_REF" name="Pool 1 Do 2" dataObjectRef="pool1Do2" />
<bpmn:dataObject id="pool1Do2" />
<bpmn:dataObject id="pool1Do1" />
<bpmn:dataObjectReference id="pool1Do2_REF" name="Pool 1 Do 2" dataObjectRef="pool1Do2" />
<bpmn:dataObjectReference id="pool1Do1_REF" name="Pool 1 Do 1" dataObjectRef="pool1Do1" />
</bpmn:process>
<bpmn:process id="Process_1y9rx5q">
<bpmn:dataObject id="Pool2do" />
<bpmn:dataObjectReference id="pool2Do2" name="Pool 2 Do" dataObjectRef="Pool2do" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0jmlu5k">
<bpmndi:BPMNShape id="Participant_11j98s8_di" bpmnElement="Participant_11j98s8" isHorizontal="true">
<dc:Bounds x="290" y="270" width="300" height="140" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="pool1Do2_REF_di" bpmnElement="pool1Do2_REF">
<dc:Bounds x="462" y="295" width="36" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="453" y="352" width="58" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="pool1Do1_REF_di" bpmnElement="pool1Do1_REF">
<dc:Bounds x="372" y="295" width="36" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="365" y="352" width="58" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Participant_1d4d2vr_di" bpmnElement="Participant_1d4d2vr" isHorizontal="true">
<dc:Bounds x="290" y="430" width="390" height="130" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="DataObjectReference_18xfjvh_di" bpmnElement="DataObjectReference_18xfjvh">
<dc:Bounds x="372" y="465" width="36" height="50" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>