spiff-arena/bpmn-js-spiffworkflow/app/spiffworkflow/eventList.js

164 lines
4.5 KiB
JavaScript
Raw Normal View History

Squashed 'bpmn-js-spiffworkflow/' changes from 0a9db509a..9dcca6c80 9dcca6c80 Merge pull request #39 from sartography/message_fixes 9de4d9a2e update github action for tests. 84183ffd3 we weren't setting the property when updating a start event. 66a26cc85 does adding a new check prevent an error that only seems to happen whenthe frontend is engaged 877424a55 Merge pull request #37 from sartography/bugfix/bugfixes-for-mi-and-payloads afb071d01 apparently didn't finish search and replace when creating the escalation panels c8040aab5 remove unused MI attributes from XML 1bc43155d Merge pull request #34 from sartography/dependabot/github_actions/dependabot/fetch-metadata-1.6.0 a645c08f5 Merge pull request #36 from sartography/feature/events-with-payloads 8e0f84fbe Merge pull request #35 from sartography/bug/data_objects_in_pools 4b732edd3 add events with payloads 3247a197c update event select to include code field 91e012582 add generic event selector 021f53bb5 add generic event list b19c69080 Assure we delete reference objects when the visible entity is removed. And remove all those console.logs. d46741ffd A few more fixes to prevent bugs from showing up later ... * Deleting a pool was erroring out when it contained a list of data objects, now it works ok. * We were getting duplicate DataObjectReferences in the XML when doing a copy paste operation. Duplicates are no longer generated. f40cecc05 * Assure that Data object in pools can be changed to reference other data objects within the same pool. * In the runnable demo, add the keyboard bindings to copy/paste/delete etc... work. * Added a test for data objects in pools. 2f835fc7f Bump dependabot/fetch-metadata from 1.4.0 to 1.6.0 f6a79440e Merge pull request #33 from sartography/bugfix/restore-references-without-breaking-messages 2556a4599 better method for fixing references 5c49d665f Merge pull request #32 from sartography/bugfix/add-mi-to-subprocess e138c4c26 add mi panel to subprocesses 462a5e777 Merge pull request #27 from sartography/feature/multi-instance-task-panel 63dc415fc add MI for call activities 61f2e5db3 add custom importer to handle loop input/output e504af9bb add multi instance configuration panel git-subtree-dir: bpmn-js-spiffworkflow git-subtree-split: 9dcca6c80b8ab8ed0d79658456047b90e8483541
2023-08-09 20:14:32 +00:00
import { is } from 'bpmn-js/lib/util/ModelUtil';
import { useService } from 'bpmn-js-properties-panel';
import {
ListGroup,
TextFieldEntry,
isTextFieldEntryEdited
} from '@bpmn-io/properties-panel';
import { getRoot } from './helpers';
/* This function creates a list of a particular event type at the process level using the item list
* and add function provided by `getArray`.
*
* Usage:
* const getArray = getArrayForType('bpmn:Signal', 'signalRef', 'Signal');
* const signalGroup = createGroupForType('signals', 'Signals', getArray);
*/
function getListGroupForType(groupId, label, getArray) {
return function (props) {
const { element, translate, moddle, commandStack } = props;
const eventArray = {
id: groupId,
element,
label: label,
component: ListGroup,
...getArray({ element, moddle, commandStack, translate }),
};
if (eventArray.items) {
return eventArray;
}
}
}
function getArrayForType(itemType, referenceType, prefix) {
return function (props) {
const { element, moddle, commandStack, translate } = props;
const root = getRoot(element.businessObject);
const matching = root.rootElements ? root.rootElements.filter(elem => elem.$type === itemType) : [];
function removeModelReferences(flowElements, match) {
flowElements.map(elem => {
if (elem.eventDefinitions)
elem.eventDefinitions = elem.eventDefinitions.filter(def => def.get(referenceType) != match);
else if (elem.flowElements)
removeModelReferences(elem.flowElements, match);
});
}
function removeElementReferences(children, match) {
children.map(child => {
if (child.businessObject.eventDefinitions) {
const bo = child.businessObject;
bo.eventDefinitions = bo.eventDefinitions.filter(def => def.get(referenceType) != match);
commandStack.execute('element.updateProperties', {
element: child,
moddleElement: bo,
properties: {}
});
}
if (child.children)
removeElementReferences(child.children, match);
});
}
function removeFactory(item) {
return function (event) {
event.stopPropagation();
if (root.rootElements) {
root.rootElements = root.rootElements.filter(elem => elem != item);
// This updates visible elements
removeElementReferences(element.children, item);
// This handles everything else (eg collapsed subprocesses) but does not update the shapes
// I can't figure out how to do that
root.rootElements.filter(elem => elem.$type === 'bpmn:Process').map(
process => removeModelReferences(process.flowElements, item)
);
commandStack.execute('element.updateProperties', {
element,
properties: {},
});
}
}
}
const items = matching.map((item, idx) => {
const itemId = `${prefix}-${idx}`;
return {
id: itemId,
label: item.name,
entries: getItemEditor({
itemId,
element,
item,
commandStack,
translate,
}),
autoFocusEntry: itemId,
remove: removeFactory(item),
};
});
function add(event) {
event.stopPropagation();
const item = moddle.create(itemType);
item.id = moddle.ids.nextPrefixed(`${prefix}_`);
item.name = item.id;
if (root.rootElements)
root.rootElements.push(item);
commandStack.execute('element.updateProperties', {
element,
properties: {},
});
};
return { items, add };
}
}
function getItemEditor(props) {
const { itemId, element, item, commandStack, translate } = props;
return [
{
id: `${itemId}-name`,
component: ItemTextField,
item,
commandStack,
translate,
},
];
}
function ItemTextField(props) {
const { itemId, element, item, commandStack, translate } = props;
const debounce = useService('debounceInput');
const setValue = (value) => {
commandStack.execute('element.updateModdleProperties', {
element,
moddleElement: item,
properties: {
id: value,
name: value,
},
});
};
const getValue = () => { return item.id; }
return TextFieldEntry({
element,
id: `${itemId}-id-textField`,
label: translate('ID'),
getValue,
setValue,
debounce,
});
}
export { getArrayForType, getListGroupForType };