From 845c3edc4c7c198a2beac961ff23c911451df202 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Fri, 1 Dec 2023 13:46:43 +0100 Subject: [PATCH 01/20] INNIT --- .../propertiesPanel/DataObjectArray.js | 38 +++++++++ .../DataObjectPropertiesProvider.js | 80 ++++++++++++++++++- 2 files changed, 114 insertions(+), 4 deletions(-) diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js index 70e5f41..614f3f8 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js @@ -102,6 +102,13 @@ function DataObjectGroup(props) { idPrefix, dataObject, }, + { + id: `${idPrefix}-dataObjectName`, + component: DataObjectNameTextField, + isEdited: isTextFieldEntryEdited, + idPrefix, + dataObject, + } ]; } @@ -147,3 +154,34 @@ function DataObjectTextField(props) { debounce, }); } + + +function DataObjectNameTextField(props) { + const { idPrefix, element, parameter, dataObject } = props; + + const commandStack = useService('commandStack'); + const debounce = useService('debounceInput'); + + const setValue = (value) => { + commandStack.execute('element.updateModdleProperties', { + element, + moddleElement: dataObject, + properties: { + name: value, + }, + }); + }; + + const getValue = () => { + return dataObject.name; + }; + + return TextFieldEntry({ + element: parameter, + id: `${idPrefix}-name`, + label: 'Data Object Name', + getValue, + setValue, + debounce, + }); +} \ No newline at end of file diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js index 6af1426..afa09ce 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js @@ -1,7 +1,8 @@ import { is, isAny } from 'bpmn-js/lib/util/ModelUtil'; -import { ListGroup, isTextFieldEntryEdited } from '@bpmn-io/properties-panel'; +import { ListGroup, isTextFieldEntryEdited, TextFieldEntry } from '@bpmn-io/properties-panel'; import { DataObjectSelect } from './DataObjectSelect'; import { DataObjectArray } from './DataObjectArray'; +import { useService } from 'bpmn-js-properties-panel'; const LOW_PRIORITY = 500; @@ -10,13 +11,15 @@ export default function DataObjectPropertiesProvider( translate, moddle, commandStack, - elementRegistry + elementRegistry, + modeling, + bpmnFactory ) { this.getGroups = function (element) { return function (groups) { if (is(element, 'bpmn:DataObjectReference')) { groups.push( - createDataObjectSelector(element, translate, moddle, commandStack) + createDataObjectSelector(element, translate, moddle, commandStack, modeling, bpmnFactory) ); } if ( @@ -45,6 +48,8 @@ DataObjectPropertiesProvider.$inject = [ 'moddle', 'commandStack', 'elementRegistry', + 'modeling', + 'bpmnFactory' ]; /** @@ -54,7 +59,7 @@ DataObjectPropertiesProvider.$inject = [ * @param moddle * @returns entries */ -function createDataObjectSelector(element, translate, moddle, commandStack) { +function createDataObjectSelector(element, translate, moddle, commandStack, modeling, bpmnFactory) { return { id: 'data_object_properties', label: translate('Data Object Properties'), @@ -67,6 +72,15 @@ function createDataObjectSelector(element, translate, moddle, commandStack) { moddle, commandStack, }, + { + id: 'selectDataState', + element, + component: createDataStateTextField, + moddle, + commandStack, + modeling, + bpmnFactory + } ], }; } @@ -98,3 +112,61 @@ function createDataObjectEditor( return dataObjectArray; } } + +function createDataStateTextField(props) { + const { id, element, commandStack, modeling, bpmnFactory } = props; + + const debounce = useService('debounceInput'); + + const setValue = (value) => { + const businessObject = element.businessObject; + + // Check if the element is a DataObjectReference + if (!is(businessObject, 'bpmn:DataObjectReference')) { + console.error('The element is not a DataObjectReference.'); + return; + } + + // Create a new DataState or update the existing one + let dataState = businessObject.dataState; + if (!dataState) { + dataState = bpmnFactory.create('bpmn:DataState', { + id: 'DataState_' + businessObject.id, + name: value + }); + } else { + dataState.name = value; + } + + // Update the DataObjectReference with new or updated DataState + modeling.updateProperties(element, { + dataState: dataState + }); + + // Extract the original name + const originalName = businessObject.name.split(' [')[0]; + + // Update the label of the DataObjectReference + const newName = (value) ? originalName + ' [' + value + ']' : originalName; + + modeling.updateProperties(element, { + name: newName + }); + }; + + const getValue = () => { + const businessObject = element.businessObject; + return businessObject.dataState ? businessObject.dataState.name : ''; + }; + + return TextFieldEntry({ + element, + id: `${id}-textField`, + name: 'spiffworkflow:DataStateLabel', + label: 'Which Data State does this reference?', + description: 'Select the Data State this represents.', + getValue, + setValue, + debounce, + }); +} \ No newline at end of file From ee68f07f23b81b8529ed1d49a1146b6317c1db20 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Fri, 1 Dec 2023 14:07:15 +0100 Subject: [PATCH 02/20] Update reference name on change dataObj Name --- .../propertiesPanel/DataObjectArray.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js index 614f3f8..9a07bf9 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js @@ -126,19 +126,6 @@ function DataObjectTextField(props) { id: value, }, }); - - // Also update the label of all the references - const references = findDataObjectReferenceShapes(element.children, dataObject.id); - for (const ref of references) { - commandStack.execute('element.updateProperties', { - element: ref, - moddleElement: ref.businessObject, - properties: { - name: idToHumanReadableName(value), - }, - changed: [ref], // everything is already marked as changed, don't recalculate. - }); - } }; const getValue = () => { @@ -163,6 +150,21 @@ function DataObjectNameTextField(props) { const debounce = useService('debounceInput'); const setValue = (value) => { + + // Update references name + const references = findDataObjectReferenceShapes(element.children, dataObject.id); + for (const ref of references) { + commandStack.execute('element.updateProperties', { + element: ref, + moddleElement: ref.businessObject, + properties: { + name: idToHumanReadableName(value), + }, + changed: [ref], + }); + } + + // Update dataObject name commandStack.execute('element.updateModdleProperties', { element, moddleElement: dataObject, From e35578061939a97b4ad97ae30b35d35b196abb96 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Fri, 1 Dec 2023 16:13:53 +0100 Subject: [PATCH 03/20] Remove Name Input --- .../DataObject/propertiesPanel/DataObjectArray.js | 1 - .../propertiesPanel/DataObjectPropertiesProvider.js | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js index 9a07bf9..dde6330 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js @@ -142,7 +142,6 @@ function DataObjectTextField(props) { }); } - function DataObjectNameTextField(props) { const { idPrefix, element, parameter, dataObject } = props; diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js index afa09ce..3dbdcf4 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js @@ -18,6 +18,13 @@ export default function DataObjectPropertiesProvider( this.getGroups = function (element) { return function (groups) { if (is(element, 'bpmn:DataObjectReference')) { + + // Remove Name Input from default group entries + const generalGroup = groups.find(group => group.id === 'general'); + if (generalGroup) { + generalGroup.entries = generalGroup.entries.filter(entry => entry.id !== 'name'); + } + groups.push( createDataObjectSelector(element, translate, moddle, commandStack, modeling, bpmnFactory) ); From 84d6e20ff8a874874bbf69a20e99bb3414a8f5cd Mon Sep 17 00:00:00 2001 From: theaubmov Date: Fri, 1 Dec 2023 16:51:17 +0100 Subject: [PATCH 04/20] OnChange Events --- .../DataObject/DataObjectInterceptor.js | 3 +- .../propertiesPanel/DataObjectArray.js | 6 +++- .../propertiesPanel/DataObjectSelect.js | 32 +++++++++++-------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/spiffworkflow/DataObject/DataObjectInterceptor.js b/app/spiffworkflow/DataObject/DataObjectInterceptor.js index a8eb3f7..3dd2199 100644 --- a/app/spiffworkflow/DataObject/DataObjectInterceptor.js +++ b/app/spiffworkflow/DataObject/DataObjectInterceptor.js @@ -87,6 +87,7 @@ export default class DataObjectInterceptor extends CommandInterceptor { dataObject = existingDataObjects[0]; } else { dataObject = bpmnFactory.create('bpmn:DataObject'); + dataObject.name = 'DataObject Name'; } // set the reference to the DataObject shape.businessObject.dataObjectRef = dataObject; @@ -107,7 +108,7 @@ export default class DataObjectInterceptor extends CommandInterceptor { element: shape, moddleElement: shape.businessObject, properties: { - name: idToHumanReadableName(shape.businessObject.dataObjectRef.id), + name: idToHumanReadableName(shape.businessObject.dataObjectRef.name), }, }); } diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js index dde6330..01e5c4a 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js @@ -57,6 +57,7 @@ export function DataObjectArray(props) { const newDataObject = moddle.create('bpmn:DataObject'); const newElements = process.get('flowElements'); newDataObject.id = moddle.ids.nextPrefixed('DataObject_'); + newDataObject.name = 'DataObject Name'; newDataObject.$parent = process; newElements.push(newDataObject); commandStack.execute('element.updateModdleProperties', { @@ -153,11 +154,14 @@ function DataObjectNameTextField(props) { // Update references name const references = findDataObjectReferenceShapes(element.children, dataObject.id); for (const ref of references) { + const stateName = ref.businessObject.dataState && ref.businessObject.dataState.name ? ref.businessObject.dataState.name : ''; + const newName = stateName ? `${value} [${stateName}]` : value; + commandStack.execute('element.updateProperties', { element: ref, moddleElement: ref.businessObject, properties: { - name: idToHumanReadableName(value), + name: newName, }, changed: [ref], }); diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js index 2804355..75b2fc1 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js @@ -1,6 +1,6 @@ -import {useService } from 'bpmn-js-properties-panel'; +import { useService } from 'bpmn-js-properties-panel'; import { SelectEntry } from '@bpmn-io/properties-panel'; -import {findDataObjects, idToHumanReadableName} from '../DataObjectHelpers'; +import { findDataObjects, idToHumanReadableName } from '../DataObjectHelpers'; /** * Finds the value of the given type within the extensionElements @@ -32,20 +32,26 @@ export function DataObjectSelect(props) { const setValue = value => { const businessObject = element.businessObject; const dataObjects = findDataObjects(businessObject.$parent) - for (const flowElem of dataObjects) { - if (flowElem.$type === 'bpmn:DataObject' && flowElem.id === value) { + for (const dataObject of dataObjects) { + if (dataObject.$type === 'bpmn:DataObject' && dataObject.id === value) { + commandStack.execute('element.updateModdleProperties', { - element, + element: element, moddleElement: businessObject, properties: { - dataObjectRef: flowElem + dataObjectRef: dataObject } }); + + // Construct the new name by : the dataObject name and the current state + const stateName = businessObject.dataState && businessObject.dataState.name ? businessObject.dataState.name : ''; + const newName = stateName ? `${dataObject.name} [${stateName}]` : dataObject.name; + + // Update the name property of the DataObjectReference commandStack.execute('element.updateProperties', { - element, - moddleElement: businessObject, + element: element, properties: { - 'name': idToHumanReadableName(flowElem.id) + name: newName } }); } @@ -58,7 +64,7 @@ export function DataObjectSelect(props) { let dataObjects = findDataObjects(parent); let options = []; dataObjects.forEach(dataObj => { - options.push({label: dataObj.id, value: dataObj.id}) + options.push({ label: dataObj.id, value: dataObj.id }) }); return options; } @@ -68,9 +74,9 @@ export function DataObjectSelect(props) { element={element} description={"Select the Data Object this represents."} label={"Which Data Object does this reference?"} - getValue={ getValue } - setValue={ setValue } - getOptions={ getOptions } + getValue={getValue} + setValue={setValue} + getOptions={getOptions} debounce={debounce} />; From 39d0cf61645006609b7820ac374036fa18aa041a Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 14:44:03 +0100 Subject: [PATCH 05/20] Before Implement Manual Change --- .../DataObject/DataObjectInterceptor.js | 1 + .../DataObjectPropertiesProvider.js | 51 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/app/spiffworkflow/DataObject/DataObjectInterceptor.js b/app/spiffworkflow/DataObject/DataObjectInterceptor.js index 3dd2199..af0cdc9 100644 --- a/app/spiffworkflow/DataObject/DataObjectInterceptor.js +++ b/app/spiffworkflow/DataObject/DataObjectInterceptor.js @@ -138,6 +138,7 @@ export default class DataObjectInterceptor extends CommandInterceptor { } } }); + } } diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js index 3dbdcf4..0f21f17 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js @@ -13,12 +13,58 @@ export default function DataObjectPropertiesProvider( commandStack, elementRegistry, modeling, - bpmnFactory + bpmnFactory, + eventBus ) { this.getGroups = function (element) { return function (groups) { if (is(element, 'bpmn:DataObjectReference')) { + eventBus.on('element.dblclick', 1000, function (event) { + console.log('element.dblclick', event); + // const element = event.element; + // modeling.updateLabel(element, 'newLabel'); + // // eventBus.fire('directEditing.activate', element); + // eventBus.fire('directEditing.activate', { + // element: element + // }); + }); + + eventBus.on('directEditing.activate', async function (event) { + console.log('directEditing.activate', event); + const { element, provider, context } = event.active; + // console.log('element', element); + // console.log('provider', provider); + // console.log('context', context); + // console.log('modeling', modeling); + + await modeling.updateLabel(element, 'newLabel'); + // provider.update(element, 'newLabel', context); + provider.activate(element); + }); + + eventBus.on('directEditing.complete', function (event) { + console.log('directEditing.complete', event); + }); + + // eventBus.on('directEditing.activate', function (event) { + // // Direct editing started + // console.log('directEditing.activate', event); + // event.active.context.text = 'elele' + // const element = event.active.element; + // // event.active.element.label = "jeje"; + // // event.active.element.set('label', 'jke'); + // event.active.element.name = "jeje"; + // element.businessObject.name = "jeje"; + // element.businessObject.dataObjectRef.name = "jeje"; + // const originalLabel = element.businessObject.name; + // const labelWithoutState = originalLabel.split(' [')[0]; + // // modeling.updateProperties(element, { name: labelWithoutState }); + // // storeOriginalLabel(element, originalLabel); + // }); + + + // Remove Name Input from default group entries const generalGroup = groups.find(group => group.id === 'general'); if (generalGroup) { @@ -56,7 +102,8 @@ DataObjectPropertiesProvider.$inject = [ 'commandStack', 'elementRegistry', 'modeling', - 'bpmnFactory' + 'bpmnFactory', + 'eventBus' ]; /** From ab311a29fcc6698dfadb4fd90f97869b399a2968 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 14:45:43 +0100 Subject: [PATCH 06/20] NPM RUN LINT --- app/spiffworkflow/DataObject/DataObjectInterceptor.js | 2 +- .../DataObject/propertiesPanel/DataObjectArray.js | 4 ++-- .../DataObject/propertiesPanel/DataObjectSelect.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/spiffworkflow/DataObject/DataObjectInterceptor.js b/app/spiffworkflow/DataObject/DataObjectInterceptor.js index af0cdc9..9823cad 100644 --- a/app/spiffworkflow/DataObject/DataObjectInterceptor.js +++ b/app/spiffworkflow/DataObject/DataObjectInterceptor.js @@ -138,7 +138,7 @@ export default class DataObjectInterceptor extends CommandInterceptor { } } }); - + } } diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js index 01e5c4a..5fa3e0d 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js @@ -150,13 +150,13 @@ function DataObjectNameTextField(props) { const debounce = useService('debounceInput'); const setValue = (value) => { - + // Update references name const references = findDataObjectReferenceShapes(element.children, dataObject.id); for (const ref of references) { const stateName = ref.businessObject.dataState && ref.businessObject.dataState.name ? ref.businessObject.dataState.name : ''; const newName = stateName ? `${value} [${stateName}]` : value; - + commandStack.execute('element.updateProperties', { element: ref, moddleElement: ref.businessObject, diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js index 75b2fc1..efeea7d 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js @@ -34,7 +34,7 @@ export function DataObjectSelect(props) { const dataObjects = findDataObjects(businessObject.$parent) for (const dataObject of dataObjects) { if (dataObject.$type === 'bpmn:DataObject' && dataObject.id === value) { - + commandStack.execute('element.updateModdleProperties', { element: element, moddleElement: businessObject, From f3d5a94c9973131449a9b6f8948ab45dc13e71f6 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 15:56:55 +0100 Subject: [PATCH 07/20] Add LabelEditing Provider --- .../DataObjectLabelEditingProvider.js | 65 +++++++++++++++++++ app/spiffworkflow/DataObject/index.js | 4 +- .../DataObjectPropertiesProvider.js | 47 -------------- app/spiffworkflow/index.js | 3 + 4 files changed, 71 insertions(+), 48 deletions(-) create mode 100644 app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js diff --git a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js new file mode 100644 index 0000000..c379358 --- /dev/null +++ b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js @@ -0,0 +1,65 @@ +import { is, isAny } from 'bpmn-js/lib/util/ModelUtil'; +import { ListGroup, isTextFieldEntryEdited, TextFieldEntry } from '@bpmn-io/properties-panel'; +import { useService } from 'bpmn-js-properties-panel'; + +const LOW_PRIORITY = 500; + +export default function DataObjectLabelEditingProvider(eventBus, canvas, directEditing, commandStack, modeling) { + + console.log('DataObjectLabelEditingProvider', eventBus, canvas, directEditing, commandStack, modeling, this); + + directEditing.registerProvider(LOW_PRIORITY, this); + + let el; + + // listen to dblclick on non-root elements + eventBus.on('element.dblclick', function (event) { + const { element } = event; + if (is(element.businessObject, 'bpmn:DataObjectReference')) { + let label = element.businessObject.name; + label = label.replace(/\s*\[.*?\]\s*$/, ''); + modeling.updateLabel(element, label); + directEditing.activate(element); + el = element; + console.log('IS ACTIVE', directEditing.isActive(element)) + + } + }); + + eventBus.on('directEditing.activate', async function (event) { + console.log('directEditing.activate', event); + const { element } = event.active; + if (is(element.businessObject, 'bpmn:DataObjectReference')) { + console.log('directEditing.activate bpmn:DataObjectReference', element, directEditing); + // modeling.updateLabel(element, 'newLabel'); + // directEditing.activate(element); + } + }); + + eventBus.on('directEditing.complete', function (event) { + const element = el; + if (element && is(element.businessObject, 'bpmn:DataObjectReference')) { + const dataState = element.businessObject.dataState && element.businessObject.dataState.name; + let newLabel = element.businessObject.name; + + // Append the data state if it exists + if (dataState) { + newLabel += ` [${dataState}]`; + } + + // Update the label with the data state + modeling.updateLabel(element, newLabel); + + el = undefined; + } + }); + +} + +DataObjectLabelEditingProvider.$inject = [ + 'eventBus', + 'canvas', + 'directEditing', + 'commandStack', + 'modeling' +]; \ No newline at end of file diff --git a/app/spiffworkflow/DataObject/index.js b/app/spiffworkflow/DataObject/index.js index 8489aec..703642a 100644 --- a/app/spiffworkflow/DataObject/index.js +++ b/app/spiffworkflow/DataObject/index.js @@ -3,6 +3,7 @@ import DataObjectRules from './DataObjectRules'; import RulesModule from 'diagram-js/lib/features/rules'; import DataObjectRenderer from './DataObjectRenderer'; import DataObjectPropertiesProvider from './propertiesPanel/DataObjectPropertiesProvider'; +import DataObjectLabelEditingProvider from './DataObjectLabelEditingProvider'; export default { @@ -13,7 +14,8 @@ export default { dataInterceptor: [ 'type', DataObjectInterceptor ], dataObjectRules: [ 'type', DataObjectRules ], dataObjectRenderer: [ 'type', DataObjectRenderer ], - dataObjectPropertiesProvider: [ 'type', DataObjectPropertiesProvider ] + dataObjectPropertiesProvider: [ 'type', DataObjectPropertiesProvider ], + dataObjectLabelEditingProvider: [ 'type', DataObjectLabelEditingProvider ] }; diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js index 0f21f17..0d6226c 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js @@ -19,53 +19,6 @@ export default function DataObjectPropertiesProvider( this.getGroups = function (element) { return function (groups) { if (is(element, 'bpmn:DataObjectReference')) { - - eventBus.on('element.dblclick', 1000, function (event) { - console.log('element.dblclick', event); - // const element = event.element; - // modeling.updateLabel(element, 'newLabel'); - // // eventBus.fire('directEditing.activate', element); - // eventBus.fire('directEditing.activate', { - // element: element - // }); - }); - - eventBus.on('directEditing.activate', async function (event) { - console.log('directEditing.activate', event); - const { element, provider, context } = event.active; - // console.log('element', element); - // console.log('provider', provider); - // console.log('context', context); - // console.log('modeling', modeling); - - await modeling.updateLabel(element, 'newLabel'); - // provider.update(element, 'newLabel', context); - provider.activate(element); - }); - - eventBus.on('directEditing.complete', function (event) { - console.log('directEditing.complete', event); - }); - - // eventBus.on('directEditing.activate', function (event) { - // // Direct editing started - // console.log('directEditing.activate', event); - // event.active.context.text = 'elele' - // const element = event.active.element; - // // event.active.element.label = "jeje"; - // // event.active.element.set('label', 'jke'); - // event.active.element.name = "jeje"; - // element.businessObject.name = "jeje"; - // element.businessObject.dataObjectRef.name = "jeje"; - // const originalLabel = element.businessObject.name; - // const labelWithoutState = originalLabel.split(' [')[0]; - // // modeling.updateProperties(element, { name: labelWithoutState }); - // // storeOriginalLabel(element, originalLabel); - // }); - - - - // Remove Name Input from default group entries const generalGroup = groups.find(group => group.id === 'general'); if (generalGroup) { generalGroup.entries = generalGroup.entries.filter(entry => entry.id !== 'name'); diff --git a/app/spiffworkflow/index.js b/app/spiffworkflow/index.js index 2be2aa5..7cfa5a2 100644 --- a/app/spiffworkflow/index.js +++ b/app/spiffworkflow/index.js @@ -6,6 +6,7 @@ import DataObjectInterceptor from './DataObject/DataObjectInterceptor'; import DataObjectRules from './DataObject/DataObjectRules'; import DataObjectRenderer from './DataObject/DataObjectRenderer'; import DataObjectPropertiesProvider from './DataObject/propertiesPanel/DataObjectPropertiesProvider'; +import DataObjectLabelEditingProvider from './DataObject/DataObjectLabelEditingProvider'; import DataStorePropertiesProvider from './DataStoreReference/propertiesPanel/DataStorePropertiesProvider'; import DataStoreInterceptor from './DataStoreReference/DataStoreInterceptor'; import ConditionsPropertiesProvider from './conditions/propertiesPanel/ConditionsPropertiesProvider'; @@ -24,6 +25,7 @@ export default { 'dataObjectInterceptor', 'dataObjectRules', 'dataObjectPropertiesProvider', + 'dataObjectLabelEditingProvider', 'dataStoreInterceptor', 'dataStorePropertiesProvider', 'conditionsPropertiesProvider', @@ -44,6 +46,7 @@ export default { dataObjectRules: ['type', DataObjectRules], dataObjectRenderer: ['type', DataObjectRenderer], dataObjectPropertiesProvider: ['type', DataObjectPropertiesProvider], + dataObjectLabelEditingProvider: ['type', DataObjectLabelEditingProvider], dataStoreInterceptor: ['type', DataStoreInterceptor], dataStorePropertiesProvider: ['type', DataStorePropertiesProvider], conditionsPropertiesProvider: ['type', ConditionsPropertiesProvider], From cc2482ad432c4cbcd78bf31001d5402e8ff48472 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 16:30:58 +0100 Subject: [PATCH 08/20] Handle Manual Changes --- .../DataObjectLabelEditingProvider.js | 47 ++++++++++++++----- .../DataObjectPropertiesProvider.js | 6 +-- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js index c379358..86880e9 100644 --- a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js +++ b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js @@ -1,13 +1,10 @@ -import { is, isAny } from 'bpmn-js/lib/util/ModelUtil'; -import { ListGroup, isTextFieldEntryEdited, TextFieldEntry } from '@bpmn-io/properties-panel'; -import { useService } from 'bpmn-js-properties-panel'; +import { is } from 'bpmn-js/lib/util/ModelUtil'; +import { findDataObject, findDataObjectReferenceShapes, findDataObjects } from './DataObjectHelpers'; const LOW_PRIORITY = 500; export default function DataObjectLabelEditingProvider(eventBus, canvas, directEditing, commandStack, modeling) { - console.log('DataObjectLabelEditingProvider', eventBus, canvas, directEditing, commandStack, modeling, this); - directEditing.registerProvider(LOW_PRIORITY, this); let el; @@ -21,27 +18,50 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE modeling.updateLabel(element, label); directEditing.activate(element); el = element; - console.log('IS ACTIVE', directEditing.isActive(element)) - } }); eventBus.on('directEditing.activate', async function (event) { - console.log('directEditing.activate', event); const { element } = event.active; - if (is(element.businessObject, 'bpmn:DataObjectReference')) { - console.log('directEditing.activate bpmn:DataObjectReference', element, directEditing); - // modeling.updateLabel(element, 'newLabel'); - // directEditing.activate(element); - } + if (is(element.businessObject, 'bpmn:DataObjectReference')) { } }); eventBus.on('directEditing.complete', function (event) { + const element = el; + if (element && is(element.businessObject, 'bpmn:DataObjectReference')) { + + const process = element.parent.businessObject; + const dataObject = findDataObject(process, element.businessObject.dataObjectRef.id); const dataState = element.businessObject.dataState && element.businessObject.dataState.name; + let newLabel = element.businessObject.name; + commandStack.execute('element.updateModdleProperties', { + element, + moddleElement: dataObject, + properties: { + name: newLabel, + }, + }); + + // Update references name + const references = findDataObjectReferenceShapes(element.parent.children, dataObject.id); + for (const ref of references) { + const stateName = ref.businessObject.dataState && ref.businessObject.dataState.name ? ref.businessObject.dataState.name : ''; + const newName = stateName ? `${newLabel} [${stateName}]` : newLabel; + + commandStack.execute('element.updateProperties', { + element: ref, + moddleElement: ref.businessObject, + properties: { + name: newName, + }, + changed: [ref], + }); + } + // Append the data state if it exists if (dataState) { newLabel += ` [${dataState}]`; @@ -51,6 +71,7 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE modeling.updateLabel(element, newLabel); el = undefined; + } }); diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js index 0d6226c..dfcde52 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js @@ -13,8 +13,7 @@ export default function DataObjectPropertiesProvider( commandStack, elementRegistry, modeling, - bpmnFactory, - eventBus + bpmnFactory ) { this.getGroups = function (element) { return function (groups) { @@ -55,8 +54,7 @@ DataObjectPropertiesProvider.$inject = [ 'commandStack', 'elementRegistry', 'modeling', - 'bpmnFactory', - 'eventBus' + 'bpmnFactory' ]; /** From 5289bd6ee9cf0db5e8fe68cb78c50795872d8245 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 17:04:50 +0100 Subject: [PATCH 09/20] Add Rename references to dataObjectHelpers --- .../DataObject/DataObjectHelpers.js | 20 +++++++++++++++++-- .../DataObjectLabelEditingProvider.js | 19 ++---------------- .../propertiesPanel/DataObjectArray.js | 17 ++-------------- .../propertiesPanel/DataObjectSelect.js | 2 +- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/app/spiffworkflow/DataObject/DataObjectHelpers.js b/app/spiffworkflow/DataObject/DataObjectHelpers.js index dd34378..a254816 100644 --- a/app/spiffworkflow/DataObject/DataObjectHelpers.js +++ b/app/spiffworkflow/DataObject/DataObjectHelpers.js @@ -5,7 +5,7 @@ */ export function findDataObjects(parent, dataObjects) { - if (typeof(dataObjects) === 'undefined') + if (typeof (dataObjects) === 'undefined') dataObjects = []; let process; if (!parent) { @@ -18,7 +18,7 @@ export function findDataObjects(parent, dataObjects) { if (process.$type === 'bpmn:SubProcess') findDataObjects(process.$parent, dataObjects); } - if (typeof(process.flowElements) !== 'undefined') { + if (typeof (process.flowElements) !== 'undefined') { for (const element of process.flowElements) { if (element.$type === 'bpmn:DataObject') dataObjects.push(element); @@ -68,3 +68,19 @@ export function idToHumanReadableName(id) { return word.charAt(0).toUpperCase() + word.substring(1); } } + +export function updateDataObjectReferencesName(parent, nameValue, dataObjectId, commandStack) { + const references = findDataObjectReferenceShapes(parent.children, dataObjectId); + for (const ref of references) { + const stateName = ref.businessObject.dataState && ref.businessObject.dataState.name ? ref.businessObject.dataState.name : ''; + const newName = stateName ? `${nameValue} [${stateName}]` : nameValue; + commandStack.execute('element.updateProperties', { + element: ref, + moddleElement: ref.businessObject, + properties: { + name: newName, + }, + changed: [ref], + }); + } +} diff --git a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js index 86880e9..8525e97 100644 --- a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js +++ b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js @@ -1,5 +1,5 @@ import { is } from 'bpmn-js/lib/util/ModelUtil'; -import { findDataObject, findDataObjectReferenceShapes, findDataObjects } from './DataObjectHelpers'; +import { findDataObject, updateDataObjectReferencesName } from './DataObjectHelpers'; const LOW_PRIORITY = 500; @@ -47,20 +47,7 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE }); // Update references name - const references = findDataObjectReferenceShapes(element.parent.children, dataObject.id); - for (const ref of references) { - const stateName = ref.businessObject.dataState && ref.businessObject.dataState.name ? ref.businessObject.dataState.name : ''; - const newName = stateName ? `${newLabel} [${stateName}]` : newLabel; - - commandStack.execute('element.updateProperties', { - element: ref, - moddleElement: ref.businessObject, - properties: { - name: newName, - }, - changed: [ref], - }); - } + updateDataObjectReferencesName(element.parent, newLabel, dataObject.id, commandStack); // Append the data state if it exists if (dataState) { @@ -69,9 +56,7 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE // Update the label with the data state modeling.updateLabel(element, newLabel); - el = undefined; - } }); diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js index 5fa3e0d..efbad75 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js @@ -8,7 +8,7 @@ import { is } from 'bpmn-js/lib/util/ModelUtil'; import { findDataObjects, findDataObjectReferenceShapes, - idToHumanReadableName, + updateDataObjectReferencesName, } from '../DataObjectHelpers'; /** @@ -152,20 +152,7 @@ function DataObjectNameTextField(props) { const setValue = (value) => { // Update references name - const references = findDataObjectReferenceShapes(element.children, dataObject.id); - for (const ref of references) { - const stateName = ref.businessObject.dataState && ref.businessObject.dataState.name ? ref.businessObject.dataState.name : ''; - const newName = stateName ? `${value} [${stateName}]` : value; - - commandStack.execute('element.updateProperties', { - element: ref, - moddleElement: ref.businessObject, - properties: { - name: newName, - }, - changed: [ref], - }); - } + updateDataObjectReferencesName(element, value, dataObject.id, commandStack); // Update dataObject name commandStack.execute('element.updateModdleProperties', { diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js index efeea7d..9203ddd 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js @@ -1,6 +1,6 @@ import { useService } from 'bpmn-js-properties-panel'; import { SelectEntry } from '@bpmn-io/properties-panel'; -import { findDataObjects, idToHumanReadableName } from '../DataObjectHelpers'; +import { findDataObjects } from '../DataObjectHelpers'; /** * Finds the value of the given type within the extensionElements From e598f86fe39cbff1566e88ac6f8f9c4fd634822d Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 17:15:07 +0100 Subject: [PATCH 10/20] Broken Tests --- test/spec/DataObjectInterceptorSpec.js | 18 ++++++------ test/spec/DataObjectPropsSpec.js | 40 +++++++++++++------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/test/spec/DataObjectInterceptorSpec.js b/test/spec/DataObjectInterceptorSpec.js index c109f62..3a3b555 100644 --- a/test/spec/DataObjectInterceptorSpec.js +++ b/test/spec/DataObjectInterceptorSpec.js @@ -89,17 +89,17 @@ describe('DataObject Interceptor', function() { expect(dataObjects.length).to.equal(0); })); - it('Creating a new Reference will update the name to match the DataObject', inject(function(canvas, modeling) { + // it('Creating a new Reference will update the name to match the DataObject', inject(function(canvas, modeling) { - // IF - a Data Reference Exists - let rootShape = canvas.getRootElement(); - const dataObjectRefShape1 = modeling.createShape({ type: 'bpmn:DataObjectReference' }, - { x: 220, y: 220 }, rootShape); + // // IF - a Data Reference Exists + // let rootShape = canvas.getRootElement(); + // const dataObjectRefShape1 = modeling.createShape({ type: 'bpmn:DataObjectReference' }, + // { x: 220, y: 220 }, rootShape); - const dataObjects = findDataObjects(rootShape.businessObject); - const human_readable_name = idToHumanReadableName(dataObjects[0].id) - expect(dataObjectRefShape1.businessObject.name).to.equal(human_readable_name); - })); + // const dataObjects = findDataObjects(rootShape.businessObject); + // const human_readable_name = idToHumanReadableName(dataObjects[0].id) + // expect(dataObjectRefShape1.businessObject.name).to.equal(human_readable_name); + // })); it('should allow you to add a data object to a subprocess', inject(function(canvas, modeling, elementRegistry) { diff --git a/test/spec/DataObjectPropsSpec.js b/test/spec/DataObjectPropsSpec.js index aa97a50..1178018 100644 --- a/test/spec/DataObjectPropsSpec.js +++ b/test/spec/DataObjectPropsSpec.js @@ -62,30 +62,30 @@ describe('Properties Panel for Data Objects', function() { expect(businessObject.get('dataObjectRef').id).to.equal('my_third_data_object'); }); - it('renaming a data object, changes to the label of references', async function() { + // it('renaming a data object, changes to the label of references', 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, 'my_nifty_new_name'); - let my_data_ref_1 = await expectSelected('my_data_ref_1'); + // // 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, 'my_nifty_new_name'); + // 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('my_nifty_new_name'); - expect(my_data_ref_1.businessObject.name).to.equal('My Nifty New Name'); - }); + // // THEN - both the data object itself, and the label of any references are updated. + // expect(my_data_ref_1.businessObject.dataObjectRef.id).to.equal('my_nifty_new_name'); + // 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() { + // 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'); + // // 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'); - }); + // // 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'); + // }); }); From d3a1f38258b26f683eee188ec5bdab2d76a6b77d Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 17:25:59 +0100 Subject: [PATCH 11/20] Handle Broken Tests 2 --- test/spec/DataObjectInterceptorSpec.js | 26 +++++++++++++- test/spec/DataObjectPropsSpec.js | 47 +++++++++++++++++++++----- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/test/spec/DataObjectInterceptorSpec.js b/test/spec/DataObjectInterceptorSpec.js index 3a3b555..b25b2ee 100644 --- a/test/spec/DataObjectInterceptorSpec.js +++ b/test/spec/DataObjectInterceptorSpec.js @@ -88,7 +88,7 @@ describe('DataObject Interceptor', function() { const dataObjects = findDataObjects(rootShape.businessObject); expect(dataObjects.length).to.equal(0); })); - + // it('Creating a new Reference will update the name to match the DataObject', inject(function(canvas, modeling) { // // IF - a Data Reference Exists @@ -165,4 +165,28 @@ describe('DataObject Interceptor', function() { })); + // it('should not allow two dataObjects to have the same ID', inject(async function(canvas, modeling) { + + // // Creating the first dataObject + // let rootShape = canvas.getRootElement(); + // const dataObject1 = modeling.createShape({ type: 'bpmn:DataObject' }, + // { x: 100, y: 100 }, rootShape); + + // // Creating the second dataObject + // const dataObject2 = modeling.createShape({ type: 'bpmn:DataObject' }, + // { x: 150, y: 100 }, rootShape); + + // await expectSelected(dataObject2.id); + + // let entry = findEntry('dataObjectId', container); + // let idInput = findInput('text', entry); + + // const duplicateId = dataObject1.businessObject.id; + // changeInput(idInput, duplicateId); + + // // Checkk that the ID change is not successful + // expect(dataObject2.businessObject.id).not.to.equal(duplicateId); + + // })); + }); diff --git a/test/spec/DataObjectPropsSpec.js b/test/spec/DataObjectPropsSpec.js index 1178018..136531f 100644 --- a/test/spec/DataObjectPropsSpec.js +++ b/test/spec/DataObjectPropsSpec.js @@ -62,6 +62,9 @@ describe('Properties Panel for Data Objects', function() { expect(businessObject.get('dataObjectRef').id).to.equal('my_third_data_object'); }); + // Notice: Test Case for Data Object ID Changes No Longer Required + // With our new feature implementation, changing a Data Object ID is now independent of altering + // its Data Reference Name. This decoupling eliminates the need for the specific test case previously required for these changes. // it('renaming a data object, changes to the label of references', async function() { // // IF - a process is selected, and the name of a data object is changed. @@ -74,18 +77,46 @@ describe('Properties Panel for Data Objects', function() { // expect(my_data_ref_1.businessObject.dataObjectRef.id).to.equal('my_nifty_new_name'); // 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() { - // 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'); - // // 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'); + // 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'); + // Notice: Test Case for Data Object ID Changes No Longer Required + // expect(my_data_ref_1.businessObject.name).to.equal('My Object 1'); + }); + + it('renaming a data object, does not change the label of references', 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, 'my_nifty_new_name'); + 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('my_nifty_new_name'); + expect(my_data_ref_1.businessObject.name).not.to.equal('My Nifty New Name'); + }); + + // it('selecting a different data object should not change the data object reference name.', async function() { + + // // IF - a data object reference is selected // 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'); + // let entry = findEntry('selectDataObject', container); + // let selector = findSelect(entry); + // let businessObject = my_data_ref_1.businessObject; + + // changeInput(selector, 'my_third_data_object'); + + // expect(businessObject.get('dataObjectRef').id).to.equal('my_third_data_object'); + // expect(businessObject.name).to.equal('my_data_object'); + // expect(businessObject.name).not.to.equal('My Third Data Object'); // }); }); From 80dcc92d2f98570373ee981a30229b832388f5c5 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 18:05:31 +0100 Subject: [PATCH 12/20] Handle Broken Tests 3 --- .../propertiesPanel/DataObjectSelect.js | 1 - test/spec/DataObjectPropsSpec.js | 38 +++++++++++-------- test/spec/bpmn/diagram.bpmn | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js index 9203ddd..2db1a39 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectSelect.js @@ -46,7 +46,6 @@ export function DataObjectSelect(props) { // Construct the new name by : the dataObject name and the current state const stateName = businessObject.dataState && businessObject.dataState.name ? businessObject.dataState.name : ''; const newName = stateName ? `${dataObject.name} [${stateName}]` : dataObject.name; - // Update the name property of the DataObjectReference commandStack.execute('element.updateProperties', { element: element, diff --git a/test/spec/DataObjectPropsSpec.js b/test/spec/DataObjectPropsSpec.js index 136531f..cca3525 100644 --- a/test/spec/DataObjectPropsSpec.js +++ b/test/spec/DataObjectPropsSpec.js @@ -1,9 +1,17 @@ import { - bootstrapPropertiesPanel, changeInput, + bootstrapPropertiesPanel, + changeInput, expectSelected, - findEntry, findInput, findSelect, + findEntry, + findInput, + findSelect } from './helpers'; -import { BpmnPropertiesPanelModule, BpmnPropertiesProviderModule } from 'bpmn-js-properties-panel'; + +import { + BpmnPropertiesPanelModule, + BpmnPropertiesProviderModule +} from 'bpmn-js-properties-panel'; + import spiffModdleExtension from '../../app/spiffworkflow/moddle/spiffworkflow.json'; import TestContainer from 'mocha-test-container-support'; import DataObject from '../../app/spiffworkflow/DataObject'; @@ -103,20 +111,20 @@ describe('Properties Panel for Data Objects', function() { expect(my_data_ref_1.businessObject.name).not.to.equal('My Nifty New Name'); }); - // it('selecting a different data object should not change the data object reference name.', async function() { + it('selecting a different data object should not change the data object reference name.', async function() { - // // IF - a data object reference is selected - // let my_data_ref_1 = await expectSelected('my_data_ref_1'); + // IF - a data object reference is selected + let my_data_ref_1 = await expectSelected('my_data_ref_1'); - // let entry = findEntry('selectDataObject', container); - // let selector = findSelect(entry); - // let businessObject = my_data_ref_1.businessObject; - - // changeInput(selector, 'my_third_data_object'); + let entry = findEntry('selectDataObject', container); + let selector = findSelect(entry); + let businessObject = my_data_ref_1.businessObject; - // expect(businessObject.get('dataObjectRef').id).to.equal('my_third_data_object'); - // expect(businessObject.name).to.equal('my_data_object'); - // expect(businessObject.name).not.to.equal('My Third Data Object'); - // }); + changeInput(selector, 'my_third_data_object'); + + expect(businessObject.get('dataObjectRef').id).to.equal('my_third_data_object'); + expect(businessObject.name).to.equal('D3'); + expect(businessObject.name).not.to.equal('my_data_object'); + }); }); diff --git a/test/spec/bpmn/diagram.bpmn b/test/spec/bpmn/diagram.bpmn index 9104624..0f0c041 100644 --- a/test/spec/bpmn/diagram.bpmn +++ b/test/spec/bpmn/diagram.bpmn @@ -38,7 +38,7 @@ elizabeth="awesome" - + From 7aa03cd39ce1c26476c187cd96be7a029e1c94fc Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 18:40:49 +0100 Subject: [PATCH 13/20] Handle Broken Test 4 --- .../DataObject/DataObjectInterceptor.js | 4 +-- .../propertiesPanel/DataObjectArray.js | 25 +++++++++++++------ test/spec/DataObjectInterceptorSpec.js | 18 ++++++------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/app/spiffworkflow/DataObject/DataObjectInterceptor.js b/app/spiffworkflow/DataObject/DataObjectInterceptor.js index 9823cad..862f970 100644 --- a/app/spiffworkflow/DataObject/DataObjectInterceptor.js +++ b/app/spiffworkflow/DataObject/DataObjectInterceptor.js @@ -87,7 +87,7 @@ export default class DataObjectInterceptor extends CommandInterceptor { dataObject = existingDataObjects[0]; } else { dataObject = bpmnFactory.create('bpmn:DataObject'); - dataObject.name = 'DataObject Name'; + dataObject.name = idToHumanReadableName(dataObject.id); } // set the reference to the DataObject shape.businessObject.dataObjectRef = dataObject; @@ -108,7 +108,7 @@ export default class DataObjectInterceptor extends CommandInterceptor { element: shape, moddleElement: shape.businessObject, properties: { - name: idToHumanReadableName(shape.businessObject.dataObjectRef.name), + name: shape.businessObject.dataObjectRef.name, }, }); } diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js index efbad75..1b0ef2a 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js @@ -9,6 +9,7 @@ import { findDataObjects, findDataObjectReferenceShapes, updateDataObjectReferencesName, + idToHumanReadableName, } from '../DataObjectHelpers'; /** @@ -57,7 +58,7 @@ export function DataObjectArray(props) { const newDataObject = moddle.create('bpmn:DataObject'); const newElements = process.get('flowElements'); newDataObject.id = moddle.ids.nextPrefixed('DataObject_'); - newDataObject.name = 'DataObject Name'; + newDataObject.name = idToHumanReadableName(newDataObject.id); newDataObject.$parent = process; newElements.push(newDataObject); commandStack.execute('element.updateModdleProperties', { @@ -120,13 +121,21 @@ function DataObjectTextField(props) { const debounce = useService('debounceInput'); const setValue = (value) => { - commandStack.execute('element.updateModdleProperties', { - element, - moddleElement: dataObject, - properties: { - id: value, - }, - }); + try { + // let doName = idToHumanReadableName(value); + commandStack.execute('element.updateModdleProperties', { + element, + moddleElement: dataObject, + properties: { + id: value, + // name: doName + }, + }); + // Update references name + // updateDataObjectReferencesName(element, doName, value, commandStack); + } catch (error) { + console.log('Set Value Error : ', error); + } }; const getValue = () => { diff --git a/test/spec/DataObjectInterceptorSpec.js b/test/spec/DataObjectInterceptorSpec.js index b25b2ee..b50a65d 100644 --- a/test/spec/DataObjectInterceptorSpec.js +++ b/test/spec/DataObjectInterceptorSpec.js @@ -89,17 +89,17 @@ describe('DataObject Interceptor', function() { expect(dataObjects.length).to.equal(0); })); - // it('Creating a new Reference will update the name to match the DataObject', inject(function(canvas, modeling) { + it('Creating a new Reference will update the name to match the DataObject', inject(function(canvas, modeling) { - // // IF - a Data Reference Exists - // let rootShape = canvas.getRootElement(); - // const dataObjectRefShape1 = modeling.createShape({ type: 'bpmn:DataObjectReference' }, - // { x: 220, y: 220 }, rootShape); + // IF - a Data Reference Exists + let rootShape = canvas.getRootElement(); + const dataObjectRefShape1 = modeling.createShape({ type: 'bpmn:DataObjectReference' }, + { x: 220, y: 220 }, rootShape); - // const dataObjects = findDataObjects(rootShape.businessObject); - // const human_readable_name = idToHumanReadableName(dataObjects[0].id) - // expect(dataObjectRefShape1.businessObject.name).to.equal(human_readable_name); - // })); + const dataObjects = findDataObjects(rootShape.businessObject); + const human_readable_name = idToHumanReadableName(dataObjects[0].id) + expect(dataObjectRefShape1.businessObject.name).to.equal(human_readable_name); + })); it('should allow you to add a data object to a subprocess', inject(function(canvas, modeling, elementRegistry) { From 37e71bdef2e18a668706b4e88c7c72b81fb592c2 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 18:44:01 +0100 Subject: [PATCH 14/20] Handle Broken Tests 5 --- test/spec/DataObjectInterceptorSpec.js | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/spec/DataObjectInterceptorSpec.js b/test/spec/DataObjectInterceptorSpec.js index b50a65d..3a4681f 100644 --- a/test/spec/DataObjectInterceptorSpec.js +++ b/test/spec/DataObjectInterceptorSpec.js @@ -165,28 +165,28 @@ describe('DataObject Interceptor', function() { })); - // it('should not allow two dataObjects to have the same ID', inject(async function(canvas, modeling) { + it('should not allow two dataObjects to have the same ID', inject(async function(canvas, modeling) { - // // Creating the first dataObject - // let rootShape = canvas.getRootElement(); - // const dataObject1 = modeling.createShape({ type: 'bpmn:DataObject' }, - // { x: 100, y: 100 }, rootShape); + // Creating the first dataObject + let rootShape = canvas.getRootElement(); + const dataObject1 = modeling.createShape({ type: 'bpmn:DataObject' }, + { x: 100, y: 100 }, rootShape); - // // Creating the second dataObject - // const dataObject2 = modeling.createShape({ type: 'bpmn:DataObject' }, - // { x: 150, y: 100 }, rootShape); + // Creating the second dataObject + const dataObject2 = modeling.createShape({ type: 'bpmn:DataObject' }, + { x: 150, y: 100 }, rootShape); - // await expectSelected(dataObject2.id); + await expectSelected(dataObject2.id); - // let entry = findEntry('dataObjectId', container); - // let idInput = findInput('text', entry); + let entry = findEntry('dataObjectId', container); + let idInput = findInput('text', entry); - // const duplicateId = dataObject1.businessObject.id; - // changeInput(idInput, duplicateId); + const duplicateId = dataObject1.businessObject.id; + changeInput(idInput, duplicateId); - // // Checkk that the ID change is not successful - // expect(dataObject2.businessObject.id).not.to.equal(duplicateId); + // Check that the ID change is not successful + expect(dataObject2.businessObject.id).not.to.equal(duplicateId); - // })); + })); }); From 511a9c9c3158a184b64ddabd19f5485eb48bfb58 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 18:53:23 +0100 Subject: [PATCH 15/20] Done with Fixing Broken Tests --- .../propertiesPanel/DataObjectArray.js | 7 +++++ test/spec/DataObjectInterceptorSpec.js | 26 +---------------- test/spec/DataObjectPropsSpec.js | 28 +++++++++++++++++++ 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js index 1b0ef2a..5bd5715 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectArray.js @@ -10,6 +10,7 @@ import { findDataObjectReferenceShapes, updateDataObjectReferencesName, idToHumanReadableName, + findDataObject, } from '../DataObjectHelpers'; /** @@ -122,6 +123,12 @@ function DataObjectTextField(props) { const setValue = (value) => { try { + // Check if new dataObject Id is not unique + if(findDataObject(element.businessObject, value) !== undefined){ + alert('Data Object ID Should be unique'); + return; + } + // let doName = idToHumanReadableName(value); commandStack.execute('element.updateModdleProperties', { element, diff --git a/test/spec/DataObjectInterceptorSpec.js b/test/spec/DataObjectInterceptorSpec.js index 3a4681f..9705abf 100644 --- a/test/spec/DataObjectInterceptorSpec.js +++ b/test/spec/DataObjectInterceptorSpec.js @@ -1,4 +1,4 @@ -import { bootstrapPropertiesPanel } from './helpers'; +import { bootstrapPropertiesPanel, changeInput, expectSelected, findEntry, findInput } from './helpers'; import dataObjectInterceptor from '../../app/spiffworkflow/DataObject'; import { BpmnPropertiesPanelModule, BpmnPropertiesProviderModule } from 'bpmn-js-properties-panel'; import { @@ -165,28 +165,4 @@ describe('DataObject Interceptor', function() { })); - it('should not allow two dataObjects to have the same ID', inject(async function(canvas, modeling) { - - // Creating the first dataObject - let rootShape = canvas.getRootElement(); - const dataObject1 = modeling.createShape({ type: 'bpmn:DataObject' }, - { x: 100, y: 100 }, rootShape); - - // Creating the second dataObject - const dataObject2 = modeling.createShape({ type: 'bpmn:DataObject' }, - { x: 150, y: 100 }, rootShape); - - await expectSelected(dataObject2.id); - - let entry = findEntry('dataObjectId', container); - let idInput = findInput('text', entry); - - const duplicateId = dataObject1.businessObject.id; - changeInput(idInput, duplicateId); - - // Check that the ID change is not successful - expect(dataObject2.businessObject.id).not.to.equal(duplicateId); - - })); - }); diff --git a/test/spec/DataObjectPropsSpec.js b/test/spec/DataObjectPropsSpec.js index cca3525..ccea526 100644 --- a/test/spec/DataObjectPropsSpec.js +++ b/test/spec/DataObjectPropsSpec.js @@ -7,6 +7,10 @@ import { findSelect } from './helpers'; +import { + inject, +} from 'bpmn-js/test/helper'; + import { BpmnPropertiesPanelModule, BpmnPropertiesProviderModule @@ -127,4 +131,28 @@ describe('Properties Panel for Data Objects', function() { expect(businessObject.name).not.to.equal('my_data_object'); }); + it('should not allow two dataObjects to have the same ID', inject(async function(canvas, modeling) { + + // Creating the first dataObject + let rootShape = canvas.getRootElement(); + const dataObject1 = modeling.createShape({ type: 'bpmn:DataObject' }, + { x: 100, y: 100 }, rootShape); + + // Creating the second dataObject + const dataObject2 = modeling.createShape({ type: 'bpmn:DataObject' }, + { x: 150, y: 100 }, rootShape); + + await expectSelected(dataObject2.id); + + let entry = findEntry('dataObjectId', container); + let idInput = findInput('text', entry); + + const duplicateId = dataObject1.businessObject.id; + changeInput(idInput, duplicateId); + + // Check that the ID change is not successful + expect(dataObject2.businessObject.id).not.to.equal(duplicateId); + + })); + }); From 84a0667ec4dd77a34e2cce3ada70e8b9b0792ad6 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 19:36:11 +0100 Subject: [PATCH 16/20] Remove Consoles --- .../DataObject/DataObjectLabelEditingProvider.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js index 8525e97..a25102d 100644 --- a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js +++ b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js @@ -38,6 +38,10 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE let newLabel = element.businessObject.name; + console.log('newLabel', newLabel); + console.log('dataObject', dataObject); + console.log('element', element); + commandStack.execute('element.updateModdleProperties', { element, moddleElement: dataObject, @@ -46,6 +50,8 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE }, }); + console.log('cdataObject', dataObject); + // Update references name updateDataObjectReferencesName(element.parent, newLabel, dataObject.id, commandStack); @@ -57,6 +63,8 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE // Update the label with the data state modeling.updateLabel(element, newLabel); el = undefined; + + console.log('---------------------'); } }); From 123037d8eee2922d4c87db0d08ed47eebc7b5909 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sat, 2 Dec 2023 23:04:31 +0100 Subject: [PATCH 17/20] Before implementing new tests --- .../DataObjectLabelEditingProvider.js | 22 +++------- test/spec/DataObjectInterceptorSpec.js | 24 +++++----- test/spec/DataObjectPropsSpec.js | 44 +++++++++---------- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js index a25102d..74e345f 100644 --- a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js +++ b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js @@ -5,8 +5,7 @@ const LOW_PRIORITY = 500; export default function DataObjectLabelEditingProvider(eventBus, canvas, directEditing, commandStack, modeling) { - directEditing.registerProvider(LOW_PRIORITY, this); - + // directEditing.registerProvider(LOW_PRIORITY, this); let el; // listen to dblclick on non-root elements @@ -21,27 +20,21 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE } }); - eventBus.on('directEditing.activate', async function (event) { - const { element } = event.active; - if (is(element.businessObject, 'bpmn:DataObjectReference')) { } - }); + // eventBus.on('directEditing.activate', async function (event) { + // const { element } = event.active; + // if (is(element.businessObject, 'bpmn:DataObjectReference')) { } + // }); eventBus.on('directEditing.complete', function (event) { const element = el; - if (element && is(element.businessObject, 'bpmn:DataObjectReference')) { - const process = element.parent.businessObject; const dataObject = findDataObject(process, element.businessObject.dataObjectRef.id); const dataState = element.businessObject.dataState && element.businessObject.dataState.name; let newLabel = element.businessObject.name; - console.log('newLabel', newLabel); - console.log('dataObject', dataObject); - console.log('element', element); - commandStack.execute('element.updateModdleProperties', { element, moddleElement: dataObject, @@ -50,8 +43,6 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE }, }); - console.log('cdataObject', dataObject); - // Update references name updateDataObjectReferencesName(element.parent, newLabel, dataObject.id, commandStack); @@ -63,11 +54,8 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE // Update the label with the data state modeling.updateLabel(element, newLabel); el = undefined; - - console.log('---------------------'); } }); - } DataObjectLabelEditingProvider.$inject = [ diff --git a/test/spec/DataObjectInterceptorSpec.js b/test/spec/DataObjectInterceptorSpec.js index 9705abf..ff235b7 100644 --- a/test/spec/DataObjectInterceptorSpec.js +++ b/test/spec/DataObjectInterceptorSpec.js @@ -1,4 +1,4 @@ -import { bootstrapPropertiesPanel, changeInput, expectSelected, findEntry, findInput } from './helpers'; +import { bootstrapPropertiesPanel } from './helpers'; import dataObjectInterceptor from '../../app/spiffworkflow/DataObject'; import { BpmnPropertiesPanelModule, BpmnPropertiesProviderModule } from 'bpmn-js-properties-panel'; import { @@ -10,7 +10,7 @@ import { idToHumanReadableName, } from '../../app/spiffworkflow/DataObject/DataObjectHelpers'; -describe('DataObject Interceptor', function() { +describe('DataObject Interceptor', function () { let xml = require('./bpmn/empty_diagram.bpmn').default; @@ -23,7 +23,7 @@ describe('DataObject Interceptor', function() { ] })); - it('New Data Object References should create a data object if none exist.', inject(function(canvas, modeling) { + it('New Data Object References should create a data object if none exist.', inject(function (canvas, modeling) { // IF - a new dataObjectReference is created let rootShape = canvas.getRootElement(); @@ -37,7 +37,7 @@ describe('DataObject Interceptor', function() { })); - it('New Data Object References should connect to the first available data Object if it exists', inject(function(canvas, modeling) { + it('New Data Object References should connect to the first available data Object if it exists', inject(function (canvas, modeling) { // IF - two dataObjectReferences are created let rootShape = canvas.getRootElement(); @@ -54,7 +54,7 @@ describe('DataObject Interceptor', function() { })); - it('Deleting a data object reference does not delete the data object, unless it is the last reference', inject(function(canvas, modeling) { + it('Deleting a data object reference does not delete the data object, unless it is the last reference', inject(function (canvas, modeling) { // IF - two dataObjectReferences are created let rootShape = canvas.getRootElement(); @@ -71,7 +71,7 @@ describe('DataObject Interceptor', function() { expect(dataObjects.length).to.equal(1); })); - it('Deleting all the data references will also delete the data object', inject(function(canvas, modeling) { + it('Deleting all the data references will also delete the data object', inject(function (canvas, modeling) { // IF - two dataObjectReferences are created let rootShape = canvas.getRootElement(); @@ -88,8 +88,8 @@ describe('DataObject Interceptor', function() { const dataObjects = findDataObjects(rootShape.businessObject); expect(dataObjects.length).to.equal(0); })); - - it('Creating a new Reference will update the name to match the DataObject', inject(function(canvas, modeling) { + + it('Creating a new Reference will update the name to match the DataObject', inject(function (canvas, modeling) { // IF - a Data Reference Exists let rootShape = canvas.getRootElement(); @@ -101,7 +101,7 @@ describe('DataObject Interceptor', function() { expect(dataObjectRefShape1.businessObject.name).to.equal(human_readable_name); })); - it('should allow you to add a data object to a subprocess', inject(function(canvas, modeling, elementRegistry) { + it('should allow you to add a data object to a subprocess', inject(function (canvas, modeling, elementRegistry) { // IF - A data object reference is added to a sup-process let subProcessShape = elementRegistry.get('my_subprocess'); @@ -117,7 +117,7 @@ describe('DataObject Interceptor', function() { expect(dataObjects.length).to.equal(1); })); - it('Data objects in a process should be visible in a subprocess', inject(function(canvas, modeling, elementRegistry) { + it('Data objects in a process should be visible in a subprocess', inject(function (canvas, modeling, elementRegistry) { let subProcessShape = elementRegistry.get('my_subprocess'); let subProcess = subProcessShape.businessObject; @@ -132,7 +132,7 @@ describe('DataObject Interceptor', function() { expect(dataObjects.length).to.equal(1); })); - it('Data objects in a subprocess should not be visible in a process', inject(function(canvas, modeling, elementRegistry) { + it('Data objects in a subprocess should not be visible in a process', inject(function (canvas, modeling, elementRegistry) { let subProcessShape = elementRegistry.get('my_subprocess'); let subProcess = subProcessShape.businessObject; @@ -147,7 +147,7 @@ describe('DataObject Interceptor', function() { expect(dataObjects.length).to.equal(0); })); - it('References inside subprocesses should be visible in a process', inject(function(canvas, modeling, elementRegistry) { + it('References inside subprocesses should be visible in a process', inject(function (canvas, modeling, elementRegistry) { let rootShape = canvas.getRootElement(); const refOne = modeling.createShape({ type: 'bpmn:DataObjectReference' }, diff --git a/test/spec/DataObjectPropsSpec.js b/test/spec/DataObjectPropsSpec.js index ccea526..224add9 100644 --- a/test/spec/DataObjectPropsSpec.js +++ b/test/spec/DataObjectPropsSpec.js @@ -1,9 +1,9 @@ import { - bootstrapPropertiesPanel, + bootstrapPropertiesPanel, changeInput, expectSelected, - findEntry, - findInput, + findEntry, + findInput, findSelect } from './helpers'; @@ -11,20 +11,20 @@ import { inject, } from 'bpmn-js/test/helper'; -import { - BpmnPropertiesPanelModule, - BpmnPropertiesProviderModule +import { + BpmnPropertiesPanelModule, + BpmnPropertiesProviderModule } from 'bpmn-js-properties-panel'; import spiffModdleExtension from '../../app/spiffworkflow/moddle/spiffworkflow.json'; import TestContainer from 'mocha-test-container-support'; import DataObject from '../../app/spiffworkflow/DataObject'; -describe('Properties Panel for Data Objects', function() { +describe('Properties Panel for Data Objects', function () { let xml = require('./bpmn/diagram.bpmn').default; let container; - beforeEach(function() { + beforeEach(function () { container = TestContainer.get(this); }); @@ -41,7 +41,7 @@ describe('Properties Panel for Data Objects', function() { }, })); - it('should allow you to see a list of data objects', async function() { + it('should allow you to see a list of data objects', async function () { // IF - a data object reference is selected let my_data_ref_1 = await expectSelected('my_data_ref_1'); @@ -58,7 +58,7 @@ describe('Properties Panel for Data Objects', function() { }); - it('selecting a different data object should change the data model.', async function() { + it('selecting a different data object should change the data model.', async function () { // IF - a data object reference is selected let my_data_ref_1 = await expectSelected('my_data_ref_1'); @@ -89,8 +89,8 @@ describe('Properties Panel for Data Objects', function() { // expect(my_data_ref_1.businessObject.dataObjectRef.id).to.equal('my_nifty_new_name'); // 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() { + + 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); @@ -104,7 +104,7 @@ describe('Properties Panel for Data Objects', function() { // expect(my_data_ref_1.businessObject.name).to.equal('My Object 1'); }); - it('renaming a data object, does not change the label of references', async function() { + it('renaming a data object, does not change the label of references', 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); @@ -115,7 +115,7 @@ describe('Properties Panel for Data Objects', function() { expect(my_data_ref_1.businessObject.name).not.to.equal('My Nifty New Name'); }); - it('selecting a different data object should not change the data object reference name.', async function() { + it('selecting a different data object should not change the data object reference name.', async function () { // IF - a data object reference is selected let my_data_ref_1 = await expectSelected('my_data_ref_1'); @@ -123,7 +123,7 @@ describe('Properties Panel for Data Objects', function() { let entry = findEntry('selectDataObject', container); let selector = findSelect(entry); let businessObject = my_data_ref_1.businessObject; - + changeInput(selector, 'my_third_data_object'); expect(businessObject.get('dataObjectRef').id).to.equal('my_third_data_object'); @@ -131,28 +131,28 @@ describe('Properties Panel for Data Objects', function() { expect(businessObject.name).not.to.equal('my_data_object'); }); - it('should not allow two dataObjects to have the same ID', inject(async function(canvas, modeling) { + it('should not allow two dataObjects to have the same ID', inject(async function (canvas, modeling) { // Creating the first dataObject let rootShape = canvas.getRootElement(); const dataObject1 = modeling.createShape({ type: 'bpmn:DataObject' }, { x: 100, y: 100 }, rootShape); - + // Creating the second dataObject const dataObject2 = modeling.createShape({ type: 'bpmn:DataObject' }, { x: 150, y: 100 }, rootShape); - + await expectSelected(dataObject2.id); - + let entry = findEntry('dataObjectId', container); let idInput = findInput('text', entry); - + const duplicateId = dataObject1.businessObject.id; changeInput(idInput, duplicateId); - + // Check that the ID change is not successful expect(dataObject2.businessObject.id).not.to.equal(duplicateId); - + })); }); From 9c1d9afac816e10024b8a8c54ee299a106dce305 Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sun, 3 Dec 2023 12:22:26 +0100 Subject: [PATCH 18/20] Implement new tests --- .../DataObjectPropertiesProvider.js | 4 +- test/spec/DataObjectPropsSpec.js | 41 ++++++++++++++++++- test/spec/bpmn/diagram.bpmn | 11 +++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js index dfcde52..ce63e27 100644 --- a/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js +++ b/app/spiffworkflow/DataObject/propertiesPanel/DataObjectPropertiesProvider.js @@ -168,8 +168,8 @@ function createDataStateTextField(props) { element, id: `${id}-textField`, name: 'spiffworkflow:DataStateLabel', - label: 'Which Data State does this reference?', - description: 'Select the Data State this represents.', + label: 'Enter Data State of this reference?', + description: 'Enter the Data State for this reference.', getValue, setValue, debounce, diff --git a/test/spec/DataObjectPropsSpec.js b/test/spec/DataObjectPropsSpec.js index 224add9..3b27f50 100644 --- a/test/spec/DataObjectPropsSpec.js +++ b/test/spec/DataObjectPropsSpec.js @@ -57,7 +57,6 @@ describe('Properties Panel for Data Objects', function () { expect(selector.length).to.equal(3); }); - it('selecting a different data object should change the data model.', async function () { // IF - a data object reference is selected @@ -104,7 +103,7 @@ describe('Properties Panel for Data Objects', function () { // expect(my_data_ref_1.businessObject.name).to.equal('My Object 1'); }); - it('renaming a data object, does not change the label of references', async function () { + it('renaming a data object ID, does not change the label of references', 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); @@ -115,6 +114,44 @@ describe('Properties Panel for Data Objects', function () { expect(my_data_ref_1.businessObject.name).not.to.equal('My Nifty New Name'); }); + it('renaming a data object name, does change the label of references', async function () { + + let entry = findEntry('ProcessTest-dataObj-2-name', container); + let textInput = findInput('text', entry); + let newDataObjectName = 'A New Data Object Name'; + + changeInput(textInput, newDataObjectName); + + let my_data_ref_1 = await expectSelected('my_data_ref_1'); + let my_data_ref_2 = await expectSelected('my_data_ref_2'); + + // THEN - the label of any references are updated. + expect(my_data_ref_1.businessObject.name).to.equal(newDataObjectName); + expect(my_data_ref_2.businessObject.name).to.equal(newDataObjectName); + + // Test References with DataState + let my_data_ref_3 = await expectSelected('my_data_ref_3'); + let my_data_ref_3_DataState = my_data_ref_3.businessObject.dataState.name; + + expect(my_data_ref_3.businessObject.name).to.equal(`${newDataObjectName} [${my_data_ref_3_DataState}]`); + }); + + it('renaming a data object reference state, does change the label of references', async function () { + + let my_data_ref_1 = await expectSelected('my_data_ref_1'); + let dtObjCurrentName = my_data_ref_1.businessObject.name; + let entry = findEntry('selectDataState-textField', container); + let idInput = findInput('text', entry); + let nwState = "New State"; + + // Change Data State + changeInput(idInput, nwState); + + // Expect new DataObjectRef Name to be like 'DataObjectRefName [DataState]' + expect(my_data_ref_1.businessObject.name).to.equal(`${dtObjCurrentName} [${nwState}]`); + expect(my_data_ref_1.businessObject.name).not.to.equal(dtObjCurrentName); + }); + it('selecting a different data object should not change the data object reference name.', async function () { // IF - a data object reference is selected diff --git a/test/spec/bpmn/diagram.bpmn b/test/spec/bpmn/diagram.bpmn index 0f0c041..de82f6e 100644 --- a/test/spec/bpmn/diagram.bpmn +++ b/test/spec/bpmn/diagram.bpmn @@ -61,6 +61,11 @@ + + + + + @@ -119,6 +124,12 @@ + + + + + + From ec81cfa0bfb8bc245902b9b91e353a58258a42cb Mon Sep 17 00:00:00 2001 From: theaubmov Date: Sun, 3 Dec 2023 12:25:51 +0100 Subject: [PATCH 19/20] Done with basic unic testing --- test/spec/DataObjectPropsSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/DataObjectPropsSpec.js b/test/spec/DataObjectPropsSpec.js index 3b27f50..a4eff94 100644 --- a/test/spec/DataObjectPropsSpec.js +++ b/test/spec/DataObjectPropsSpec.js @@ -136,7 +136,7 @@ describe('Properties Panel for Data Objects', function () { expect(my_data_ref_3.businessObject.name).to.equal(`${newDataObjectName} [${my_data_ref_3_DataState}]`); }); - it('renaming a data object reference state, does change the label of references', async function () { + it('renaming a data object reference state, does change the label its reference', async function () { let my_data_ref_1 = await expectSelected('my_data_ref_1'); let dtObjCurrentName = my_data_ref_1.businessObject.name; From ae4bd81548b954d357105b761ee675023d8a886f Mon Sep 17 00:00:00 2001 From: theaubmov Date: Tue, 5 Dec 2023 18:51:02 +0100 Subject: [PATCH 20/20] Fix Overrided Label editing provider bug --- .../DataObjectLabelEditingProvider.js | 55 +++++++++---------- app/spiffworkflow/DataObject/index.js | 3 +- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js index 74e345f..2ab145a 100644 --- a/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js +++ b/app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js @@ -1,11 +1,8 @@ import { is } from 'bpmn-js/lib/util/ModelUtil'; import { findDataObject, updateDataObjectReferencesName } from './DataObjectHelpers'; -const LOW_PRIORITY = 500; +export default function DataObjectLabelEditingProvider(eventBus, directEditing, commandStack, modeling) { -export default function DataObjectLabelEditingProvider(eventBus, canvas, directEditing, commandStack, modeling) { - - // directEditing.registerProvider(LOW_PRIORITY, this); let el; // listen to dblclick on non-root elements @@ -20,47 +17,45 @@ export default function DataObjectLabelEditingProvider(eventBus, canvas, directE } }); - // eventBus.on('directEditing.activate', async function (event) { - // const { element } = event.active; - // if (is(element.businessObject, 'bpmn:DataObjectReference')) { } - // }); - eventBus.on('directEditing.complete', function (event) { const element = el; + if (element && is(element.businessObject, 'bpmn:DataObjectReference')) { - const process = element.parent.businessObject; - const dataObject = findDataObject(process, element.businessObject.dataObjectRef.id); - const dataState = element.businessObject.dataState && element.businessObject.dataState.name; - let newLabel = element.businessObject.name; + setTimeout(() => { + const process = element.parent.businessObject; + const dataObject = findDataObject(process, element.businessObject.dataObjectRef.id); + const dataState = element.businessObject.dataState && element.businessObject.dataState.name; - commandStack.execute('element.updateModdleProperties', { - element, - moddleElement: dataObject, - properties: { - name: newLabel, - }, - }); + let newLabel = element.businessObject.name; - // Update references name - updateDataObjectReferencesName(element.parent, newLabel, dataObject.id, commandStack); + commandStack.execute('element.updateModdleProperties', { + element, + moddleElement: dataObject, + properties: { + name: newLabel, + }, + }); - // Append the data state if it exists - if (dataState) { - newLabel += ` [${dataState}]`; - } + // Update references name + updateDataObjectReferencesName(element.parent, newLabel, dataObject.id, commandStack); - // Update the label with the data state - modeling.updateLabel(element, newLabel); - el = undefined; + // Append the data state if it exists + if (dataState) { + newLabel += ` [${dataState}]`; + } + + // Update the label with the data state + modeling.updateLabel(element, newLabel); + el = undefined; + }, 100); } }); } DataObjectLabelEditingProvider.$inject = [ 'eventBus', - 'canvas', 'directEditing', 'commandStack', 'modeling' diff --git a/app/spiffworkflow/DataObject/index.js b/app/spiffworkflow/DataObject/index.js index 703642a..0c0ab14 100644 --- a/app/spiffworkflow/DataObject/index.js +++ b/app/spiffworkflow/DataObject/index.js @@ -5,12 +5,11 @@ import DataObjectRenderer from './DataObjectRenderer'; import DataObjectPropertiesProvider from './propertiesPanel/DataObjectPropertiesProvider'; import DataObjectLabelEditingProvider from './DataObjectLabelEditingProvider'; - export default { __depends__: [ RulesModule ], - __init__: [ 'dataInterceptor', 'dataObjectRules', 'dataObjectRenderer', 'dataObjectPropertiesProvider' ], + __init__: [ 'dataInterceptor', 'dataObjectRules', 'dataObjectRenderer', 'dataObjectPropertiesProvider', 'dataObjectLabelEditingProvider' ], dataInterceptor: [ 'type', DataObjectInterceptor ], dataObjectRules: [ 'type', DataObjectRules ], dataObjectRenderer: [ 'type', DataObjectRenderer ],