Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improved data object naming #46

Merged
merged 13 commits into from
Nov 22, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ export function findDataReferenceShapes(processShape, id) {
}
return refs;
}

export function idToHumanReadableName(id) {
const words = id.match(/[A-Za-z][a-z]*/g) || [];
return words.map(capitalize).join(' ');

function capitalize(word) {
return word.charAt(0).toUpperCase() + word.substring(1);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
import {getDi, is} from 'bpmn-js/lib/util/ModelUtil';
import {findDataObjects, findDataReferenceShapes} from './DataObjectHelpers';
import {findDataObjects, findDataReferenceShapes, idToHumanReadableName} from './DataObjectHelpers';
var HIGH_PRIORITY = 1500;
import {
remove as collectionRemove,
Expand Down Expand Up @@ -49,7 +49,7 @@ export default class DataObjectInterceptor extends CommandInterceptor {
}

// Update the name of the reference to match the data object's id.
shape.businessObject.name = dataObject.id;
shape.businessObject.name = idToHumanReadableName(dataObject.id);

// set the reference to the DataObject
shape.businessObject.dataObjectRef = dataObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@bpmn-io/properties-panel';
import { without } from 'min-dash';
import { is } from 'bpmn-js/lib/util/ModelUtil';
import { findDataObjects, findDataReferenceShapes } from '../DataObjectHelpers';
import {findDataObjects, findDataReferenceShapes, idToHumanReadableName} from '../DataObjectHelpers';

/**
* Provides a list of data objects, and allows you to add / remove data objects, and change their ids.
Expand Down Expand Up @@ -129,7 +129,7 @@ function DataObjectTextField(props) {
element: ref,
moddleElement: ref.businessObject,
properties: {
name: value,
name: idToHumanReadableName(value),
},
changed: [ref], // everything is already marked as changed, don't recalculate.
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {useService } from 'bpmn-js-properties-panel';
import { SelectEntry } from '@bpmn-io/properties-panel';
import {idToHumanReadableName} from '../DataObjectHelpers';

/**
* Finds the value of the given type within the extensionElements
Expand Down Expand Up @@ -43,7 +44,7 @@ export function DataObjectSelect(props) {
element,
moddleElement: businessObject,
properties: {
'name': flowElem.id
'name': idToHumanReadableName(flowElem.id)
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions bpmn-js-spiffworkflow/test/spec/DataObjectInterceptorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BpmnPropertiesPanelModule, BpmnPropertiesProviderModule } from 'bpmn-js
import {
inject,
} from 'bpmn-js/test/helper';
import { findDataObjects } from '../../app/spiffworkflow/DataObject/DataObjectHelpers';
import {findDataObjects, idToHumanReadableName} from '../../app/spiffworkflow/DataObject/DataObjectHelpers';

describe('DataObject Interceptor', function() {

Expand Down Expand Up @@ -93,7 +93,8 @@ describe('DataObject Interceptor', function() {
{ x: 220, y: 220 }, rootShape);

const dataObjects = findDataObjects(rootShape.businessObject);
expect(dataObjectRefShape1.businessObject.name).to.equal(dataObjects[0].id);
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) {
Expand Down
2 changes: 1 addition & 1 deletion bpmn-js-spiffworkflow/test/spec/DataObjectPropsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Properties Panel for Data Objects', function() {

// 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');
expect(my_data_ref_1.businessObject.name).to.equal('My Nifty New Name');
});

});