This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Mapping.js
146 lines (111 loc) · 3.7 KB
/
Mapping.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/
import {
isPayloadMappingsSupported
} from '../../helper/PayloadMappingsHelper';
import cmdHelper from 'bpmn-js-properties-panel/lib/helper/CmdHelper';
import utils from 'bpmn-js-properties-panel/lib/Utils';
import entryFactory from 'bpmn-js-properties-panel/lib/factory/EntryFactory';
function ensurePayloadMappingsSupported(element) {
return isPayloadMappingsSupported(element);
}
export default function(element, bpmnFactory, options = {}) {
const idPrefix = options.idPrefix || '';
const getSelected = options.getSelectedMapping;
if (!ensurePayloadMappingsSupported(element)) {
return [];
}
const entries = [];
const isSelected = (element, node) => {
return getSelected(element, node);
};
// parameter source ////////////////////////////////////////////////////////
entries.push(entryFactory.validationAwareTextField({
id: `${idPrefix}mappingSource`,
label: 'Source',
modelProperty: 'source',
getProperty: function(element, node) {
return (getSelected(element, node) || {}).source;
},
setProperty: function(element, values, node) {
const param = getSelected(element, node);
return cmdHelper.updateBusinessObject(element, param, values);
},
validate: function(element, values, node) {
const bo = getSelected(element, node);
const validation = {};
if (bo) {
const sourceValue = values.source;
if (sourceValue) {
if (utils.containsSpace(sourceValue)) {
validation.source = 'Source must not contain spaces';
}
}
else {
validation.source = 'Mapping must have a source';
}
}
return validation;
},
disabled: function(element, node) {
return !isSelected(element, node);
}
}));
// parameter target ////////////////////////////////////////////////////////
entries.push(entryFactory.validationAwareTextField({
id: `${idPrefix}mappingTarget`,
label: 'Target',
modelProperty: 'target',
getProperty: function(element, node) {
return (getSelected(element, node) || {}).target;
},
setProperty: function(element, values, node) {
const param = getSelected(element, node);
return cmdHelper.updateBusinessObject(element, param, values);
},
validate: function(element, values, node) {
const bo = getSelected(element, node);
const validation = {};
if (bo) {
const targetValue = values.target;
if (targetValue) {
if (utils.containsSpace(targetValue)) {
validation.target = 'Target must not contain spaces';
}
}
else {
validation.target = 'Mapping must have a Target';
}
}
return validation;
},
disabled: function(element, node) {
return !isSelected(element, node);
}
}));
entries.push(entryFactory.selectBox({
id: 'mapping-type',
label: 'Type',
selectOptions: [
{ name: 'PUT', value: 'PUT' },
{ name: 'COLLECT', value: 'COLLECT' }
],
modelProperty: 'type',
emptyParameter: false,
get: function(element, node) {
return (getSelected(element, node) || {});
},
set: function(element, values, node) {
const param = getSelected(element, node);
return cmdHelper.updateBusinessObject(element, param, values);
}
}));
return entries;
}