Skip to content

Commit

Permalink
feat(zeebe): add _Version tag_ field to linked resources
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Aug 23, 2024
1 parent 8acfcd4 commit 8ed7ddc
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 50 deletions.
41 changes: 33 additions & 8 deletions src/contextProvider/zeebe/TooltipProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,41 @@ const TooltipProvider = {
);
},
'versionTag': (element) => {

const translate = useService('translate');

return (
<div>
<p>
{ translate('Specifying a version tag will allow you to reference this process in another process.') }
</p>
</div>
);
if (is(element, 'bpmn:Process')) {
return (
<div>
<p>
{ translate('Version tag by which this process can be referenced.') }
</p>
</div>
);
} else if (is(element, 'bpmn:CallActivity')) {
return (
<div>
<p>
{ translate('Version tag by which the called process will be referenced.') }
</p>
</div>
);
} else if (is(element, 'bpmn:BusinessRuleTask')) {
return (
<div>
<p>
{ translate('Version tag by which the called decision will be referenced.') }
</p>
</div>
);
} else if (is(element, 'bpmn:UserTask')) {
return (
<div>
<p>
{ translate('Version tag by which the linked form will be referenced.') }
</p>
</div>
);
}
},
'priorityDefinitionPriority': (element) => {

Expand Down
26 changes: 19 additions & 7 deletions src/provider/zeebe/properties/CalledDecisionProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
TextFieldEntry
} from '@bpmn-io/properties-panel';

import Binding from './shared/Binding';
import Binding, { getBindingType } from './shared/Binding';
import VersionTag from './shared/VersionTag.js';

import {
getExtensionElementsList
Expand All @@ -36,7 +37,7 @@ export function CalledDecisionProps(props) {
return [];
}

return [
const entries = [
{
id: 'decisionId',
component: DecisionID,
Expand All @@ -46,13 +47,24 @@ export function CalledDecisionProps(props) {
id: 'bindingType',
component: withProps(Binding, { type: 'zeebe:CalledDecision' }),
isEdited: isSelectEntryEdited
},
{
id: 'resultVariable',
component: ResultVariable,
isEdited: isTextFieldEntryEdited
}
];

if (getBindingType(element, 'zeebe:CalledDecision') === 'versionTag') {
entries.push({
id: 'versionTag',
component: withProps(VersionTag, { type: 'zeebe:CalledDecision' }),
isEdited: isTextFieldEntryEdited
});
}

entries.push({
id: 'resultVariable',
component: ResultVariable,
isEdited: isTextFieldEntryEdited
});

return entries;
}

function DecisionID(props) {
Expand Down
11 changes: 10 additions & 1 deletion src/provider/zeebe/properties/FormProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
isTextAreaEntryEdited
} from '@bpmn-io/properties-panel';

import Binding from './shared/Binding';
import Binding, { getBindingType } from './shared/Binding';
import VersionTag from './shared/VersionTag';

import { FeelEntryWithVariableContext } from '../../../entries/FeelEntryWithContext';

Expand Down Expand Up @@ -89,6 +90,14 @@ export function FormProps(props) {
component: withProps(Binding, { type: 'zeebe:FormDefinition' }),
isEdited: isSelectEntryEdited
});

if (getBindingType(element, 'zeebe:FormDefinition') === 'versionTag') {
entries.push({
id: 'versionTag',
component: withProps(VersionTag, { type: 'zeebe:FormDefinition' }),
isEdited: isTextFieldEntryEdited
});
}
}

return entries;
Expand Down
18 changes: 15 additions & 3 deletions src/provider/zeebe/properties/TargetProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {

import {
isFeelEntryEdited,
isSelectEntryEdited
isSelectEntryEdited,
isTextFieldEntryEdited
} from '@bpmn-io/properties-panel';

import Binding from './shared/Binding';
import Binding, { getBindingType } from './shared/Binding';
import VersionTag from './shared/VersionTag.js';

import {
createElement
Expand All @@ -35,7 +37,7 @@ export function TargetProps(props) {
return [];
}

return [
const entries = [
{
id: 'targetProcessId',
component: TargetProcessId,
Expand All @@ -47,6 +49,16 @@ export function TargetProps(props) {
isEdited: isSelectEntryEdited
}
];

if (getBindingType(element, 'zeebe:CalledElement') === 'versionTag') {
entries.push({
id: 'versionTag',
component: withProps(VersionTag, { type: 'zeebe:CalledElement' }),
isEdited: isTextFieldEntryEdited
});
}

return entries;
}

function TargetProcessId(props) {
Expand Down
27 changes: 15 additions & 12 deletions src/provider/zeebe/properties/shared/Binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ export default function Binding(props) {
commandStack = useService('commandStack'),
translate = useService('translate');

const getValue = () => {
const businessObject = getBusinessObject(element);

const extensionElement = getExtensionElementsList(businessObject, type)[ 0 ];

if (!extensionElement) {
return 'latest';
}

return extensionElement.get('bindingType');
};
const getValue = () => getBindingType(element, type);

const setValue = value => {
const commands = [];
Expand Down Expand Up @@ -98,7 +88,8 @@ export default function Binding(props) {

const getOptions = () => ([
{ value: 'latest', label: translate('latest') },
{ value: 'deployment', label: translate('deployment') }
{ value: 'deployment', label: translate('deployment') },
{ value: 'versionTag', label: translate('version tag') }
]);

return <SelectEntry
Expand All @@ -109,4 +100,16 @@ export default function Binding(props) {
setValue={ setValue }
getOptions={ getOptions }
/>;
}

export function getBindingType(element, type) {
const businessObject = getBusinessObject(element);

const extensionElement = getExtensionElementsList(businessObject, type)[ 0 ];

if (!extensionElement) {
return 'latest';
}

return extensionElement.get('bindingType');
}
110 changes: 110 additions & 0 deletions src/provider/zeebe/properties/shared/VersionTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';

import { TextFieldEntry } from '@bpmn-io/properties-panel';

import { createElement } from '../../../../utils/ElementUtil';

import { useService } from '../../../../hooks';

import { getExtensionElementsList } from '../../../../utils/ExtensionElementsUtil';

export default function VersionTag(props) {
const {
element,
type
} = props;

const bpmnFactory = useService('bpmnFactory'),
commandStack = useService('commandStack'),
debounce = useService('debounceInput'),
translate = useService('translate');

const getValue = () => getVersionTag(element, type);

const setValue = value => {
const commands = [];

const businessObject = getBusinessObject(element);

// (1) ensure extension elements
let extensionElements = businessObject.get('extensionElements');

if (!extensionElements) {
extensionElements = createElement(
'bpmn:ExtensionElements',
{ values: [] },
businessObject,
bpmnFactory
);

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

// (2) ensure extension element
let extensionElement = getExtensionElementsList(businessObject, type)[ 0 ];

if (!extensionElement) {
extensionElement = createElement(
type,
{},
extensionElements,
bpmnFactory
);

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: extensionElements,
properties: {
values: [ ...extensionElements.get('values'), extensionElement ]
}
}
});

}

// (3) Update versionTag attribute
commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: extensionElement,
properties: {
versionTag: value
}
}
});

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

return TextFieldEntry({
element,
id: 'versionTag',
label: translate('Version tag'),
getValue,
setValue,
debounce
});
}

export function getVersionTag(element, type) {
const businessObject = getBusinessObject(element);

const extensionElement = getExtensionElementsList(businessObject, type)[ 0 ];

if (!extensionElement) {
return '';
}

return extensionElement.get('versionTag') || '';
}
8 changes: 6 additions & 2 deletions test/spec/provider/zeebe/CalledDecisionProps.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<zeebe:calledDecision decisionId="myDecisionId" resultVariable="myResultVariable" />
</bpmn:extensionElements>
</bpmn:businessRuleTask>
<bpmn:businessRuleTask id="BusinessRuleTask_2" name="BusinessRuleTask_2" />
<bpmn:businessRuleTask id="BusinessRuleTask_2" name="BusinessRuleTask_2">
<bpmn:extensionElements>
<zeebe:calledDecision decisionId="myDecisionId" resultVariable="myResultVariable" bindingType="versionTag" versionTag="v1.0.0" />
</bpmn:extensionElements>
</bpmn:businessRuleTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0mgn9vm">
Expand All @@ -22,4 +26,4 @@
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
</bpmn:definitions>
Loading

0 comments on commit 8ed7ddc

Please sign in to comment.