wf composition
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / features / version / composition / custom-properties-provider / provider / camunda / parts / implementation / WorkflowActivity.js
1 import entryFactory from 'bpmn-js-properties-panel/lib/factory/EntryFactory';
2 import cmdHelper from 'bpmn-js-properties-panel/lib/helper/CmdHelper';
3 import {
4     implementationType,
5     IMPLEMENTATION_TYPE_VALUE
6 } from './implementationConstants';
7
8 const workflowActivity = (element, config, bpmnFactory, options, translate) => {
9     const { getImplementationType, getBusinessObject } = options;
10
11     const isWorkflowActivity = element =>
12         getImplementationType(element) === 'workflowActivity';
13
14     const workflowActivityEntry = entryFactory.selectBox({
15         id: 'activitySelect',
16         label: translate('Activity Spec'),
17         selectOptions: config.activities,
18         emptyParameter: true,
19         modelProperty: 'workflowActivity',
20
21         get: function(element) {
22             var bo = getBusinessObject(element);
23             return {
24                 workflowActivity: bo.get(implementationType.ACTIVITY_RESOURCE)
25             };
26         },
27
28         set: function(element, values) {
29             var bo = getBusinessObject(element);
30             config.onChange(bo, values.workflowActivity);
31             const commands = [];
32             const dataForUpdate = {};
33             dataForUpdate[implementationType.ACTIVITY_RESOURCE] =
34                 values.workflowActivity;
35             dataForUpdate[
36                 implementationType.ACTIVITY
37             ] = IMPLEMENTATION_TYPE_VALUE;
38             commands.push(
39                 cmdHelper.updateBusinessObject(element, bo, dataForUpdate)
40             );
41             return commands;
42         },
43
44         validate: function(element, values) {
45             return isWorkflowActivity(element) && !values.workflowActivity
46                 ? { workflowActivity: 'Must provide a value' }
47                 : {};
48         },
49
50         hidden: function(element) {
51             return !isWorkflowActivity(element);
52         }
53     });
54
55     return [workflowActivityEntry];
56 };
57
58 export default workflowActivity;