Skip to content

Commit

Permalink
feat(zeebe): add _Version tag_ field
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme authored and nikku committed Aug 26, 2024
1 parent d2cd2ca commit dbb2291
Show file tree
Hide file tree
Showing 19 changed files with 855 additions and 145 deletions.
245 changes: 117 additions & 128 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"dev": "npm test -- --auto-watch --no-single-run",
"test": "karma start karma.config.js",
"test:build": "mocha --reporter=spec --recursive test/distro",
"start": "cross-env SINGLE_START=platform npm run dev",
"start": "npm run start:cloud",
"start:cloud": "cross-env SINGLE_START=cloud npm run dev",
"start:platform": "cross-env SINGLE_START=platform npm run dev",
"start:dmn": "cross-env SINGLE_START=dmn npm run dev",
"prepare": "run-s bundle"
Expand Down Expand Up @@ -62,9 +63,9 @@
"camunda-dmn-moddle": "^1.3.0",
"chai": "^4.4.1",
"cross-env": "^7.0.3",
"dmn-js": "^16.4.0",
"dmn-js-drd": "^16.4.0",
"dmn-js-shared": "^16.4.0",
"dmn-js": "^16.6.0",
"dmn-js-drd": "^16.6.0",
"dmn-js-shared": "^16.5.0",
"eslint": "^8.57.0",
"eslint-plugin-bpmn-io": "^1.0.0",
"eslint-plugin-import": "^2.29.1",
Expand All @@ -85,7 +86,8 @@
"rollup-plugin-copy": "^3.4.0",
"sinon": "^17.0.1",
"sinon-chai": "^3.7.0",
"webpack": "^5.92.1"
"webpack": "^5.92.1",
"zeebe-dmn-moddle": "^1.0.0"
},
"peerDependencies": {
"@bpmn-io/properties-panel": ">=3.7",
Expand Down
25 changes: 25 additions & 0 deletions src/cmd/MultiCommandHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
forEach
} from 'min-dash';

/**
* A handler that combines and executes multiple commands.
*
* All updates are bundled on the command stack and executed in one step.
* This also makes it possible to revert the changes in one step.
*/
export default class MultiCommandHandler {
constructor(commandStack) {
this._commandStack = commandStack;
}

preExecute(context) {
const commandStack = this._commandStack;

forEach(context, function(command) {
commandStack.execute(command.cmd, command.context);
});
}
}

MultiCommandHandler.$inject = [ 'commandStack' ];
25 changes: 25 additions & 0 deletions src/cmd/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
forEach
} from 'min-dash';

import MultiCommandHandler from './MultiCommandHandler';

const HANDLERS = {
'properties-panel.multi-command-executor': MultiCommandHandler
};


function CommandInitializer(eventBus, commandStack) {

eventBus.on('diagram.init', function() {
forEach(HANDLERS, function(handler, id) {
commandStack.registerHandler(id, handler);
});
});
}

CommandInitializer.$inject = [ 'eventBus', 'commandStack' ];

export default {
__init__: [ CommandInitializer ]
};
21 changes: 21 additions & 0 deletions src/contextProvider/zeebe/TooltipProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable react-hooks/rules-of-hooks */
import {
useService
} from '../../hooks';

const TooltipProvider = {
'versionTag': (element) => {

const translate = useService('translate');

return (
<div>
<p>
{ translate('Version tag by which this decision can be referenced.') }
</p>
</div>
);
}
};

export default TooltipProvider;
1 change: 1 addition & 0 deletions src/contextProvider/zeebe/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as TooltipProvider } from './TooltipProvider';
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ export { default as DmnPropertiesPanelModule } from './render';
export { default as DmnPropertiesProviderModule } from './provider/dmn';
export { default as CamundaPropertiesProviderModule } from './provider/camunda';

export { TooltipProvider as ZeebeTooltipProvider } from './contextProvider/zeebe';

// hooks
export { useService } from './hooks';
12 changes: 12 additions & 0 deletions src/provider/utils/ElementUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Create a new element and (optionally) set its parent.
*/
export function createElement(type, properties, parent, dmnFactory) {
const element = dmnFactory.create(type, properties);

if (parent) {
element.$parent = parent;
}

return element;
}
96 changes: 96 additions & 0 deletions src/provider/utils/ExtensionElementsUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { is } from 'dmn-js-shared/lib/util/ModelUtil';

import { createElement } from './ElementUtil';

import { isArray } from 'min-dash';

/**
* Get extension elements of business object. Optionally filter by type.
*/
export function getExtensionElementsList(businessObject, type = undefined) {
const extensionElements = businessObject.get('extensionElements');

if (!extensionElements) {
return [];
}

const values = extensionElements.get('values');

if (!values || !values.length) {
return [];
}

if (type) {
return values.filter(value => is(value, type));
}

return values;
}

/**
* Add one or more extension elements. Create dmn:ExtensionElements if it doesn't exist.
*/
export function addExtensionElements(element, businessObject, extensionElementToAdd, dmnFactory, commandStack) {
const commands = [];

let extensionElements = businessObject.get('extensionElements');

// (1) create dmn:ExtensionElements if it doesn't exist
if (!extensionElements) {
extensionElements = createElement(
'dmn:ExtensionElements',
{
values: []
},
businessObject,
dmnFactory
);

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: businessObject,
properties: {
extensionElements
}
}
});
}

extensionElementToAdd.$parent = extensionElements;

// (2) add extension element to list
commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: extensionElements,
properties: {
values: [ ...extensionElements.get('values'), extensionElementToAdd ]
}
}
});

commandStack.execute('properties-panel.multi-command-executor', commands);
}

/**
* Remove one or more extension elements. Remove dmn:ExtensionElements afterwards if it's empty.
*/
export function removeExtensionElements(element, businessObject, extensionElementsToRemove, commandStack) {
if (!isArray(extensionElementsToRemove)) {
extensionElementsToRemove = [ extensionElementsToRemove ];
}

const extensionElements = businessObject.get('extensionElements'),
values = extensionElements.get('values').filter(value => !extensionElementsToRemove.includes(value));

commandStack.execute('element.updateModdleProperties', {
element,
moddleElement: extensionElements,
properties: {
values
}
});
}
73 changes: 73 additions & 0 deletions src/provider/zeebe/ZeebePropertiesProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { findIndex } from 'min-dash';

import {
VersionTagProps
} from './properties';


const LOW_PRIORITY = 500;

/**
* Provides `zeebe` namespace properties.
*
* @example
* ```javascript
* import DmnModeler from 'dmn-js/lib/Modeler';
* import {
* DmnPropertiesPanelModule,
* DmnPropertiesProviderModule,
* ZeebePropertiesProviderModule
* } from 'dmn-js-properties-panel';
*
* const modeler = new DmnModeler({
* container: '#canvas',
* propertiesPanel: {
* parent: '#properties'
* },
* additionalModules: [
* DmnPropertiesPanelModule,
* DmnPropertiesProviderModule,
* ZeebePropertiesProviderModule
* ]
* });
* ```
*/
export default class ZeebePropertiesProvider {

constructor(propertiesPanel, injector) {
propertiesPanel.registerProvider(LOW_PRIORITY, this);

this._injector = injector;
}

getGroups(element) {
return (groups) => {
updateGeneralGroup(groups, element);

return groups;
};
}
}

ZeebePropertiesProvider.$inject = [ 'propertiesPanel', 'injector' ];

function updateGeneralGroup(groups, element) {

const generalGroup = findGroup(groups, 'general');

if (!generalGroup) {
return;
}

const { entries } = generalGroup;

const idIndex = findIndex(entries, (entry) => entry.id === 'id');

entries.splice(idIndex + 1, 0, ...VersionTagProps({ element }));
}

// helper /////////////////////

function findGroup(groups, id) {
return groups.find(g => g.id === id);
}
6 changes: 6 additions & 0 deletions src/provider/zeebe/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import ZeebePropertiesProvider from './ZeebePropertiesProvider';

export default {
__init__: [ 'ZeebePropertiesProvider' ],
ZeebePropertiesProvider: [ 'type', ZeebePropertiesProvider ]
};
Loading

0 comments on commit dbb2291

Please sign in to comment.