-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
365 additions
and
65 deletions.
There are no files selected for viewing
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
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,87 @@ | ||
import { SelectEntry } from '@bpmn-io/properties-panel'; | ||
|
||
import { | ||
useService | ||
} from '../../../hooks'; | ||
|
||
import { ListenerType, Retries } from './shared/Listener'; | ||
|
||
export const EVENT_TYPE = [ 'complete', 'assigned' ]; | ||
|
||
export const EVENT_TO_LABEL = { | ||
complete: 'Complete', | ||
assigned: 'Assigned' | ||
}; | ||
|
||
export function TaskListenerEntries(props) { | ||
|
||
const { | ||
idPrefix, | ||
listener | ||
} = props; | ||
|
||
const entries = EVENT_TYPE.length > 1 ? [ | ||
{ | ||
id: idPrefix + '-eventType', | ||
component: EventType, | ||
idPrefix, | ||
listener, | ||
eventTypes: EVENT_TYPE | ||
} | ||
] : []; | ||
|
||
entries.push({ | ||
id: idPrefix + '-listenerType', | ||
component: ListenerType, | ||
idPrefix, | ||
listener | ||
}, | ||
{ | ||
id: idPrefix + '-retries', | ||
component: Retries, | ||
idPrefix, | ||
listener | ||
}); | ||
|
||
return entries; | ||
} | ||
|
||
function EventType(props) { | ||
const { | ||
idPrefix, | ||
element, | ||
listener, | ||
eventTypes | ||
} = props; | ||
|
||
const modeling = useService('modeling'); | ||
const translate = useService('translate'); | ||
|
||
const getOptions = () => { | ||
return eventTypes.map(eventType => ({ | ||
value: eventType, | ||
label: translate(EVENT_TO_LABEL[eventType]) | ||
})); | ||
}; | ||
|
||
const setValue = (value) => { | ||
modeling.updateModdleProperties(element, listener, { | ||
eventType: value | ||
}); | ||
}; | ||
|
||
const getValue = () => { | ||
return listener.get('eventType'); | ||
}; | ||
|
||
return SelectEntry({ | ||
element, | ||
id: idPrefix + '-eventType', | ||
label: translate('Event type'), | ||
getValue, | ||
setValue, | ||
getOptions | ||
}); | ||
} | ||
|
||
|
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,191 @@ | ||
import { | ||
getBusinessObject, | ||
is, | ||
isAny | ||
} from 'bpmn-js/lib/util/ModelUtil'; | ||
|
||
import { without } from 'min-dash'; | ||
|
||
import { TaskListenerEntries, EVENT_TYPE, EVENT_TO_LABEL } from './TaskListener'; | ||
|
||
import { | ||
createElement | ||
} from '../../../utils/ElementUtil'; | ||
|
||
import { | ||
getExtensionElementsList | ||
} from '../../../utils/ExtensionElementsUtil'; | ||
|
||
import { isZeebeUserTask } from '../utils/FormUtil'; | ||
|
||
|
||
export function TaskListenersProps({ element, injector }) { | ||
let businessObject = getRelevantBusinessObject(element); | ||
|
||
// not allowed in empty pools | ||
if (!businessObject) { | ||
return; | ||
} | ||
|
||
if (!isZeebeUserTask(element)) { | ||
return; | ||
} | ||
|
||
const moddle = injector.get('moddle'); | ||
if (!canHaveTaskListeners(businessObject, moddle)) { | ||
return; | ||
} | ||
|
||
const listeners = getListenersList(businessObject) || []; | ||
|
||
const bpmnFactory = injector.get('bpmnFactory'), | ||
commandStack = injector.get('commandStack'), | ||
modeling = injector.get('modeling'), | ||
translate = injector.get('translate'); | ||
|
||
const items = listeners.map((listener, index) => { | ||
const id = element.id + '-TaskListener-' + index; | ||
const type = listener.get('type') || '<no type>'; | ||
|
||
return { | ||
id, | ||
label: translate(`${EVENT_TO_LABEL[listener.get('eventType')]}: {type}`, { type }), | ||
entries: TaskListenerEntries({ | ||
idPrefix: id, | ||
listener | ||
}), | ||
autoFocusEntry: id + '-eventType', | ||
remove: removeFactory({ modeling, element, listener }) | ||
}; | ||
}); | ||
|
||
return { | ||
items, | ||
add: addFactory({ bpmnFactory, commandStack, element }) | ||
}; | ||
} | ||
|
||
function removeFactory({ modeling, element, listener }) { | ||
return function(event) { | ||
event.stopPropagation(); | ||
|
||
const businessObject = getRelevantBusinessObject(element); | ||
const container = getTaskListenersContainer(businessObject); | ||
|
||
if (!container) { | ||
return; | ||
} | ||
|
||
const listeners = without(container.get('listeners'), listener); | ||
|
||
modeling.updateModdleProperties(element, container, { listeners }); | ||
}; | ||
} | ||
|
||
function addFactory({ bpmnFactory, commandStack, element }) { | ||
return function(event) { | ||
event.stopPropagation(); | ||
|
||
let commands = []; | ||
|
||
const businessObject = getRelevantBusinessObject(element); | ||
|
||
let extensionElements = businessObject.get('extensionElements'); | ||
|
||
// (1) ensure extension elements | ||
if (!extensionElements) { | ||
extensionElements = createElement( | ||
'bpmn:ExtensionElements', | ||
{ values: [] }, | ||
businessObject, | ||
bpmnFactory | ||
); | ||
|
||
commands.push({ | ||
cmd: 'element.updateModdleProperties', | ||
context: { | ||
element, | ||
moddleElement: businessObject, | ||
properties: { extensionElements } | ||
} | ||
}); | ||
} | ||
|
||
// (2) ensure zeebe:TaskListeners | ||
let TaskListeners = getTaskListenersContainer(businessObject); | ||
|
||
if (!TaskListeners) { | ||
const parent = extensionElements; | ||
|
||
TaskListeners = createElement('zeebe:TaskListeners', { | ||
listeners: [] | ||
}, parent, bpmnFactory); | ||
|
||
commands.push({ | ||
cmd: 'element.updateModdleProperties', | ||
context: { | ||
element, | ||
moddleElement: extensionElements, | ||
properties: { | ||
values: [ ...extensionElements.get('values'), TaskListeners ] | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// (3) create zeebe:TaskListener | ||
const TaskListener = createElement( | ||
'zeebe:TaskListener', EVENT_TYPE[0], TaskListeners, bpmnFactory | ||
); | ||
|
||
// (4) add TaskListener to list | ||
commands.push({ | ||
cmd: 'element.updateModdleProperties', | ||
context: { | ||
element, | ||
moddleElement: TaskListeners, | ||
properties: { | ||
listeners: [ ...TaskListeners.get('listeners'), TaskListener ] | ||
} | ||
} | ||
}); | ||
|
||
// (5) commit all updates | ||
commandStack.execute('properties-panel.multi-command-executor', commands); | ||
}; | ||
} | ||
|
||
|
||
// helper ////////////////// | ||
|
||
function getRelevantBusinessObject(element) { | ||
let businessObject = getBusinessObject(element); | ||
|
||
if (is(element, 'bpmn:Participant')) { | ||
return businessObject.get('processRef'); | ||
} | ||
|
||
return businessObject; | ||
} | ||
|
||
function getTaskListenersContainer(element) { | ||
const TaskListeners = getExtensionElementsList(element, 'zeebe:TaskListeners'); | ||
|
||
return TaskListeners && TaskListeners[0]; | ||
} | ||
|
||
function getListenersList(element) { | ||
const TaskListeners = getTaskListenersContainer(element); | ||
|
||
return TaskListeners && TaskListeners.get('listeners'); | ||
} | ||
|
||
function canHaveTaskListeners(bo, moddle) { | ||
const TaskListenersDescriptor = moddle.getTypeDescriptor('zeebe:TaskListeners'); | ||
|
||
if (!isAny(bo, TaskListenersDescriptor.meta.allowedIn)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
Oops, something went wrong.