2022-08-17 16:55:14 +00:00
|
|
|
import { useService } from 'bpmn-js-properties-panel';
|
|
|
|
import { TextFieldEntry } from '@bpmn-io/properties-panel';
|
2022-08-17 17:05:46 +00:00
|
|
|
import { getMessageElementForShapeElement } from '../MessageHelpers';
|
2022-08-17 16:55:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows the creation, or editing of messageVariable at the bpmn:sendTask level of a BPMN document.
|
|
|
|
*/
|
|
|
|
export function MessageVariable(props) {
|
|
|
|
const shapeElement = props.element;
|
|
|
|
const debounce = useService('debounceInput');
|
|
|
|
|
|
|
|
const getMessageVariableObject = () => {
|
2022-08-17 17:05:46 +00:00
|
|
|
const messageElement = getMessageElementForShapeElement(shapeElement);
|
|
|
|
if (messageElement) {
|
|
|
|
const { extensionElements } = messageElement;
|
|
|
|
if (extensionElements) {
|
|
|
|
return messageElement.extensionElements
|
|
|
|
.get('values')
|
|
|
|
.filter(function getInstanceOfType(e) {
|
|
|
|
return e.$instanceOf('spiffworkflow:messageVariable');
|
|
|
|
})[0];
|
2022-08-17 16:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getValue = () => {
|
|
|
|
const messageVariableObject = getMessageVariableObject();
|
|
|
|
if (messageVariableObject) {
|
|
|
|
return messageVariableObject.messageVariable;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
|
|
|
const setValue = (value) => {
|
|
|
|
let messageVariableObject = getMessageVariableObject();
|
|
|
|
if (!messageVariableObject) {
|
2022-08-17 17:05:46 +00:00
|
|
|
const messageElement = getMessageElementForShapeElement(shapeElement);
|
|
|
|
messageVariableObject = messageElement.$model.create(
|
2022-08-17 16:55:14 +00:00
|
|
|
'spiffworkflow:messageVariable'
|
|
|
|
);
|
2022-08-17 17:05:46 +00:00
|
|
|
if (!messageElement.extensionElements) {
|
|
|
|
messageElement.extensionElements = messageElement.$model.create(
|
2022-08-17 16:55:14 +00:00
|
|
|
'bpmn:ExtensionElements'
|
|
|
|
);
|
|
|
|
}
|
2022-08-17 17:05:46 +00:00
|
|
|
messageElement.extensionElements
|
2022-08-17 16:55:14 +00:00
|
|
|
.get('values')
|
|
|
|
.push(messageVariableObject);
|
|
|
|
}
|
|
|
|
messageVariableObject.messageVariable = value;
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TextFieldEntry
|
|
|
|
id="messageVariable"
|
|
|
|
element={shapeElement}
|
|
|
|
description="The name of the variable where we should store payload."
|
|
|
|
label="Variable Name"
|
|
|
|
getValue={getValue}
|
|
|
|
setValue={setValue}
|
|
|
|
debounce={debounce}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|