2022-10-31 20:20:05 +00:00
|
|
|
import { SelectEntry } from '@bpmn-io/properties-panel';
|
|
|
|
import { useService } from 'bpmn-js-properties-panel';
|
|
|
|
import {
|
2022-11-01 14:35:07 +00:00
|
|
|
getExtensionValue,
|
2022-11-02 00:24:28 +00:00
|
|
|
setExtensionValue,
|
2022-10-31 20:20:05 +00:00
|
|
|
} from '../extensionHelpers';
|
|
|
|
|
2023-09-06 21:38:38 +00:00
|
|
|
export const spiffExtensionOptions = {};
|
2022-10-31 20:20:05 +00:00
|
|
|
|
|
|
|
export const OPTION_TYPE = {
|
2023-09-06 21:38:38 +00:00
|
|
|
json_schema_files: 'json_schema_files',
|
2022-11-02 00:35:29 +00:00
|
|
|
dmn_files: 'dmn_files',
|
2022-10-31 20:20:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow selecting an option from a list of available options, and setting
|
|
|
|
* the name and value of a SpiffWorkflow Property to the one selected in the
|
|
|
|
* dropdown list.
|
|
|
|
* The list of options must be provided by the containing library - by responding
|
|
|
|
* to a request passed to the eventBus.
|
2022-11-02 00:35:29 +00:00
|
|
|
* When needed, the event "spiff.${optionType}.requested" will be fired.
|
|
|
|
* The response should be sent to "spiff.${optionType}.returned". The response
|
2022-10-31 20:20:05 +00:00
|
|
|
* event should include an 'options' attribute that is list of labels and values:
|
|
|
|
* [ { label: 'Product Prices DMN', value: 'Process_16xfaqc' } ]
|
|
|
|
*/
|
|
|
|
export function SpiffExtensionSelect(props) {
|
|
|
|
const { element } = props;
|
|
|
|
const { commandStack } = props;
|
|
|
|
const { moddle } = props;
|
|
|
|
const { label, description } = props;
|
|
|
|
|
|
|
|
const { name } = props;
|
|
|
|
const { optionType } = props;
|
|
|
|
|
|
|
|
const debounce = useService('debounceInput');
|
|
|
|
const eventBus = useService('eventBus');
|
|
|
|
|
|
|
|
const getValue = () => {
|
2022-11-01 14:35:07 +00:00
|
|
|
return getExtensionValue(element, name);
|
2022-10-31 20:20:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const setValue = (value) => {
|
2022-11-02 00:24:28 +00:00
|
|
|
setExtensionValue(element, name, value, moddle, commandStack);
|
2022-10-31 20:20:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (
|
|
|
|
!(optionType in spiffExtensionOptions) ||
|
2022-11-09 16:39:57 +00:00
|
|
|
spiffExtensionOptions[optionType] === null
|
2022-10-31 20:20:05 +00:00
|
|
|
) {
|
2022-11-09 16:39:57 +00:00
|
|
|
spiffExtensionOptions[optionType] = null;
|
2022-10-31 20:20:05 +00:00
|
|
|
requestOptions(eventBus, element, commandStack, optionType);
|
|
|
|
}
|
|
|
|
const getOptions = () => {
|
|
|
|
const optionList = [];
|
2023-09-06 21:38:38 +00:00
|
|
|
optionList.push({
|
|
|
|
label: '',
|
|
|
|
value: '',
|
|
|
|
});
|
2022-11-16 21:31:47 +00:00
|
|
|
if (
|
|
|
|
optionType in spiffExtensionOptions &&
|
|
|
|
spiffExtensionOptions[optionType] !== null
|
|
|
|
) {
|
2022-10-31 20:20:05 +00:00
|
|
|
spiffExtensionOptions[optionType].forEach((opt) => {
|
|
|
|
optionList.push({
|
|
|
|
label: opt.label,
|
|
|
|
value: opt.value,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return optionList;
|
|
|
|
};
|
|
|
|
|
|
|
|
return SelectEntry({
|
|
|
|
id: `extension_${name}`,
|
|
|
|
element,
|
|
|
|
label,
|
|
|
|
description,
|
|
|
|
getValue,
|
|
|
|
setValue,
|
|
|
|
getOptions,
|
|
|
|
debounce,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function requestOptions(eventBus, element, commandStack, optionType) {
|
|
|
|
// Little backwards, but you want to assure you are ready to catch, before you throw
|
|
|
|
// or you risk a race condition.
|
2023-09-06 21:38:38 +00:00
|
|
|
eventBus.on(`spiff.${optionType}.returned`, (event) => {
|
2022-10-31 20:20:05 +00:00
|
|
|
spiffExtensionOptions[optionType] = event.options;
|
|
|
|
});
|
2022-11-02 00:35:29 +00:00
|
|
|
eventBus.fire(`spiff.${optionType}.requested`, { eventBus });
|
2022-10-31 20:20:05 +00:00
|
|
|
}
|