@gridsuite/commons-ui 0.32.0 → 0.32.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -69,14 +69,14 @@ function extractDefault(paramDescription) {
|
|
|
69
69
|
}
|
|
70
70
|
return d !== null && d !== void 0 ? d : null;
|
|
71
71
|
}
|
|
72
|
-
function longestCommonPrefix(
|
|
73
|
-
if (!(
|
|
72
|
+
function longestCommonPrefix(stringList) {
|
|
73
|
+
if (!(stringList === null || stringList === void 0 ? void 0 : stringList.length)) {
|
|
74
74
|
return '';
|
|
75
75
|
}
|
|
76
|
-
var prefix =
|
|
76
|
+
var prefix = stringList.reduce(function (acc, str) {
|
|
77
77
|
return str.length < acc.length ? str : acc;
|
|
78
78
|
});
|
|
79
|
-
for (var _iterator = _createForOfIteratorHelperLoose(
|
|
79
|
+
for (var _iterator = _createForOfIteratorHelperLoose(stringList), _step; !(_step = _iterator()).done;) {
|
|
80
80
|
var str = _step.value;
|
|
81
81
|
while (str.slice(0, prefix.length) !== prefix) {
|
|
82
82
|
prefix = prefix.slice(0, -1);
|
|
@@ -112,19 +112,26 @@ var FlatParameters = function FlatParameters(_ref) {
|
|
|
112
112
|
var _useState2 = (0, _react.useState)(null),
|
|
113
113
|
inEditionParam = _useState2[0],
|
|
114
114
|
setInEditionParam = _useState2[1];
|
|
115
|
-
var
|
|
115
|
+
var getTranslatedValue = (0, _react.useCallback)(function (prefix, value) {
|
|
116
|
+
return intl.formatMessage({
|
|
117
|
+
id: prefix + '.' + value,
|
|
118
|
+
defaultMessage: value
|
|
119
|
+
});
|
|
120
|
+
}, [intl]);
|
|
121
|
+
var sortPossibleValues = (0, _react.useCallback)(function (prefix, values) {
|
|
116
122
|
if (values == null) {
|
|
117
123
|
return [];
|
|
118
124
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
// Sort by translated values
|
|
126
|
+
return values.map(function (value) {
|
|
127
|
+
return {
|
|
128
|
+
id: value,
|
|
129
|
+
message: getTranslatedValue(prefix, value)
|
|
130
|
+
};
|
|
124
131
|
}).sort(function (a, b) {
|
|
125
|
-
return a.localeCompare(b);
|
|
132
|
+
return a.message.localeCompare(b.message);
|
|
126
133
|
});
|
|
127
|
-
}, [
|
|
134
|
+
}, [getTranslatedValue]);
|
|
128
135
|
var onFieldChange = (0, _react.useCallback)(function (value, param) {
|
|
129
136
|
var paramName = param.name;
|
|
130
137
|
var isInEdition = inEditionParam === paramName;
|
|
@@ -132,14 +139,14 @@ var FlatParameters = function FlatParameters(_ref) {
|
|
|
132
139
|
setUncommitted(value);
|
|
133
140
|
}
|
|
134
141
|
if (onChange) {
|
|
135
|
-
if (
|
|
136
|
-
onChange(paramName,
|
|
142
|
+
if (param.type === 'STRING_LIST') {
|
|
143
|
+
onChange(paramName, value ? value.toString() : null, isInEdition);
|
|
137
144
|
} else {
|
|
138
145
|
onChange(paramName, value, isInEdition);
|
|
139
146
|
}
|
|
140
147
|
}
|
|
141
148
|
}, [inEditionParam, onChange]);
|
|
142
|
-
var
|
|
149
|
+
var onUncommitted = (0, _react.useCallback)(function (param, inEdit) {
|
|
143
150
|
if (inEdit) {
|
|
144
151
|
setInEditionParam(param.name);
|
|
145
152
|
} else {
|
|
@@ -161,23 +168,38 @@ var FlatParameters = function FlatParameters(_ref) {
|
|
|
161
168
|
if (param.name === inEditionParam && uncommitted !== null) {
|
|
162
169
|
return uncommitted;
|
|
163
170
|
} else if (initValues && initValues.hasOwnProperty(param.name)) {
|
|
164
|
-
|
|
171
|
+
if (param.type !== 'STRING_LIST') {
|
|
172
|
+
return initValues[param.name];
|
|
173
|
+
}
|
|
174
|
+
var valueList = initValues[param.name];
|
|
175
|
+
if (Array.isArray(valueList)) {
|
|
176
|
+
return valueList;
|
|
177
|
+
}
|
|
178
|
+
// otherwise split string into array
|
|
179
|
+
return valueList ? valueList.split(',').map(function (s) {
|
|
180
|
+
return s.trim();
|
|
181
|
+
}).filter(function (s) {
|
|
182
|
+
return !!s;
|
|
183
|
+
}) : [];
|
|
165
184
|
} else {
|
|
166
185
|
return extractDefault(param);
|
|
167
186
|
}
|
|
168
187
|
}
|
|
188
|
+
var outputTransformFloatString = function outputTransformFloatString(value) {
|
|
189
|
+
return (value === null || value === void 0 ? void 0 : value.replace(',', '.')) || '';
|
|
190
|
+
};
|
|
169
191
|
var renderField = function renderField(param) {
|
|
170
|
-
var
|
|
192
|
+
var fieldValue = mixInitAndDefault(param);
|
|
171
193
|
switch (param.type) {
|
|
172
194
|
case 'BOOLEAN':
|
|
173
195
|
return /*#__PURE__*/_react["default"].createElement(_material.Switch, {
|
|
174
|
-
checked: !!
|
|
196
|
+
checked: !!fieldValue,
|
|
175
197
|
onChange: function onChange(e) {
|
|
176
198
|
return onFieldChange(e.target.checked, param);
|
|
177
199
|
}
|
|
178
200
|
});
|
|
179
201
|
case 'DOUBLE':
|
|
180
|
-
var err = isNaN(
|
|
202
|
+
var err = isNaN(fieldValue) || typeof fieldValue !== 'number' && !!fieldValue && isNaN(fieldValue - 0);
|
|
181
203
|
return /*#__PURE__*/_react["default"].createElement(_material.TextField, {
|
|
182
204
|
fullWidth: true,
|
|
183
205
|
sx: {
|
|
@@ -185,17 +207,17 @@ var FlatParameters = function FlatParameters(_ref) {
|
|
|
185
207
|
textAlign: 'right'
|
|
186
208
|
}
|
|
187
209
|
},
|
|
188
|
-
value:
|
|
210
|
+
value: fieldValue,
|
|
189
211
|
onFocus: function onFocus() {
|
|
190
|
-
return
|
|
212
|
+
return onUncommitted(param, true);
|
|
191
213
|
},
|
|
192
214
|
onBlur: function onBlur() {
|
|
193
|
-
return
|
|
215
|
+
return onUncommitted(param, false);
|
|
194
216
|
},
|
|
195
217
|
onChange: function onChange(e) {
|
|
196
218
|
var m = FloatRE.exec(e.target.value);
|
|
197
219
|
if (m) {
|
|
198
|
-
onFieldChange(e.target.value, param);
|
|
220
|
+
onFieldChange(outputTransformFloatString(e.target.value), param);
|
|
199
221
|
}
|
|
200
222
|
},
|
|
201
223
|
error: err,
|
|
@@ -209,12 +231,12 @@ var FlatParameters = function FlatParameters(_ref) {
|
|
|
209
231
|
textAlign: 'right'
|
|
210
232
|
}
|
|
211
233
|
},
|
|
212
|
-
value:
|
|
234
|
+
value: fieldValue,
|
|
213
235
|
onFocus: function onFocus() {
|
|
214
|
-
return
|
|
236
|
+
return onUncommitted(param, true);
|
|
215
237
|
},
|
|
216
238
|
onBlur: function onBlur() {
|
|
217
|
-
return
|
|
239
|
+
return onUncommitted(param, false);
|
|
218
240
|
},
|
|
219
241
|
onChange: function onChange(e) {
|
|
220
242
|
var m = IntegerRE.exec(e.target.value);
|
|
@@ -229,34 +251,67 @@ var FlatParameters = function FlatParameters(_ref) {
|
|
|
229
251
|
return /*#__PURE__*/_react["default"].createElement(_material.Autocomplete, {
|
|
230
252
|
fullWidth: true,
|
|
231
253
|
multiple: true,
|
|
232
|
-
options:
|
|
254
|
+
options: sortPossibleValues(param.name, param.possibleValues).map(function (v) {
|
|
255
|
+
return v.id;
|
|
256
|
+
}),
|
|
257
|
+
getOptionLabel: function getOptionLabel(option) {
|
|
258
|
+
return getTranslatedValue(param.name, option);
|
|
259
|
+
},
|
|
260
|
+
onChange: function onChange(e, value) {
|
|
261
|
+
return onFieldChange(value, param);
|
|
262
|
+
},
|
|
263
|
+
value: fieldValue,
|
|
264
|
+
renderTags: function renderTags(values, getTagProps) {
|
|
265
|
+
return values.map(function (value, index) {
|
|
266
|
+
return /*#__PURE__*/_react["default"].createElement(_material.Chip, _extends({
|
|
267
|
+
label: getTranslatedValue(param.name, value)
|
|
268
|
+
}, getTagProps({
|
|
269
|
+
index: index
|
|
270
|
+
})));
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
renderInput: function renderInput(inputProps) {
|
|
274
|
+
return /*#__PURE__*/_react["default"].createElement(_material.TextField, _extends({}, inputProps, {
|
|
275
|
+
variant: variant
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
} else {
|
|
280
|
+
// no possible values => free user inputs
|
|
281
|
+
return /*#__PURE__*/_react["default"].createElement(_material.Autocomplete, {
|
|
282
|
+
fullWidth: true,
|
|
283
|
+
multiple: true,
|
|
284
|
+
freeSolo: true,
|
|
285
|
+
autoSelect: true,
|
|
286
|
+
options: [],
|
|
233
287
|
onChange: function onChange(e, value) {
|
|
234
288
|
return onFieldChange(value, param);
|
|
235
289
|
},
|
|
236
|
-
value:
|
|
237
|
-
renderTags: function renderTags(
|
|
238
|
-
return
|
|
290
|
+
value: fieldValue,
|
|
291
|
+
renderTags: function renderTags(values, getTagProps) {
|
|
292
|
+
return values.map(function (value, index) {
|
|
239
293
|
return /*#__PURE__*/_react["default"].createElement(_material.Chip, _extends({
|
|
240
|
-
|
|
294
|
+
id: 'chip_' + value,
|
|
295
|
+
size: 'small',
|
|
296
|
+
label: value
|
|
241
297
|
}, getTagProps({
|
|
242
298
|
index: index
|
|
243
299
|
})));
|
|
244
300
|
});
|
|
245
301
|
},
|
|
246
|
-
renderInput: function renderInput(
|
|
247
|
-
return /*#__PURE__*/_react["default"].createElement(_material.TextField, _extends({},
|
|
302
|
+
renderInput: function renderInput(inputProps) {
|
|
303
|
+
return /*#__PURE__*/_react["default"].createElement(_material.TextField, _extends({}, inputProps, {
|
|
248
304
|
variant: variant
|
|
249
305
|
}));
|
|
250
306
|
}
|
|
251
307
|
});
|
|
252
308
|
}
|
|
253
|
-
// else fallthrough to default
|
|
254
309
|
case 'STRING':
|
|
255
310
|
if (param.possibleValues) {
|
|
256
311
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_material.Select, {
|
|
257
312
|
labelId: param.name,
|
|
258
|
-
value:
|
|
259
|
-
onChange: function onChange(ev
|
|
313
|
+
value: fieldValue !== null && fieldValue !== void 0 ? fieldValue : '',
|
|
314
|
+
onChange: function onChange(ev) {
|
|
260
315
|
onFieldChange(ev.target.value, param);
|
|
261
316
|
},
|
|
262
317
|
size: "small",
|
|
@@ -264,26 +319,23 @@ var FlatParameters = function FlatParameters(_ref) {
|
|
|
264
319
|
minWidth: '4em'
|
|
265
320
|
},
|
|
266
321
|
variant: variant
|
|
267
|
-
}, param.possibleValues.map(function (value) {
|
|
322
|
+
}, sortPossibleValues(param.name, param.possibleValues).map(function (value) {
|
|
268
323
|
return /*#__PURE__*/_react["default"].createElement(_material.MenuItem, {
|
|
269
|
-
key: value,
|
|
270
|
-
value: value
|
|
271
|
-
}, /*#__PURE__*/_react["default"].createElement(_material.Typography, null,
|
|
272
|
-
id: value,
|
|
273
|
-
defaultMessage: value
|
|
274
|
-
})));
|
|
324
|
+
key: value.id,
|
|
325
|
+
value: value.id
|
|
326
|
+
}, /*#__PURE__*/_react["default"].createElement(_material.Typography, null, value.message));
|
|
275
327
|
})));
|
|
276
328
|
}
|
|
277
329
|
// else fallthrough to default
|
|
278
330
|
default:
|
|
279
331
|
return /*#__PURE__*/_react["default"].createElement(_material.TextField, {
|
|
280
332
|
fullWidth: true,
|
|
281
|
-
|
|
333
|
+
value: fieldValue || '',
|
|
282
334
|
onFocus: function onFocus() {
|
|
283
|
-
return
|
|
335
|
+
return onUncommitted(param, true);
|
|
284
336
|
},
|
|
285
337
|
onBlur: function onBlur() {
|
|
286
|
-
return
|
|
338
|
+
return onUncommitted(param, false);
|
|
287
339
|
},
|
|
288
340
|
onChange: function onChange(e) {
|
|
289
341
|
return onFieldChange(e.target.value, param);
|
|
@@ -296,7 +348,10 @@ var FlatParameters = function FlatParameters(_ref) {
|
|
|
296
348
|
className: classes.paramList
|
|
297
349
|
}, paramsAsArray.map(function (param) {
|
|
298
350
|
return /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
|
|
299
|
-
title:
|
|
351
|
+
title: /*#__PURE__*/_react["default"].createElement(_reactIntl.FormattedMessage, {
|
|
352
|
+
id: param.name + '.desc',
|
|
353
|
+
defaultMessage: param.description
|
|
354
|
+
}),
|
|
300
355
|
enterDelay: 1200,
|
|
301
356
|
key: param.name
|
|
302
357
|
}, /*#__PURE__*/_react["default"].createElement(_material.ListItem, {
|
|
@@ -304,7 +359,10 @@ var FlatParameters = function FlatParameters(_ref) {
|
|
|
304
359
|
className: classes.paramListItem
|
|
305
360
|
}, /*#__PURE__*/_react["default"].createElement(_material.Typography, {
|
|
306
361
|
className: classes.paramName
|
|
307
|
-
},
|
|
362
|
+
}, /*#__PURE__*/_react["default"].createElement(_reactIntl.FormattedMessage, {
|
|
363
|
+
id: param.name,
|
|
364
|
+
defaultMessage: param.name.slice(prefix.length)
|
|
365
|
+
})), renderField(param)));
|
|
308
366
|
}));
|
|
309
367
|
};
|
|
310
368
|
exports.FlatParameters = FlatParameters;
|