diff --git a/app/spiffworkflow/messages/MessageHelpers.js b/app/spiffworkflow/messages/MessageHelpers.js index efcd9f8..79f0337 100644 --- a/app/spiffworkflow/messages/MessageHelpers.js +++ b/app/spiffworkflow/messages/MessageHelpers.js @@ -50,15 +50,39 @@ function processCorrelationProperty(correlationProperty, message) { return expressions } -export function findCorrelationKeys(element) { +export function findCorrelationProperties(element) { const root = getRoot(element); const correlationProperties = []; for (const rootElement of root.rootElements) { if (rootElement.$type === 'bpmn:CorrelationProperty') { correlationProperties.push(rootElement); } + } - return correlationProperties; + return correlationProperties +} + +export function findCorrelationKeys(element) { + const root = getRoot(element); + const correlationKeys = []; + for (const rootElement of root.rootElements) { + if (rootElement.$type === 'bpmn:Collaboration') { + const currentKeys = rootElement.correlationKeys; + for (let correlationKey in currentKeys) { + let correlationProperties = []; + const currentCorrelation = rootElement.correlationKeys[correlationKey]; + let currentProperty = {} + currentProperty.name = currentCorrelation.name; + currentProperty.refs = []; + for (let correlationProperty in currentCorrelation.correlationPropertyRef) { + console.log("findCorrelationKeys: propertyRef", correlationProperty); + currentProperty.refs.push(currentCorrelation.correlationPropertyRef[correlationProperty]); + } + correlationKeys.push(currentProperty); + } + } + } + return correlationKeys } export function findMessageModdleElements(element) { diff --git a/app/spiffworkflow/messages/propertiesPanel/CorrelationKeysArray.js b/app/spiffworkflow/messages/propertiesPanel/CorrelationKeysArray.js index 2021935..22af1c3 100644 --- a/app/spiffworkflow/messages/propertiesPanel/CorrelationKeysArray.js +++ b/app/spiffworkflow/messages/propertiesPanel/CorrelationKeysArray.js @@ -1,6 +1,6 @@ import { useService } from 'bpmn-js-properties-panel'; import { - isTextFieldEntryEdited, + isTextFieldEntryEdited, ListGroup, TextFieldEntry, } from '@bpmn-io/properties-panel'; import { without } from 'min-dash'; @@ -9,7 +9,7 @@ import { findDataObjects, findDataReferenceShapes, } from '../../DataObject/DataObjectHelpers'; -import {findCorrelationKeys} from '../MessageHelpers'; +import { findCorrelationProperties, findCorrelationKeys, getRoot } from '../MessageHelpers'; @@ -26,15 +26,17 @@ export function CorrelationKeysArray(props) { const correlationProperties = findCorrelationKeys(element.businessObject); const items = correlationProperties.map((correlationProperty, index) => { - const id = `correlation-${correlationProperty.id}`; + const id = `correlationGroup-${correlationProperty.name}`; return { id, - label: correlationProperty.id, - entries: CorrelationKeyGroup({ - id, - element, - correlationProperty, - }), + correlationProperty, + label: correlationProperty.name, + entries: correlationProperty.refs, + // entries: correlationGroup({ + // id, + // element, + // correlationProperty, + // }), autoFocusEntry: id, // remove: removeFactory({ element, correlationProperty, commandStack, elementRegistry }) }; @@ -42,19 +44,14 @@ export function CorrelationKeysArray(props) { function add(event) { event.stopPropagation(); - const newCorrelationProperty = moddle.create('bpmn:CorrelationProperty'); - const newElements = correlationProperties; - newCorrelationProperty.id = moddle.ids.nextPrefixed('CorrelationProperty_'); - newElements.push(newCorrelationProperty); - console.log('element', element); + const newCorrelationKey = moddle.create('bpmn:CorrelationKey'); + newCorrelationKey.name = moddle.ids.nextPrefixed('CorrelationKey_'); + console.log('newCorrelationKey', newCorrelationKey); commandStack.execute('element.updateModdleProperties', { element, moddleElement: element.businessObject, - properties: { - flowElements: newElements, - }, + newElements: newCorrelationKey }); - // moddle.updateModdleProperties(element, updatedBusinessObject, update); } return { items, add }; @@ -87,6 +84,21 @@ function removeFactory(props) { }; } +function correlationGroup(props) { + const { element, correlationProperty } = props; + const id = `correlation-${correlationProperty.id}`; + return { + id, + label: correlationProperty.id, + entries: CorrelationKeyGroup({ + id, + element, + correlationProperty, + }), + autoFocusEntry: id, + }; +} + function CorrelationKeyGroup(props) { const { idPrefix, correlationProperty } = props; @@ -132,13 +144,14 @@ function CorrelationKeyTextField(props) { }; const getValue = (parameter) => { - return correlationProperty.name; + return correlationProperty.refs; }; - return TextFieldEntry({ + return ListGroup({ element: parameter, + items: correlationProperty.refs, id: `${idPrefix}-textField`, - label: 'Correlation Key', + label: 'Correlation Properties', getValue, setValue, debounce, diff --git a/app/spiffworkflow/messages/propertiesPanel/MessageCorrelationsArray.js b/app/spiffworkflow/messages/propertiesPanel/MessageCorrelationsArray.js index fefbc21..3f61eaf 100644 --- a/app/spiffworkflow/messages/propertiesPanel/MessageCorrelationsArray.js +++ b/app/spiffworkflow/messages/propertiesPanel/MessageCorrelationsArray.js @@ -31,12 +31,38 @@ export function MessageCorrelationsArray(props) { }; }); - function add(event) {} + function add(event) { + event.stopPropagation(); + const newRetrievalExpression = moddle.create('bpmn:CorrelationPropertyRetrievalExpression'); + const newElements = formalExpressions; + newRetrievalExpression.messageRef = element.businessObject.messageRef; + newElements.push(newRetrievalExpression); + console.log('element', element); + commandStack.execute('element.updateModdleProperties', { + element, + moddleElement: element.businessObject, + }); + + } return { items, add } } +function MessageKeyGroup(props) { + const { idPrefix, keys } = props; + + return [ + { + id: `${idPrefix}-group`, + component: MessageCorrelationGroup, + isEdited: isTextFieldEntryEdited, + idPrefix, + formalExpression: keys + } + ] +} + function MessageCorrelationGroup(props) { const { idPrefix, formalExpression } = props; diff --git a/test/spec/MessagesSpec.js b/test/spec/MessagesSpec.js index 76ad5d6..5883fd8 100644 --- a/test/spec/MessagesSpec.js +++ b/test/spec/MessagesSpec.js @@ -1,5 +1,5 @@ import TestContainer from 'mocha-test-container-support'; -import { bootstrapPropertiesPanel, expectSelected, findEntry, findGroupEntry, findInput, findSelect, findTextarea } from './helpers'; +import { bootstrapPropertiesPanel, expectSelected, findEntry, findGroupEntry, findInput, findSelect, findTextarea, findButtonByClass, pressButton, findDivByClass } from './helpers'; import { BpmnPropertiesPanelModule, BpmnPropertiesProviderModule } from 'bpmn-js-properties-panel'; import spiffModdleExtension from '../../app/spiffworkflow/moddle/spiffworkflow.json'; import messages from '../../app/spiffworkflow/messages'; @@ -91,4 +91,35 @@ describe('Messages should work', function() { }); + it('should add a new correlation when clicked', async function() { + + // Select the second Task + const send_shape = await expectSelected('ActivitySendLetter'); + expect(send_shape, "Can't find Send Task").to.exist; + + const buttonClass = "bio-properties-panel-group-header-button bio-properties-panel-add-entry"; + let button = findButtonByClass(buttonClass, container); + pressButton(button); + + console.log(button); + + }); + + it('should add a new Correlation Key when clicked', async function() { + const divClass = "bio-properties-panel-list"; + const divs = findDivByClass(divClass, container); + + const buttonClass = "bio-properties-panel-group-header-button bio-properties-panel-add-entry"; + let button = findButtonByClass(buttonClass, container); + pressButton(button); + + // THEN - a select Data Object section should appear in the properties panel + let entry = findGroupEntry('correlation_keys', container); + expect(entry).to.exist; + + let divs2 = findDivByClass(divClass, container); + + console.log(button); + }); + }); diff --git a/test/spec/bpmn/collaboration.bpmn b/test/spec/bpmn/collaboration.bpmn index 04b8693..834da02 100644 --- a/test/spec/bpmn/collaboration.bpmn +++ b/test/spec/bpmn/collaboration.bpmn @@ -10,8 +10,6 @@ lover_name - - lover_instrument diff --git a/test/spec/helpers.js b/test/spec/helpers.js index 5b83e3a..051c73f 100644 --- a/test/spec/helpers.js +++ b/test/spec/helpers.js @@ -119,6 +119,10 @@ export function findButton(id, container) { return domQuery(`button[id='${ id }']`, container); } +export function findButtonByClass(buttonClass, container) { + return domQuery(`button[class='${ buttonClass }']`, container) +} + export function findSelect(container) { return domQuery('select', container); } @@ -131,6 +135,10 @@ export function pressButton(button) { fireEvent.click(button); } +export function findDivByClass(divClass, container) { + return domQuery(`div[class='${ divClass }']`, container) +} +