Fix output params
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / features / version / composition / custom-properties-provider / provider / camunda / parts / implementation / InputOutputUpdater.js
1 /*
2 * Copyright © 2018 European Support Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *http://www.apache.org/licenses/LICENSE-2.0
9 *
10  * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 import cmdHelper from 'bpmn-js-properties-panel/lib/helper/CmdHelper';
18 import { createInputOutput, createElement } from './InputOutput';
19 import InputOutputHelper from './InputOutputHelper';
20 import { INPUT, OUTPUT } from './implementationConstants';
21
22 export default ({ element, bo, bpmnFactory, activityInputsOutputs }) => {
23     const commands = [];
24     const existedInputOutput = InputOutputHelper.getInputOutput(element);
25
26     let newInputOutput = createInputOutput(element, bpmnFactory, {
27         inputParameters: [],
28         outputParameters: []
29     });
30
31     const inputs = activityInputsOutputs.inputs.map(({ name, value }) =>
32         createElement(INPUT, newInputOutput, bpmnFactory, {
33             name,
34             type: 'Text',
35             value
36         })
37     );
38
39     const outputs = activityInputsOutputs.outputs.map(({ name, value }) =>
40         createElement(OUTPUT, newInputOutput, bpmnFactory, {
41             name,
42             type: 'Text',
43             value
44         })
45     );
46
47     newInputOutput.inputParameters = inputs;
48     newInputOutput.outputParameters = outputs;
49
50     const objectToRemove = existedInputOutput ? [existedInputOutput] : [];
51     const extensionElements =
52         bo.extensionElements ||
53         createElement('bpmn:ExtensionElements', bo, bpmnFactory, []);
54
55     if (!bo.extensionElements) {
56         commands.push(
57             cmdHelper.updateBusinessObject(element, bo, {
58                 extensionElements
59             })
60         );
61     }
62
63     commands.push(
64         cmdHelper.addAndRemoveElementsFromList(
65             element,
66             extensionElements,
67             'values',
68             'extensionElements',
69             [newInputOutput],
70             objectToRemove
71         )
72     );
73     return commands;
74 };