@finos/legend-query-builder 4.16.20 → 4.16.21
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.
- package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.d.ts +21 -1
- package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.d.ts.map +1 -1
- package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.js +16 -2
- package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.js.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.js +1 -1
- package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.js.map +1 -1
- package/lib/components/filter/QueryBuilderFilterPanel.js +1 -1
- package/lib/components/filter/QueryBuilderFilterPanel.js.map +1 -1
- package/lib/components/shared/BasicValueSpecificationEditor.d.ts +155 -4
- package/lib/components/shared/BasicValueSpecificationEditor.d.ts.map +1 -1
- package/lib/components/shared/BasicValueSpecificationEditor.js +239 -158
- package/lib/components/shared/BasicValueSpecificationEditor.js.map +1 -1
- package/lib/components/shared/CustomDatePicker.d.ts +8 -55
- package/lib/components/shared/CustomDatePicker.d.ts.map +1 -1
- package/lib/components/shared/CustomDatePicker.js +31 -415
- package/lib/components/shared/CustomDatePicker.js.map +1 -1
- package/lib/components/shared/CustomDatePickerHelper.d.ts +145 -0
- package/lib/components/shared/CustomDatePickerHelper.d.ts.map +1 -0
- package/lib/components/shared/CustomDatePickerHelper.js +517 -0
- package/lib/components/shared/CustomDatePickerHelper.js.map +1 -0
- package/lib/components/shared/QueryBuilderVariableSelector.js +1 -1
- package/lib/components/shared/QueryBuilderVariableSelector.js.map +1 -1
- package/lib/components/shared/V1_BasicValueSpecificationEditor.d.ts +36 -0
- package/lib/components/shared/V1_BasicValueSpecificationEditor.d.ts.map +1 -0
- package/lib/components/shared/V1_BasicValueSpecificationEditor.js +166 -0
- package/lib/components/shared/V1_BasicValueSpecificationEditor.js.map +1 -0
- package/lib/index.css +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/stores/shared/V1_ValueSpecificationEditorHelper.d.ts +23 -0
- package/lib/stores/shared/V1_ValueSpecificationEditorHelper.d.ts.map +1 -0
- package/lib/stores/shared/V1_ValueSpecificationEditorHelper.js +69 -0
- package/lib/stores/shared/V1_ValueSpecificationEditorHelper.js.map +1 -0
- package/lib/stores/shared/V1_ValueSpecificationModifierHelper.d.ts +20 -0
- package/lib/stores/shared/V1_ValueSpecificationModifierHelper.d.ts.map +1 -0
- package/lib/stores/shared/V1_ValueSpecificationModifierHelper.js +38 -0
- package/lib/stores/shared/V1_ValueSpecificationModifierHelper.js.map +1 -0
- package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts +4 -1
- package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts.map +1 -1
- package/lib/stores/shared/ValueSpecificationEditorHelper.js +23 -2
- package/lib/stores/shared/ValueSpecificationEditorHelper.js.map +1 -1
- package/package.json +5 -5
- package/src/components/__test-utils__/QueryBuilderComponentTestUtils.tsx +101 -12
- package/src/components/fetch-structure/QueryBuilderPostFilterPanel.tsx +1 -1
- package/src/components/filter/QueryBuilderFilterPanel.tsx +1 -1
- package/src/components/shared/BasicValueSpecificationEditor.tsx +1417 -1085
- package/src/components/shared/CustomDatePicker.tsx +136 -902
- package/src/components/shared/CustomDatePickerHelper.ts +984 -0
- package/src/components/shared/QueryBuilderVariableSelector.tsx +1 -1
- package/src/components/shared/V1_BasicValueSpecificationEditor.tsx +396 -0
- package/src/index.ts +5 -0
- package/src/stores/shared/V1_ValueSpecificationEditorHelper.ts +113 -0
- package/src/stores/shared/V1_ValueSpecificationModifierHelper.ts +76 -0
- package/src/stores/shared/ValueSpecificationEditorHelper.ts +71 -2
- package/tsconfig.json +4 -0
@@ -16,18 +16,19 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
16
16
|
*/
|
17
17
|
import { DEFAULT_TYPEAHEAD_SEARCH_MINIMUM_SEARCH_LENGTH, useApplicationStore, } from '@finos/legend-application';
|
18
18
|
import { Tooltip, DollarIcon, clsx, InfoCircleIcon, RefreshIcon, CheckSquareIcon, SquareIcon, CustomSelectorInput, SaveIcon, PencilIcon, DragPreviewLayer, CalculateIcon, InputWithInlineValidation, CopyIcon, } from '@finos/legend-art';
|
19
|
-
import {
|
20
|
-
import { guaranteeNonNullable, isNonNullable, guaranteeIsNumber, csvStringify, guaranteeType, isNonEmptyString, parseCSVString, uniq,
|
19
|
+
import { CollectionInstanceValue, Enumeration, EnumValueExplicitReference, EnumValueInstanceValue, GenericType, GenericTypeExplicitReference, getMultiplicityDescription, getPrimitiveTypeInstanceFromEnum, InstanceValue, INTERNAL__PropagatedValue, isSubType, matchFunctionName, PRIMITIVE_TYPE, PrimitiveInstanceValue, PrimitiveType, SimpleFunctionExpression, Type, VariableExpression, observe_ValueSpecification, V1_PackageableType, } from '@finos/legend-graph';
|
20
|
+
import { guaranteeNonNullable, isNonNullable, guaranteeIsNumber, csvStringify, guaranteeType, isNonEmptyString, parseCSVString, uniq, } from '@finos/legend-shared';
|
21
21
|
import { flowResult } from 'mobx';
|
22
22
|
import { observer } from 'mobx-react-lite';
|
23
23
|
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from 'react';
|
24
|
-
import { instanceValue_setValue, instanceValue_setValues, } from '../../stores/shared/ValueSpecificationModifierHelper.js';
|
25
|
-
import { CustomDatePicker } from './CustomDatePicker.js';
|
24
|
+
import { instanceValue_setValue, instanceValue_setValues, valueSpecification_setGenericType, } from '../../stores/shared/ValueSpecificationModifierHelper.js';
|
26
25
|
import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../../graph/QueryBuilderMetaModelConst.js';
|
27
26
|
import { isValidInstanceValue, simplifyValueExpression, } from '../../stores/QueryBuilderValueSpecificationHelper.js';
|
28
27
|
import { evaluate } from 'mathjs';
|
29
28
|
import { isUsedDateFunctionSupportedInFormMode } from '../../stores/QueryBuilderStateBuilder.js';
|
30
|
-
import { convertTextToEnum, convertTextToPrimitiveInstanceValue, getValueSpecificationStringValue, } from '../../stores/shared/ValueSpecificationEditorHelper.js';
|
29
|
+
import { buildPrimitiveInstanceValue, convertTextToEnum, convertTextToPrimitiveInstanceValue, getValueSpecificationStringValue, } from '../../stores/shared/ValueSpecificationEditorHelper.js';
|
30
|
+
import { CustomDatePicker } from './CustomDatePicker.js';
|
31
|
+
import { CustomDateOption, buildPureAdjustDateFunction, CustomFirstDayOfOption, buildPureDateFunctionExpression, CustomPreviousDayOfWeekOption, DatePickerOption, } from './CustomDatePickerHelper.js';
|
31
32
|
export const VariableInfoTooltip = (props) => {
|
32
33
|
const { variable, children, placement } = props;
|
33
34
|
const type = variable.genericType?.value.rawType;
|
@@ -50,28 +51,25 @@ const VariableExpressionParameterEditor = observer((props) => {
|
|
50
51
|
'value-spec-editor__variable__constant': isConstant,
|
51
52
|
}), children: [_jsx("div", { className: "value-spec-editor__variable__icon", children: isConstant ? _jsx("div", { className: "icon", children: "C" }) : _jsx(DollarIcon, {}) }), _jsxs("div", { className: "value-spec-editor__variable__label", children: [_jsx("div", { className: "value-spec-editor__variable__text", children: varName }), _jsx(VariableInfoTooltip, { variable: valueSpecification, children: _jsx("div", { className: "value-spec-editor__variable__info", children: _jsx(InfoCircleIcon, {}) }) }), _jsx("button", { className: "value-spec-editor__variable__reset-btn", name: "Reset", title: "Reset", onClick: resetValue, children: _jsx(RefreshIcon, {}) })] })] })] }));
|
52
53
|
});
|
53
|
-
|
54
|
-
|
55
|
-
const
|
54
|
+
// eslint-disable-next-line comma-spacing
|
55
|
+
const StringPrimitiveInstanceValueEditorInner = (props, ref) => {
|
56
|
+
const { valueSpecification, valueSelector, updateValueSpecification, errorChecker, resetValue, handleBlur, handleKeyDown, className, selectorSearchConfig, selectorConfig, } = props;
|
57
|
+
const useSelector = Boolean(selectorSearchConfig);
|
56
58
|
const applicationStore = useApplicationStore();
|
57
|
-
const value = valueSpecification
|
58
|
-
const updateValueSpec = (val) => {
|
59
|
-
instanceValue_setValue(valueSpecification, val, 0, observerContext);
|
60
|
-
setValueSpecification(valueSpecification);
|
61
|
-
};
|
59
|
+
const value = valueSelector(valueSpecification);
|
62
60
|
const changeInputValue = (event) => {
|
63
|
-
|
61
|
+
updateValueSpecification(valueSpecification, event.target.value);
|
64
62
|
};
|
65
63
|
// custom select
|
66
64
|
const selectedValue = value ? { value: value, label: value } : null;
|
67
|
-
const reloadValuesFunc =
|
65
|
+
const reloadValuesFunc = selectorSearchConfig?.reloadValues;
|
68
66
|
const changeValue = (val) => {
|
69
67
|
const newValue = val === null ? '' : val.value.toString();
|
70
|
-
|
68
|
+
updateValueSpecification(valueSpecification, newValue);
|
71
69
|
};
|
72
70
|
const handleInputChange = (inputValue, actionChange) => {
|
73
71
|
if (actionChange.action === 'input-change') {
|
74
|
-
|
72
|
+
updateValueSpecification(valueSpecification, inputValue);
|
75
73
|
reloadValuesFunc?.cancel();
|
76
74
|
const reloadValuesFuncTransformation = reloadValuesFunc?.(inputValue);
|
77
75
|
if (reloadValuesFuncTransformation) {
|
@@ -80,48 +78,48 @@ const StringPrimitiveInstanceValueEditor = observer(forwardRef(function StringPr
|
|
80
78
|
}
|
81
79
|
if (actionChange.action === 'input-blur') {
|
82
80
|
reloadValuesFunc?.cancel();
|
83
|
-
|
81
|
+
selectorSearchConfig?.cleanUpReloadValues?.();
|
84
82
|
}
|
85
83
|
};
|
86
|
-
const isLoading =
|
87
|
-
const queryOptions =
|
88
|
-
?
|
84
|
+
const isLoading = selectorSearchConfig?.isLoading;
|
85
|
+
const queryOptions = selectorSearchConfig?.values?.length
|
86
|
+
? selectorSearchConfig.values.map((e) => ({
|
89
87
|
value: e,
|
90
88
|
label: e.toString(),
|
91
89
|
}))
|
92
90
|
: undefined;
|
93
|
-
const noOptionsMessage =
|
94
|
-
const resetButtonName = `reset-${valueSpecification
|
95
|
-
const inputName = `input-${valueSpecification
|
91
|
+
const noOptionsMessage = selectorSearchConfig?.values === undefined ? () => null : undefined;
|
92
|
+
const resetButtonName = `reset-${valueSelector(valueSpecification)}`;
|
93
|
+
const inputName = `input-${valueSelector(valueSpecification)}`;
|
96
94
|
const onBlur = (event) => {
|
97
95
|
if (event.relatedTarget?.name !== resetButtonName &&
|
98
96
|
event.relatedTarget?.name !== inputName) {
|
99
97
|
handleBlur?.();
|
100
98
|
}
|
101
99
|
};
|
102
|
-
return (_jsxs("div", { className: clsx('value-spec-editor', className), onBlur: onBlur, children: [useSelector ? (_jsx(CustomSelectorInput, { className: "value-spec-editor__enum-selector", options: queryOptions, onChange: changeValue, value: selectedValue, inputValue: value ?? '', onInputChange: handleInputChange, darkMode: !applicationStore.layoutService
|
103
|
-
.TEMPORARY__isLightColorThemeEnabled, isLoading: isLoading, allowCreateWhileLoading: true, noOptionsMessage: noOptionsMessage, components: {
|
100
|
+
return (_jsxs("div", { className: clsx('value-spec-editor', className), onBlur: onBlur, children: [useSelector ? (_jsx(CustomSelectorInput, { className: "value-spec-editor__enum-selector", options: queryOptions, onChange: changeValue, value: selectedValue, inputValue: value ?? '', onInputChange: handleInputChange, darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, isLoading: isLoading, allowCreateWhileLoading: true, noOptionsMessage: noOptionsMessage, components: {
|
104
101
|
DropdownIndicator: null,
|
105
|
-
}, hasError:
|
102
|
+
}, hasError: errorChecker?.(valueSpecification), placeholder: value === '' ? '(empty)' : undefined, inputRef: ref, onKeyDown: handleKeyDown, inputName: inputName, optionCustomization: selectorConfig?.optionCustomization })) : (_jsx(InputWithInlineValidation, { className: "panel__content__form__section__input value-spec-editor__input", spellCheck: false, value: value ?? '', placeholder: value === '' ? '(empty)' : undefined, onChange: changeInputValue, ref: ref, error: errorChecker?.(valueSpecification)
|
106
103
|
? 'Invalid String value'
|
107
104
|
: undefined, onKeyDown: handleKeyDown, name: inputName })), _jsx("button", { className: "value-spec-editor__reset-btn", name: resetButtonName, title: "Reset", onClick: resetValue, children: _jsx(RefreshIcon, {}) })] }));
|
108
|
-
}
|
109
|
-
const
|
110
|
-
|
111
|
-
|
105
|
+
};
|
106
|
+
export const StringPrimitiveInstanceValueEditor = observer(forwardRef(StringPrimitiveInstanceValueEditorInner));
|
107
|
+
// eslint-disable-next-line comma-spacing
|
108
|
+
const BooleanInstanceValueEditorInner = (props) => {
|
109
|
+
const { valueSpecification, valueSelector, updateValueSpecification, resetValue, className, } = props;
|
110
|
+
const value = valueSelector(valueSpecification);
|
112
111
|
const toggleValue = () => {
|
113
|
-
|
114
|
-
setValueSpecification(valueSpecification);
|
112
|
+
updateValueSpecification(valueSpecification, !value);
|
115
113
|
};
|
116
|
-
return (_jsxs("div", { className: clsx('value-spec-editor', className), children: [_jsx("button", { className: clsx('value-spec-editor__toggler__btn', {
|
114
|
+
return (_jsxs("div", { className: clsx('value-spec-editor', className), children: [_jsx("button", { role: "checkbox", className: clsx('value-spec-editor__toggler__btn', {
|
117
115
|
'value-spec-editor__toggler__btn--toggled': value,
|
118
116
|
}), onClick: toggleValue, children: value ? _jsx(CheckSquareIcon, {}) : _jsx(SquareIcon, {}) }), _jsx("button", { className: "value-spec-editor__reset-btn", name: "Reset", title: "Reset", onClick: resetValue, children: _jsx(RefreshIcon, {}) })] }));
|
119
|
-
}
|
120
|
-
const
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
117
|
+
};
|
118
|
+
export const BooleanPrimitiveInstanceValueEditor = observer(BooleanInstanceValueEditorInner);
|
119
|
+
// eslint-disable-next-line comma-spacing
|
120
|
+
const NumberPrimitiveInstanceValueEditorInner = (props, ref) => {
|
121
|
+
const { valueSpecification, valueSelector, updateValueSpecification, errorChecker, resetValue, handleBlur, handleKeyDown, className, isInteger, } = props;
|
122
|
+
const [value, setValue] = useState(valueSelector(valueSpecification)?.toString() ?? '');
|
125
123
|
const inputRef = useRef(null);
|
126
124
|
useImperativeHandle(ref, () => inputRef.current, []);
|
127
125
|
const numericValue = value
|
@@ -135,9 +133,8 @@ const NumberPrimitiveInstanceValueEditor = observer(forwardRef(function NumberPr
|
|
135
133
|
? Number.parseInt(Number(val).toString(), 10)
|
136
134
|
: Number(val);
|
137
135
|
if (!isNaN(parsedValue) &&
|
138
|
-
parsedValue !== valueSpecification
|
139
|
-
|
140
|
-
setValueSpecification(valueSpecification);
|
136
|
+
parsedValue !== valueSelector(valueSpecification)) {
|
137
|
+
updateValueSpecification(valueSpecification, parsedValue);
|
141
138
|
}
|
142
139
|
}
|
143
140
|
else {
|
@@ -159,10 +156,7 @@ const NumberPrimitiveInstanceValueEditor = observer(forwardRef(function NumberPr
|
|
159
156
|
}
|
160
157
|
catch {
|
161
158
|
// If we fail to evaluate the expression, we just keep the previous value
|
162
|
-
const prevValue = valueSpecification
|
163
|
-
valueSpecification.values[0] !== undefined
|
164
|
-
? valueSpecification.values[0].toString()
|
165
|
-
: '';
|
159
|
+
const prevValue = valueSelector(valueSpecification)?.toString() ?? '';
|
166
160
|
updateValueSpecIfValid(prevValue);
|
167
161
|
setValue(prevValue);
|
168
162
|
}
|
@@ -189,16 +183,16 @@ const NumberPrimitiveInstanceValueEditor = observer(forwardRef(function NumberPr
|
|
189
183
|
useEffect(() => {
|
190
184
|
if (numericValue !== null &&
|
191
185
|
!isNaN(numericValue) &&
|
192
|
-
numericValue !== valueSpecification
|
193
|
-
const valueFromValueSpec = valueSpecification
|
194
|
-
? valueSpecification.
|
186
|
+
numericValue !== valueSelector(valueSpecification)) {
|
187
|
+
const valueFromValueSpec = valueSelector(valueSpecification) !== null
|
188
|
+
? valueSelector(valueSpecification).toString()
|
195
189
|
: '';
|
196
190
|
setValue(valueFromValueSpec);
|
197
191
|
}
|
198
|
-
}, [numericValue, valueSpecification]);
|
199
|
-
const resetButtonName = `reset-${valueSpecification
|
200
|
-
const inputName = `input-${valueSpecification
|
201
|
-
const calculateButtonName = `calculate-${valueSpecification
|
192
|
+
}, [numericValue, valueSpecification, valueSelector]);
|
193
|
+
const resetButtonName = `reset-${valueSelector(valueSpecification)}`;
|
194
|
+
const inputName = `input-${valueSelector(valueSpecification)}`;
|
195
|
+
const calculateButtonName = `calculate-${valueSelector(valueSpecification)}`;
|
202
196
|
const onBlur = (event) => {
|
203
197
|
if (event.relatedTarget?.name !== resetButtonName &&
|
204
198
|
event.relatedTarget?.name !== inputName &&
|
@@ -207,29 +201,23 @@ const NumberPrimitiveInstanceValueEditor = observer(forwardRef(function NumberPr
|
|
207
201
|
}
|
208
202
|
};
|
209
203
|
return (_jsxs("div", { className: clsx('value-spec-editor', className), onBlur: onBlur, children: [_jsxs("div", { className: "value-spec-editor__number__input-container", children: [_jsx("input", { ref: inputRef, className: clsx('panel__content__form__section__input', 'value-spec-editor__input', 'value-spec-editor__number__input', {
|
210
|
-
'value-spec-editor__number__input--error':
|
204
|
+
'value-spec-editor__number__input--error': errorChecker?.(valueSpecification),
|
211
205
|
}), spellCheck: false, type: "text" // NOTE: we leave this as text so that we can support expression evaluation
|
212
206
|
, inputMode: "numeric", value: value, onChange: handleInputChange, onBlur: calculateExpression, onKeyDown: (event) => {
|
213
207
|
onKeyDown(event);
|
214
208
|
handleKeyDown?.(event);
|
215
209
|
}, name: inputName }), _jsx("div", { className: "value-spec-editor__number__actions", children: _jsx("button", { className: "value-spec-editor__number__action", title: "Evaluate Expression (Enter)", name: calculateButtonName, onClick: calculateExpression, children: _jsx(CalculateIcon, {}) }) })] }), _jsx("button", { className: "value-spec-editor__reset-btn", name: resetButtonName, title: "Reset", onClick: resetValue, children: _jsx(RefreshIcon, {}) })] }));
|
216
|
-
}
|
217
|
-
const
|
218
|
-
|
210
|
+
};
|
211
|
+
export const NumberPrimitiveInstanceValueEditor = observer(forwardRef(NumberPrimitiveInstanceValueEditorInner));
|
212
|
+
// eslint-disable-next-line comma-spacing
|
213
|
+
const EnumInstanceValueEditorInner = (props) => {
|
214
|
+
const { valueSpecification, valueSelector, updateValueSpecification, errorChecker, resetValue, handleBlur, options, className, selectorConfig, } = props;
|
219
215
|
const applicationStore = useApplicationStore();
|
220
|
-
const
|
221
|
-
const
|
222
|
-
|
223
|
-
: valueSpecification.values[0].value;
|
224
|
-
const options = enumType.values.map((value) => ({
|
225
|
-
label: value.name,
|
226
|
-
value: value,
|
227
|
-
}));
|
228
|
-
const resetButtonName = `reset-${valueSpecification.hashCode}`;
|
229
|
-
const inputName = `input-${valueSpecification.hashCode}`;
|
216
|
+
const enumValue = valueSelector(valueSpecification);
|
217
|
+
const resetButtonName = `reset-${valueSelector(valueSpecification)}`;
|
218
|
+
const inputName = `input-${valueSelector(valueSpecification)}`;
|
230
219
|
const changeValue = (val) => {
|
231
|
-
|
232
|
-
setValueSpecification(valueSpecification);
|
220
|
+
updateValueSpecification(valueSpecification, val.value);
|
233
221
|
handleBlur?.();
|
234
222
|
};
|
235
223
|
const onBlur = (event) => {
|
@@ -238,8 +226,9 @@ const EnumValueInstanceValueEditor = observer((props) => {
|
|
238
226
|
handleBlur?.();
|
239
227
|
}
|
240
228
|
};
|
241
|
-
return (_jsxs("div", { className: clsx('value-spec-editor', className), onBlur: onBlur, children: [_jsx(CustomSelectorInput, { className: "value-spec-editor__enum-selector", options: options, onChange: changeValue, value: enumValue ? { value: enumValue, label: enumValue
|
242
|
-
}
|
229
|
+
return (_jsxs("div", { className: clsx('value-spec-editor', className), onBlur: onBlur, children: [_jsx(CustomSelectorInput, { className: "value-spec-editor__enum-selector", options: options, onChange: changeValue, value: enumValue ? { value: enumValue, label: enumValue } : null, darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, hasError: errorChecker?.(valueSpecification), placeholder: "Select value", autoFocus: true, inputName: inputName, optionCustomization: selectorConfig?.optionCustomization }), _jsx("button", { className: "value-spec-editor__reset-btn", name: resetButtonName, title: "Reset", onClick: resetValue, children: _jsx(RefreshIcon, {}) })] }));
|
230
|
+
};
|
231
|
+
export const EnumInstanceValueEditor = observer(EnumInstanceValueEditorInner);
|
243
232
|
const stringifyValue = (values) => {
|
244
233
|
if (values.length === 0) {
|
245
234
|
return '';
|
@@ -270,45 +259,60 @@ const getPlaceHolder = (expectedType) => {
|
|
270
259
|
return 'Add';
|
271
260
|
}
|
272
261
|
}
|
273
|
-
|
262
|
+
else if (expectedType instanceof V1_PackageableType) {
|
263
|
+
switch (expectedType.fullPath) {
|
264
|
+
case PRIMITIVE_TYPE.DATE:
|
265
|
+
case PRIMITIVE_TYPE.STRICTDATE:
|
266
|
+
return 'yyyy-mm-dd';
|
267
|
+
case PRIMITIVE_TYPE.DATETIME:
|
268
|
+
case PRIMITIVE_TYPE.STRICTTIME:
|
269
|
+
return 'yyyy-mm-ddThh:mm:ss';
|
270
|
+
default:
|
271
|
+
return 'Add';
|
272
|
+
}
|
273
|
+
}
|
274
|
+
else {
|
275
|
+
throw new Error(`Cannot get placeholder for type ${expectedType}`);
|
276
|
+
}
|
274
277
|
};
|
275
|
-
const
|
276
|
-
const { valueSpecification,
|
278
|
+
const PrimitiveCollectionInstanceValueEditorInner = (props) => {
|
279
|
+
const { valueSpecification, convertTextToValueSpecification, convertValueSpecificationToText, updateValueSpecification, saveEdit, selectorSearchConfig, selectorConfig, expectedType, } = props;
|
277
280
|
// local state and variables
|
278
281
|
const applicationStore = useApplicationStore();
|
279
282
|
const inputRef = useRef(null);
|
280
283
|
const [inputValue, setInputValue] = useState('');
|
281
284
|
const [inputValueIsError, setInputValueIsError] = useState(false);
|
282
285
|
const [selectedOptions, setSelectedOptions] = useState(valueSpecification.values
|
283
|
-
.
|
286
|
+
.filter((value) => guaranteeNonNullable(value))
|
287
|
+
.map(convertValueSpecificationToText)
|
284
288
|
.filter(isNonEmptyString)
|
285
289
|
.map((value) => ({
|
286
290
|
label: value,
|
287
291
|
value,
|
288
292
|
})));
|
289
293
|
// typehead search setup
|
290
|
-
const isTypeaheadSearchEnabled = expectedType === PrimitiveType.STRING && Boolean(
|
294
|
+
const isTypeaheadSearchEnabled = expectedType === PrimitiveType.STRING && Boolean(selectorSearchConfig);
|
291
295
|
const reloadValuesFunc = isTypeaheadSearchEnabled
|
292
|
-
?
|
296
|
+
? selectorSearchConfig?.reloadValues
|
293
297
|
: undefined;
|
294
298
|
const cleanUpReloadValuesFunc = isTypeaheadSearchEnabled
|
295
|
-
?
|
299
|
+
? selectorSearchConfig?.cleanUpReloadValues
|
296
300
|
: undefined;
|
297
301
|
const isLoading = isTypeaheadSearchEnabled
|
298
|
-
?
|
302
|
+
? selectorSearchConfig?.isLoading
|
299
303
|
: undefined;
|
300
|
-
const queryOptions = isTypeaheadSearchEnabled &&
|
301
|
-
?
|
304
|
+
const queryOptions = isTypeaheadSearchEnabled && selectorSearchConfig?.values?.length
|
305
|
+
? selectorSearchConfig.values.map((e) => ({
|
302
306
|
value: e,
|
303
307
|
label: e.toString(),
|
304
308
|
}))
|
305
309
|
: undefined;
|
306
310
|
const noMatchMessage = isTypeaheadSearchEnabled && isLoading ? 'Loading...' : undefined;
|
307
|
-
const copyButtonName = `copy-${valueSpecification.
|
308
|
-
const inputName = `input-${valueSpecification.
|
311
|
+
const copyButtonName = `copy-${valueSpecification.values[0] ? convertValueSpecificationToText(valueSpecification.values[0]) : ''}`;
|
312
|
+
const inputName = `input-${valueSpecification.values[0] ? convertValueSpecificationToText(valueSpecification.values[0]) : ''}`;
|
309
313
|
// helper functions
|
310
314
|
const buildOptionForValueSpec = (value) => {
|
311
|
-
const stringValue = guaranteeNonNullable(
|
315
|
+
const stringValue = guaranteeNonNullable(convertValueSpecificationToText(value));
|
312
316
|
return {
|
313
317
|
label: stringValue,
|
314
318
|
value: stringValue,
|
@@ -324,11 +328,10 @@ const PrimitiveCollectionInstanceValueEditor = observer((props) => {
|
|
324
328
|
const convertInputValueToValueSpec = () => {
|
325
329
|
const trimmedInputValue = inputValue.trim();
|
326
330
|
if (trimmedInputValue.length) {
|
327
|
-
const newValueSpec =
|
331
|
+
const newValueSpec = convertTextToValueSpecification(expectedType, trimmedInputValue);
|
328
332
|
if (newValueSpec === null ||
|
329
|
-
|
330
|
-
|
331
|
-
isValueAlreadySelected(guaranteeNonNullable(getValueSpecificationStringValue(newValueSpec, applicationStore)))) {
|
333
|
+
convertValueSpecificationToText(newValueSpec) === undefined ||
|
334
|
+
isValueAlreadySelected(guaranteeNonNullable(convertValueSpecificationToText(newValueSpec)))) {
|
332
335
|
return null;
|
333
336
|
}
|
334
337
|
return newValueSpec;
|
@@ -381,10 +384,11 @@ const PrimitiveCollectionInstanceValueEditor = observer((props) => {
|
|
381
384
|
const finalSelectedOptions = newValueSpec !== null
|
382
385
|
? [...selectedOptions, buildOptionForValueSpec(newValueSpec)]
|
383
386
|
: selectedOptions;
|
384
|
-
|
387
|
+
const finalFormattedSelectedOptions = finalSelectedOptions
|
385
388
|
.map((option) => option.value)
|
386
|
-
.map((value) =>
|
387
|
-
.filter(isNonNullable)
|
389
|
+
.map((value) => convertTextToValueSpecification(expectedType, value))
|
390
|
+
.filter(isNonNullable);
|
391
|
+
updateValueSpecification(valueSpecification, finalFormattedSelectedOptions);
|
388
392
|
saveEdit();
|
389
393
|
};
|
390
394
|
const handleKeyDown = (event) => {
|
@@ -401,9 +405,9 @@ const PrimitiveCollectionInstanceValueEditor = observer((props) => {
|
|
401
405
|
}
|
402
406
|
const newValues = uniq(uniq(parsedData)
|
403
407
|
.map((value) => {
|
404
|
-
const newValueSpec =
|
408
|
+
const newValueSpec = convertTextToValueSpecification(expectedType, value);
|
405
409
|
return newValueSpec
|
406
|
-
?
|
410
|
+
? convertValueSpecificationToText(newValueSpec)
|
407
411
|
: null;
|
408
412
|
})
|
409
413
|
.filter(isNonNullable)).filter((value) => !isValueAlreadySelected(value));
|
@@ -424,31 +428,29 @@ const PrimitiveCollectionInstanceValueEditor = observer((props) => {
|
|
424
428
|
}), options: queryOptions, inputValue: inputValue, isMulti: true, menuIsOpen: isTypeaheadSearchEnabled &&
|
425
429
|
inputValue.length >= DEFAULT_TYPEAHEAD_SEARCH_MINIMUM_SEARCH_LENGTH, autoFocus: true, inputRef: inputRef, onChange: changeValue, onInputChange: handleInputChange, onKeyDown: handleKeyDown, onPaste: handlePaste, value: selectedOptions, darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, isLoading: isLoading, noMatchMessage: noMatchMessage, placeholder: getPlaceHolder(expectedType), components: {
|
426
430
|
DropdownIndicator: null,
|
427
|
-
}, inputName: inputName }), _jsx("button", { className: "value-spec-editor__list-editor__copy-button",
|
431
|
+
}, inputName: inputName, optionCustomization: selectorConfig?.optionCustomization }), _jsx("button", { className: "value-spec-editor__list-editor__copy-button",
|
428
432
|
// eslint-disable-next-line no-void
|
429
433
|
onClick: () => void copyValueToClipboard(), name: copyButtonName, title: "Copy values to clipboard", children: _jsx(CopyIcon, {}) }), _jsx("button", { className: "value-spec-editor__list-editor__save-button btn--dark", name: "Save", title: "Save", onClick: updateValueSpecAndSaveEdit, children: _jsx(SaveIcon, {}) })] }));
|
430
|
-
}
|
431
|
-
const
|
432
|
-
|
434
|
+
};
|
435
|
+
export const PrimitiveCollectionInstanceValueEditor = observer(PrimitiveCollectionInstanceValueEditorInner);
|
436
|
+
const EnumCollectionInstanceValueEditorInner = (props) => {
|
437
|
+
const { valueSpecification, convertTextToValueSpecification, convertValueSpecificationToText, updateValueSpecification, saveEdit, expectedType, enumOptions, selectorConfig, } = props;
|
438
|
+
guaranteeNonNullable(enumOptions, 'Must pass enum options to EnumCollectionInstanceValueEditor');
|
433
439
|
// local state and variables
|
434
440
|
const applicationStore = useApplicationStore();
|
435
|
-
const enumType = guaranteeType(valueSpecification.genericType?.value.rawType, Enumeration);
|
436
441
|
const [inputValue, setInputValue] = useState('');
|
437
442
|
const [inputValueIsError, setInputValueIsError] = useState(false);
|
438
443
|
const [selectedOptions, setSelectedOptions] = useState(valueSpecification.values
|
439
|
-
.filter((
|
440
|
-
.map(
|
441
|
-
|
442
|
-
value: at(valueSpec.values, 0).value,
|
443
|
-
})));
|
444
|
-
const availableOptions = enumType.values
|
445
|
-
.filter((value) => !selectedOptions.some((selectedValue) => selectedValue.value.name === value.name))
|
444
|
+
.filter((value) => guaranteeNonNullable(value))
|
445
|
+
.map(convertValueSpecificationToText)
|
446
|
+
.filter(isNonEmptyString)
|
446
447
|
.map((value) => ({
|
447
|
-
label: value
|
448
|
-
value
|
449
|
-
}));
|
450
|
-
const
|
451
|
-
const
|
448
|
+
label: value,
|
449
|
+
value,
|
450
|
+
})));
|
451
|
+
const availableOptions = enumOptions?.filter((value) => !selectedOptions.some((selectedValue) => selectedValue.value === value.value));
|
452
|
+
const copyButtonName = `copy-${valueSpecification.values[0] ? convertValueSpecificationToText(valueSpecification.values[0]) : ''}`;
|
453
|
+
const inputName = `input-${valueSpecification.values[0] ? convertValueSpecificationToText(valueSpecification.values[0]) : ''}`;
|
452
454
|
// helper functions
|
453
455
|
const isValueAlreadySelected = (value) => selectedOptions.map((option) => option.value).includes(value);
|
454
456
|
/**
|
@@ -459,14 +461,12 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
|
|
459
461
|
*/
|
460
462
|
const convertInputValueToEnum = () => {
|
461
463
|
const trimmedInputValue = inputValue.trim();
|
462
|
-
if (trimmedInputValue.length
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
}
|
467
|
-
return newEnum;
|
464
|
+
if (!trimmedInputValue.length ||
|
465
|
+
isValueAlreadySelected(trimmedInputValue) ||
|
466
|
+
!enumOptions?.some((option) => option.value === trimmedInputValue)) {
|
467
|
+
return null;
|
468
468
|
}
|
469
|
-
return
|
469
|
+
return trimmedInputValue;
|
470
470
|
};
|
471
471
|
const addInputValueToSelectedOptions = () => {
|
472
472
|
const newEnum = convertInputValueToEnum();
|
@@ -474,7 +474,7 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
|
|
474
474
|
setSelectedOptions([
|
475
475
|
...selectedOptions,
|
476
476
|
{
|
477
|
-
label: newEnum
|
477
|
+
label: newEnum,
|
478
478
|
value: newEnum,
|
479
479
|
},
|
480
480
|
]);
|
@@ -491,7 +491,7 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
|
|
491
491
|
setInputValue('');
|
492
492
|
}
|
493
493
|
else if (actionChange.action === 'remove-value' &&
|
494
|
-
actionChange.removedValue.value
|
494
|
+
actionChange.removedValue.value === inputValue) {
|
495
495
|
setInputValueIsError(false);
|
496
496
|
}
|
497
497
|
};
|
@@ -513,25 +513,20 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
|
|
513
513
|
if (!parsedData) {
|
514
514
|
return;
|
515
515
|
}
|
516
|
-
const newValues = uniq(uniq(parsedData)
|
517
|
-
.map((value) => convertTextToEnum(value, enumType))
|
518
|
-
.filter(isNonNullable)).filter((value) => !isValueAlreadySelected(value));
|
516
|
+
const newValues = uniq(uniq(parsedData).filter((value) => enumOptions?.some((option) => option.value === value))).filter((value) => !isValueAlreadySelected(value));
|
519
517
|
setSelectedOptions([
|
520
518
|
...selectedOptions,
|
521
|
-
...newValues.map((value) => ({ label: value
|
519
|
+
...newValues.map((value) => ({ label: value, value })),
|
522
520
|
]);
|
523
521
|
event.preventDefault();
|
524
522
|
};
|
525
|
-
const copyValueToClipboard = async () => navigator.clipboard.writeText(selectedOptions.map((option) => option.value
|
523
|
+
const copyValueToClipboard = async () => navigator.clipboard.writeText(selectedOptions.map((option) => option.value).join(','));
|
526
524
|
const updateValueSpecAndSaveEdit = () => {
|
527
525
|
const result = selectedOptions
|
528
|
-
.map((
|
529
|
-
|
530
|
-
instanceValue_setValues(enumValueInstanceValue, [EnumValueExplicitReference.create(value.value)], observerContext);
|
531
|
-
return enumValueInstanceValue;
|
532
|
-
})
|
526
|
+
.map((option) => option.value)
|
527
|
+
.map((value) => convertTextToValueSpecification(expectedType, value))
|
533
528
|
.filter(isNonNullable);
|
534
|
-
|
529
|
+
updateValueSpecification(valueSpecification, result);
|
535
530
|
saveEdit();
|
536
531
|
};
|
537
532
|
const onBlur = (event) => {
|
@@ -542,15 +537,16 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
|
|
542
537
|
};
|
543
538
|
return (_jsxs("div", { className: "value-spec-editor", onBlur: onBlur, children: [_jsx(CustomSelectorInput, { className: clsx('value-spec-editor__enum-collection-selector', {
|
544
539
|
'value-spec-editor__enum-collection-selector--error': inputValueIsError,
|
545
|
-
}), options: availableOptions, inputValue: inputValue, isMulti: true, autoFocus: true, onChange: changeValue, onInputChange: handleInputChange, onKeyDown: handleKeyDown, onPaste: handlePaste, value: selectedOptions, darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, placeholder: "Add", menuIsOpen: true, inputName: inputName }), _jsx("button", { className: "value-spec-editor__list-editor__copy-button",
|
540
|
+
}), options: availableOptions, inputValue: inputValue, isMulti: true, autoFocus: true, onChange: changeValue, onInputChange: handleInputChange, onKeyDown: handleKeyDown, onPaste: handlePaste, value: selectedOptions, darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, placeholder: "Add", menuIsOpen: true, inputName: inputName, optionCustomization: selectorConfig?.optionCustomization }), _jsx("button", { className: "value-spec-editor__list-editor__copy-button",
|
546
541
|
// eslint-disable-next-line no-void
|
547
542
|
onClick: () => void copyValueToClipboard(), name: copyButtonName, title: "Copy values to clipboard", children: _jsx(CopyIcon, {}) }), _jsx("button", { className: "value-spec-editor__list-editor__save-button btn--dark", name: "Save", title: "Save", onClick: updateValueSpecAndSaveEdit, children: _jsx(SaveIcon, {}) })] }));
|
548
|
-
}
|
543
|
+
};
|
544
|
+
export const EnumCollectionInstanceValueEditor = observer(EnumCollectionInstanceValueEditorInner);
|
549
545
|
const COLLECTION_PREVIEW_CHAR_LIMIT = 50;
|
550
|
-
const
|
551
|
-
const { valueSpecification,
|
546
|
+
const CollectionValueInstanceValueEditorInner = (props) => {
|
547
|
+
const { valueSpecification, convertTextToValueSpecification, convertValueSpecificationToText, updateValueSpecification, stringifyCollectionValueSpecification, errorChecker, className, selectorSearchConfig, selectorConfig, expectedType, enumOptions, } = props;
|
552
548
|
const [editable, setEditable] = useState(false);
|
553
|
-
const valueText =
|
549
|
+
const valueText = stringifyCollectionValueSpecification(valueSpecification);
|
554
550
|
const previewText = `List(${valueSpecification.values.length === 0
|
555
551
|
? 'empty'
|
556
552
|
: valueSpecification.values.length})${valueSpecification.values.length === 0
|
@@ -562,74 +558,156 @@ const CollectionValueInstanceValueEditor = observer((props) => {
|
|
562
558
|
const saveEdit = () => {
|
563
559
|
if (editable) {
|
564
560
|
setEditable(false);
|
565
|
-
setValueSpecification(valueSpecification);
|
566
561
|
}
|
567
562
|
};
|
568
563
|
if (editable) {
|
569
|
-
return (_jsx(_Fragment, { children: _jsx("div", { className: clsx('value-spec-editor', className), children:
|
564
|
+
return (_jsx(_Fragment, { children: _jsx("div", { className: clsx('value-spec-editor', className), children: enumOptions !== undefined ? (_jsx(EnumCollectionInstanceValueEditor, { valueSpecification: valueSpecification, updateValueSpecification: updateValueSpecification, convertTextToValueSpecification: convertTextToValueSpecification, convertValueSpecificationToText: convertValueSpecificationToText, expectedType: expectedType, saveEdit: saveEdit, enumOptions: enumOptions, selectorConfig: selectorConfig })) : (_jsx(PrimitiveCollectionInstanceValueEditor, { valueSpecification: valueSpecification, updateValueSpecification: updateValueSpecification, convertTextToValueSpecification: convertTextToValueSpecification, convertValueSpecificationToText: convertValueSpecificationToText, expectedType: expectedType, saveEdit: saveEdit, selectorSearchConfig: selectorSearchConfig, selectorConfig: selectorConfig })) }) }));
|
570
565
|
}
|
571
566
|
return (_jsxs("div", { className: clsx('value-spec-editor', className), onClick: enableEdit, title: "Click to edit", children: [_jsx("div", { className: clsx('value-spec-editor__list-editor__preview', {
|
572
|
-
'value-spec-editor__list-editor__preview--error':
|
567
|
+
'value-spec-editor__list-editor__preview--error': errorChecker?.(valueSpecification),
|
573
568
|
}), children: previewText }), _jsx("button", { className: "value-spec-editor__list-editor__edit-icon", children: _jsx(PencilIcon, {}) })] }));
|
574
|
-
}
|
569
|
+
};
|
570
|
+
export const CollectionValueInstanceValueEditor = observer(CollectionValueInstanceValueEditorInner);
|
575
571
|
const UnsupportedValueSpecificationEditor = () => (_jsx("div", { className: "value-spec-editor--unsupported", children: "unsupported" }));
|
576
|
-
const
|
577
|
-
const { valueSpecification,
|
578
|
-
return (_jsxs("div", { className:
|
572
|
+
const DateInstanceValueEditorInner = (props) => {
|
573
|
+
const { valueSpecification, valueSelector, updateValueSpecification, resetValue, handleBlur, typeCheckOption, displayAsEditableValue, className, } = props;
|
574
|
+
return (_jsxs("div", { className: clsx('value-spec-editor', className), children: [_jsx(CustomDatePicker, { valueSpecification: valueSpecification, valueSelector: valueSelector, typeCheckOption: typeCheckOption, updateValueSpecification: updateValueSpecification, hasError: valueSpecification instanceof PrimitiveInstanceValue &&
|
579
575
|
!isValidInstanceValue(valueSpecification), handleBlur: handleBlur, displayAsEditableValue: displayAsEditableValue }), !displayAsEditableValue && (_jsx("button", { className: "value-spec-editor__reset-btn", name: "Reset", title: "Reset", onClick: resetValue, children: _jsx(RefreshIcon, {}) }))] }));
|
580
|
-
}
|
576
|
+
};
|
577
|
+
export const DateInstanceValueEditor = observer(DateInstanceValueEditorInner);
|
581
578
|
/**
|
582
579
|
* TODO we should pass in the props `resetValueSpecification`. Reset
|
583
580
|
* should be part of this editor. Also through here we can call `observe_` accordingly.
|
584
581
|
*
|
585
582
|
* See https://github.com/finos/legend-studio/pull/1021
|
586
583
|
*/
|
587
|
-
export const BasicValueSpecificationEditor = forwardRef(function
|
588
|
-
const { className, valueSpecification, graph, observerContext, typeCheckOption, setValueSpecification, resetValue, selectorConfig, isConstant, handleBlur, handleKeyDown, displayDateEditorAsEditableValue, } = props;
|
584
|
+
export const BasicValueSpecificationEditor = forwardRef(function BasicValueSpecificationEditorInner(props, ref) {
|
585
|
+
const { className, valueSpecification, graph, observerContext, typeCheckOption, setValueSpecification, resetValue, selectorSearchConfig, selectorConfig, isConstant, handleBlur, handleKeyDown, displayDateEditorAsEditableValue, } = props;
|
586
|
+
const applicationStore = useApplicationStore();
|
587
|
+
const errorChecker = (_valueSpecification) => !isValidInstanceValue(_valueSpecification);
|
588
|
+
const dateValueSelector = (_valueSpecification) => {
|
589
|
+
return _valueSpecification instanceof SimpleFunctionExpression
|
590
|
+
? ''
|
591
|
+
: _valueSpecification.values[0];
|
592
|
+
};
|
593
|
+
const dateUpdateValueSpecification = (_valueSpecification, value, options) => {
|
594
|
+
if (value instanceof CustomDateOption) {
|
595
|
+
setValueSpecification(buildPureAdjustDateFunction(value, graph, observerContext));
|
596
|
+
}
|
597
|
+
else if (value instanceof CustomFirstDayOfOption) {
|
598
|
+
setValueSpecification(buildPureDateFunctionExpression(value, graph, observerContext));
|
599
|
+
}
|
600
|
+
else if (value instanceof CustomPreviousDayOfWeekOption) {
|
601
|
+
setValueSpecification(buildPureDateFunctionExpression(value, graph, observerContext));
|
602
|
+
}
|
603
|
+
else if (value instanceof DatePickerOption) {
|
604
|
+
setValueSpecification(buildPureDateFunctionExpression(value, graph, observerContext));
|
605
|
+
}
|
606
|
+
else {
|
607
|
+
if (_valueSpecification instanceof SimpleFunctionExpression) {
|
608
|
+
setValueSpecification(buildPrimitiveInstanceValue(graph, guaranteeNonNullable(options?.primitiveTypeEnum), value, observerContext));
|
609
|
+
}
|
610
|
+
else if (_valueSpecification instanceof InstanceValue) {
|
611
|
+
instanceValue_setValue(_valueSpecification, value, 0, observerContext);
|
612
|
+
if (_valueSpecification.genericType.value.rawType.path !==
|
613
|
+
guaranteeNonNullable(options?.primitiveTypeEnum)) {
|
614
|
+
valueSpecification_setGenericType(_valueSpecification, GenericTypeExplicitReference.create(new GenericType(getPrimitiveTypeInstanceFromEnum(guaranteeNonNullable(options?.primitiveTypeEnum)))));
|
615
|
+
}
|
616
|
+
setValueSpecification(_valueSpecification);
|
617
|
+
}
|
618
|
+
else if (options?.primitiveTypeEnum === PRIMITIVE_TYPE.LATESTDATE) {
|
619
|
+
setValueSpecification(buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.LATESTDATE, value, observerContext));
|
620
|
+
}
|
621
|
+
}
|
622
|
+
};
|
589
623
|
if (valueSpecification instanceof PrimitiveInstanceValue) {
|
590
624
|
const _type = valueSpecification.genericType.value.rawType;
|
625
|
+
// eslint-disable-next-line comma-spacing
|
626
|
+
const valueSelector = (val) => val.values[0];
|
627
|
+
// eslint-disable-next-line comma-spacing
|
628
|
+
const updateValueSpecification = (_valueSpecification, value) => {
|
629
|
+
instanceValue_setValue(_valueSpecification, value, 0, observerContext);
|
630
|
+
setValueSpecification(_valueSpecification);
|
631
|
+
};
|
591
632
|
switch (_type.path) {
|
592
633
|
case PRIMITIVE_TYPE.STRING:
|
593
|
-
return (_jsx(StringPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification,
|
634
|
+
return (_jsx(StringPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification, valueSelector: valueSelector, updateValueSpecification: updateValueSpecification, errorChecker: errorChecker, className: className, resetValue: resetValue, selectorSearchConfig: selectorSearchConfig, selectorConfig: selectorConfig, ref: ref, handleBlur: handleBlur, handleKeyDown: handleKeyDown }));
|
594
635
|
case PRIMITIVE_TYPE.BOOLEAN:
|
595
|
-
return (_jsx(BooleanPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification,
|
636
|
+
return (_jsx(BooleanPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification, valueSelector: valueSelector, updateValueSpecification: updateValueSpecification, className: className, resetValue: resetValue }));
|
596
637
|
case PRIMITIVE_TYPE.NUMBER:
|
597
638
|
case PRIMITIVE_TYPE.FLOAT:
|
598
639
|
case PRIMITIVE_TYPE.DECIMAL:
|
599
640
|
case PRIMITIVE_TYPE.BINARY:
|
600
641
|
case PRIMITIVE_TYPE.BYTE:
|
601
642
|
case PRIMITIVE_TYPE.INTEGER:
|
602
|
-
return (_jsx(NumberPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification, isInteger: _type.path === PRIMITIVE_TYPE.INTEGER,
|
643
|
+
return (_jsx(NumberPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification, valueSelector: valueSelector, isInteger: _type.path === PRIMITIVE_TYPE.INTEGER, updateValueSpecification: updateValueSpecification, errorChecker: errorChecker, className: className, resetValue: resetValue, ref: ref, handleBlur: handleBlur, handleKeyDown: handleKeyDown }));
|
603
644
|
case PRIMITIVE_TYPE.DATE:
|
604
645
|
case PRIMITIVE_TYPE.STRICTDATE:
|
605
646
|
case PRIMITIVE_TYPE.DATETIME:
|
606
647
|
case PRIMITIVE_TYPE.LATESTDATE:
|
607
|
-
return (_jsx(DateInstanceValueEditor, { valueSpecification: valueSpecification,
|
648
|
+
return (_jsx(DateInstanceValueEditor, { valueSpecification: valueSpecification, valueSelector: dateValueSelector, typeCheckOption: typeCheckOption, className: className, updateValueSpecification: dateUpdateValueSpecification, resetValue: resetValue, handleBlur: handleBlur, displayAsEditableValue: displayDateEditorAsEditableValue, errorChecker: (_valueSpecification) => _valueSpecification instanceof PrimitiveInstanceValue &&
|
649
|
+
errorChecker(_valueSpecification) }));
|
608
650
|
default:
|
609
651
|
return _jsx(UnsupportedValueSpecificationEditor, {});
|
610
652
|
}
|
611
653
|
}
|
612
654
|
else if (valueSpecification instanceof EnumValueInstanceValue) {
|
613
|
-
|
655
|
+
const enumType = guaranteeType(valueSpecification.genericType?.value.rawType, Enumeration);
|
656
|
+
const options = enumType.values.map((value) => ({
|
657
|
+
label: value.name,
|
658
|
+
value: value.name,
|
659
|
+
}));
|
660
|
+
return (_jsx(EnumInstanceValueEditor, { valueSpecification: valueSpecification, valueSelector: (val) => val.values[0] === undefined ? null : val.values[0].value.name, options: options, className: className, resetValue: resetValue, updateValueSpecification: (_valueSpecification, value) => {
|
661
|
+
const enumValue = guaranteeNonNullable(enumType.values.find((val) => val.name === value), `Unable to find enum value ${value} in enumeration ${enumType.name}`);
|
662
|
+
instanceValue_setValue(_valueSpecification, EnumValueExplicitReference.create(enumValue), 0, observerContext);
|
663
|
+
setValueSpecification(_valueSpecification);
|
664
|
+
}, errorChecker: (_valueSpecification) => !isValidInstanceValue(_valueSpecification), handleBlur: handleBlur, selectorConfig: selectorConfig }));
|
614
665
|
}
|
615
666
|
else if (valueSpecification instanceof CollectionInstanceValue &&
|
616
667
|
valueSpecification.genericType) {
|
668
|
+
const updateValueSpecification = (collectionValueSpecification, valueSpecifications) => {
|
669
|
+
instanceValue_setValues(collectionValueSpecification, valueSpecifications, observerContext);
|
670
|
+
setValueSpecification(collectionValueSpecification);
|
671
|
+
};
|
672
|
+
const convertTextToValueSpecification = (type, text) => {
|
673
|
+
if (type instanceof Enumeration) {
|
674
|
+
const enumValue = convertTextToEnum(text, type);
|
675
|
+
if (enumValue) {
|
676
|
+
const enumValueInstanceValue = new EnumValueInstanceValue(GenericTypeExplicitReference.create(new GenericType(type)));
|
677
|
+
instanceValue_setValues(enumValueInstanceValue, [EnumValueExplicitReference.create(enumValue)], observerContext);
|
678
|
+
return observe_ValueSpecification(enumValueInstanceValue, observerContext);
|
679
|
+
}
|
680
|
+
}
|
681
|
+
else {
|
682
|
+
const primitiveVal = convertTextToPrimitiveInstanceValue(guaranteeType(type, Type), text, observerContext);
|
683
|
+
if (primitiveVal) {
|
684
|
+
return observe_ValueSpecification(primitiveVal, observerContext);
|
685
|
+
}
|
686
|
+
}
|
687
|
+
return null;
|
688
|
+
};
|
689
|
+
const enumOptions = typeCheckOption.expectedType instanceof Enumeration
|
690
|
+
? typeCheckOption.expectedType.values.map((enumValue) => ({
|
691
|
+
label: enumValue.name,
|
692
|
+
value: enumValue.name,
|
693
|
+
}))
|
694
|
+
: undefined;
|
617
695
|
// NOTE: since when we fill in the arguments, `[]` (or `nullish` value in Pure)
|
618
696
|
// is used for parameters we don't handle, we should not attempt to support empty collection
|
619
697
|
// without generic type here as that is equivalent to `[]`
|
620
|
-
return (_jsx(CollectionValueInstanceValueEditor, { valueSpecification: valueSpecification,
|
698
|
+
return (_jsx(CollectionValueInstanceValueEditor, { valueSpecification: valueSpecification, updateValueSpecification: updateValueSpecification, expectedType: typeCheckOption.expectedType, className: className, selectorSearchConfig: selectorSearchConfig, selectorConfig: selectorConfig, stringifyCollectionValueSpecification: (collectionValueSpecification) => stringifyValue(collectionValueSpecification.values), errorChecker: errorChecker, convertValueSpecificationToText: (_valueSpecification) => getValueSpecificationStringValue(_valueSpecification, applicationStore, { omitEnumOwnerName: true }), convertTextToValueSpecification: convertTextToValueSpecification, enumOptions: enumOptions }));
|
621
699
|
}
|
622
700
|
// property expression
|
623
701
|
else if (valueSpecification instanceof VariableExpression) {
|
624
702
|
return (_jsx(VariableExpressionParameterEditor, { valueSpecification: valueSpecification, className: className, resetValue: resetValue, isConstant: Boolean(isConstant) }));
|
625
703
|
}
|
626
704
|
else if (valueSpecification instanceof INTERNAL__PropagatedValue) {
|
627
|
-
return (_jsx(BasicValueSpecificationEditor, { valueSpecification: valueSpecification.getValue(), graph: graph, observerContext: observerContext, typeCheckOption: typeCheckOption, setValueSpecification: setValueSpecification, resetValue: resetValue, handleBlur: handleBlur, handleKeyDown: handleKeyDown, displayDateEditorAsEditableValue: displayDateEditorAsEditableValue }));
|
705
|
+
return (_jsx(BasicValueSpecificationEditor, { valueSpecification: valueSpecification.getValue(), graph: graph, observerContext: observerContext, typeCheckOption: typeCheckOption, setValueSpecification: setValueSpecification, resetValue: resetValue, handleBlur: handleBlur, handleKeyDown: handleKeyDown, displayDateEditorAsEditableValue: displayDateEditorAsEditableValue, selectorSearchConfig: selectorSearchConfig, selectorConfig: selectorConfig }));
|
628
706
|
}
|
629
707
|
else if (valueSpecification instanceof SimpleFunctionExpression) {
|
630
708
|
if (isSubType(typeCheckOption.expectedType, PrimitiveType.DATE)) {
|
631
709
|
if (isUsedDateFunctionSupportedInFormMode(valueSpecification)) {
|
632
|
-
return (_jsx(DateInstanceValueEditor, { valueSpecification: valueSpecification,
|
710
|
+
return (_jsx(DateInstanceValueEditor, { valueSpecification: valueSpecification, valueSelector: dateValueSelector, typeCheckOption: typeCheckOption, className: className, updateValueSpecification: dateUpdateValueSpecification, resetValue: resetValue, handleBlur: handleBlur, displayAsEditableValue: displayDateEditorAsEditableValue }));
|
633
711
|
}
|
634
712
|
else {
|
635
713
|
return _jsx(UnsupportedValueSpecificationEditor, {});
|
@@ -643,15 +721,18 @@ export const BasicValueSpecificationEditor = forwardRef(function _BasicValueSpec
|
|
643
721
|
const simplifiedValue = simplifyValueExpression(valueSpecification, observerContext);
|
644
722
|
if (simplifiedValue instanceof PrimitiveInstanceValue &&
|
645
723
|
isSubType(simplifiedValue.genericType.value.rawType, PrimitiveType.NUMBER)) {
|
646
|
-
return (_jsx(NumberPrimitiveInstanceValueEditor, { valueSpecification: simplifiedValue, isInteger: simplifiedValue.genericType.value.rawType ===
|
647
|
-
PrimitiveType.INTEGER,
|
724
|
+
return (_jsx(NumberPrimitiveInstanceValueEditor, { valueSpecification: simplifiedValue, valueSelector: (val) => val.values[0], isInteger: simplifiedValue.genericType.value.rawType ===
|
725
|
+
PrimitiveType.INTEGER, updateValueSpecification: (_valueSpecification, value) => {
|
726
|
+
instanceValue_setValue(_valueSpecification, value, 0, observerContext);
|
727
|
+
setValueSpecification(_valueSpecification);
|
728
|
+
}, className: className, resetValue: resetValue, ref: ref, handleBlur: handleBlur, handleKeyDown: handleKeyDown }));
|
648
729
|
}
|
649
730
|
}
|
650
731
|
}
|
651
732
|
return _jsx(UnsupportedValueSpecificationEditor, {});
|
652
733
|
});
|
653
734
|
export const EditableBasicValueSpecificationEditor = observer((props) => {
|
654
|
-
const { valueSpecification, setValueSpecification, graph, observerContext, typeCheckOption, resetValue, selectorConfig, isConstant, initializeAsEditable, } = props;
|
735
|
+
const { valueSpecification, setValueSpecification, graph, observerContext, typeCheckOption, resetValue, selectorSearchConfig, selectorConfig, isConstant, initializeAsEditable, } = props;
|
655
736
|
const applicationStore = useApplicationStore();
|
656
737
|
const [isEditingValue, setIsEditingValue] = useState(initializeAsEditable ?? false);
|
657
738
|
const inputRef = useRef(null);
|
@@ -669,7 +750,7 @@ export const EditableBasicValueSpecificationEditor = observer((props) => {
|
|
669
750
|
const valueSpecStringValue = getValueSpecificationStringValue(valueSpecification, applicationStore, {
|
670
751
|
omitEnumOwnerName: true,
|
671
752
|
});
|
672
|
-
return shouldRenderEditor ? (_jsx(BasicValueSpecificationEditor, { valueSpecification: valueSpecification, setValueSpecification: setValueSpecification, graph: graph, observerContext: observerContext, typeCheckOption: typeCheckOption, resetValue: resetValue, selectorConfig: selectorConfig, isConstant: isConstant, ref: inputRef, handleBlur: () => setIsEditingValue(false), handleKeyDown: (event) => {
|
753
|
+
return shouldRenderEditor ? (_jsx(BasicValueSpecificationEditor, { valueSpecification: valueSpecification, setValueSpecification: setValueSpecification, graph: graph, observerContext: observerContext, typeCheckOption: typeCheckOption, resetValue: resetValue, selectorSearchConfig: selectorSearchConfig, selectorConfig: selectorConfig, isConstant: isConstant, ref: inputRef, handleBlur: () => setIsEditingValue(false), handleKeyDown: (event) => {
|
673
754
|
if (event.key === 'Enter') {
|
674
755
|
setIsEditingValue(false);
|
675
756
|
}
|