-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zeebe): add _Version tag_ field
Related to camunda/camunda-modeler#4454
- Loading branch information
1 parent
d2cd2ca
commit dbb2291
Showing
19 changed files
with
855 additions
and
145 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as TooltipProvider } from './TooltipProvider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] | ||
}; |
Oops, something went wrong.