@finos/legend-query-builder 4.16.20 → 4.16.22

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.
Files changed (59) hide show
  1. package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.d.ts +23 -1
  2. package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.d.ts.map +1 -1
  3. package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.js +16 -2
  4. package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.js.map +1 -1
  5. package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.js +1 -1
  6. package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.js.map +1 -1
  7. package/lib/components/filter/QueryBuilderFilterPanel.js +1 -1
  8. package/lib/components/filter/QueryBuilderFilterPanel.js.map +1 -1
  9. package/lib/components/shared/BasicValueSpecificationEditor.d.ts +162 -4
  10. package/lib/components/shared/BasicValueSpecificationEditor.d.ts.map +1 -1
  11. package/lib/components/shared/BasicValueSpecificationEditor.js +253 -172
  12. package/lib/components/shared/BasicValueSpecificationEditor.js.map +1 -1
  13. package/lib/components/shared/CustomDatePicker.d.ts +8 -55
  14. package/lib/components/shared/CustomDatePicker.d.ts.map +1 -1
  15. package/lib/components/shared/CustomDatePicker.js +33 -417
  16. package/lib/components/shared/CustomDatePicker.js.map +1 -1
  17. package/lib/components/shared/CustomDatePickerHelper.d.ts +145 -0
  18. package/lib/components/shared/CustomDatePickerHelper.d.ts.map +1 -0
  19. package/lib/components/shared/CustomDatePickerHelper.js +517 -0
  20. package/lib/components/shared/CustomDatePickerHelper.js.map +1 -0
  21. package/lib/components/shared/QueryBuilderVariableSelector.js +1 -1
  22. package/lib/components/shared/QueryBuilderVariableSelector.js.map +1 -1
  23. package/lib/components/shared/V1_BasicValueSpecificationEditor.d.ts +38 -0
  24. package/lib/components/shared/V1_BasicValueSpecificationEditor.d.ts.map +1 -0
  25. package/lib/components/shared/V1_BasicValueSpecificationEditor.js +166 -0
  26. package/lib/components/shared/V1_BasicValueSpecificationEditor.js.map +1 -0
  27. package/lib/index.css +2 -2
  28. package/lib/index.css.map +1 -1
  29. package/lib/index.d.ts +4 -0
  30. package/lib/index.d.ts.map +1 -1
  31. package/lib/index.js +4 -0
  32. package/lib/index.js.map +1 -1
  33. package/lib/package.json +1 -1
  34. package/lib/stores/shared/V1_ValueSpecificationEditorHelper.d.ts +23 -0
  35. package/lib/stores/shared/V1_ValueSpecificationEditorHelper.d.ts.map +1 -0
  36. package/lib/stores/shared/V1_ValueSpecificationEditorHelper.js +83 -0
  37. package/lib/stores/shared/V1_ValueSpecificationEditorHelper.js.map +1 -0
  38. package/lib/stores/shared/V1_ValueSpecificationModifierHelper.d.ts +20 -0
  39. package/lib/stores/shared/V1_ValueSpecificationModifierHelper.d.ts.map +1 -0
  40. package/lib/stores/shared/V1_ValueSpecificationModifierHelper.js +38 -0
  41. package/lib/stores/shared/V1_ValueSpecificationModifierHelper.js.map +1 -0
  42. package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts +4 -1
  43. package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts.map +1 -1
  44. package/lib/stores/shared/ValueSpecificationEditorHelper.js +23 -2
  45. package/lib/stores/shared/ValueSpecificationEditorHelper.js.map +1 -1
  46. package/package.json +10 -10
  47. package/src/components/__test-utils__/QueryBuilderComponentTestUtils.tsx +103 -12
  48. package/src/components/fetch-structure/QueryBuilderPostFilterPanel.tsx +1 -1
  49. package/src/components/filter/QueryBuilderFilterPanel.tsx +1 -1
  50. package/src/components/shared/BasicValueSpecificationEditor.tsx +1477 -1088
  51. package/src/components/shared/CustomDatePicker.tsx +146 -905
  52. package/src/components/shared/CustomDatePickerHelper.ts +984 -0
  53. package/src/components/shared/QueryBuilderVariableSelector.tsx +1 -1
  54. package/src/components/shared/V1_BasicValueSpecificationEditor.tsx +409 -0
  55. package/src/index.ts +7 -0
  56. package/src/stores/shared/V1_ValueSpecificationEditorHelper.ts +131 -0
  57. package/src/stores/shared/V1_ValueSpecificationModifierHelper.ts +76 -0
  58. package/src/stores/shared/ValueSpecificationEditorHelper.ts +71 -2
  59. 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 { PrimitiveInstanceValue, CollectionInstanceValue, EnumValueInstanceValue, INTERNAL__PropagatedValue, SimpleFunctionExpression, VariableExpression, EnumValueExplicitReference, PrimitiveType, PRIMITIVE_TYPE, GenericTypeExplicitReference, GenericType, Enumeration, getMultiplicityDescription, matchFunctionName, isSubType, InstanceValue, } from '@finos/legend-graph';
20
- import { guaranteeNonNullable, isNonNullable, guaranteeIsNumber, csvStringify, guaranteeType, isNonEmptyString, parseCSVString, uniq, at, } from '@finos/legend-shared';
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
- const StringPrimitiveInstanceValueEditor = observer(forwardRef(function StringPrimitiveInstanceValueEditor(props, ref) {
54
- const { valueSpecification, className, resetValue, setValueSpecification, selectorConfig, observerContext, handleBlur, handleKeyDown, } = props;
55
- const useSelector = Boolean(selectorConfig);
54
+ // eslint-disable-next-line comma-spacing
55
+ const StringPrimitiveInstanceValueEditorInner = (props, ref) => {
56
+ const { valueSpecification, valueSelector, updateValueSpecification, errorChecker, resetValue, handleBlur, handleKeyDown, className, selectorSearchConfig, selectorConfig, lightMode, readOnly, } = props;
57
+ const useSelector = Boolean(selectorSearchConfig);
56
58
  const applicationStore = useApplicationStore();
57
- const value = valueSpecification.values[0];
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
- updateValueSpec(event.target.value);
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 = selectorConfig?.reloadValues;
65
+ const reloadValuesFunc = selectorSearchConfig?.reloadValues;
68
66
  const changeValue = (val) => {
69
67
  const newValue = val === null ? '' : val.value.toString();
70
- updateValueSpec(newValue);
68
+ updateValueSpecification(valueSpecification, newValue);
71
69
  };
72
70
  const handleInputChange = (inputValue, actionChange) => {
73
71
  if (actionChange.action === 'input-change') {
74
- updateValueSpec(inputValue);
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
- selectorConfig?.cleanUpReloadValues?.();
81
+ selectorSearchConfig?.cleanUpReloadValues?.();
84
82
  }
85
83
  };
86
- const isLoading = selectorConfig?.isLoading;
87
- const queryOptions = selectorConfig?.values?.length
88
- ? selectorConfig.values.map((e) => ({
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 = selectorConfig?.values === undefined ? () => null : undefined;
94
- const resetButtonName = `reset-${valueSpecification.hashCode}`;
95
- const inputName = `input-${valueSpecification.hashCode}`;
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: !lightMode, isLoading: isLoading, allowCreateWhileLoading: true, noOptionsMessage: noOptionsMessage, components: {
104
101
  DropdownIndicator: null,
105
- }, hasError: !isValidInstanceValue(valueSpecification), placeholder: value === '' ? '(empty)' : undefined, inputRef: ref, onKeyDown: handleKeyDown, inputName: inputName })) : (_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: !isValidInstanceValue(valueSpecification)
102
+ }, hasError: errorChecker?.(valueSpecification), placeholder: value === '' ? '(empty)' : undefined, inputRef: ref, onKeyDown: handleKeyDown, inputName: inputName, optionCustomization: selectorConfig?.optionCustomization, disabled: readOnly })) : (_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
- : 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 BooleanPrimitiveInstanceValueEditor = observer((props) => {
110
- const { valueSpecification, className, resetValue, setValueSpecification, observerContext, } = props;
111
- const value = valueSpecification.values[0];
104
+ : undefined, onKeyDown: handleKeyDown, name: inputName, disabled: readOnly })), _jsx("button", { className: "value-spec-editor__reset-btn", name: resetButtonName, title: "Reset", onClick: resetValue, disabled: readOnly, children: _jsx(RefreshIcon, {}) })] }));
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, readOnly, } = props;
110
+ const value = valueSelector(valueSpecification);
112
111
  const toggleValue = () => {
113
- instanceValue_setValue(valueSpecification, !value, 0, observerContext);
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
- }), 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 NumberPrimitiveInstanceValueEditor = observer(forwardRef(function NumberPrimitiveInstanceValueEditor(props, ref) {
121
- const { valueSpecification, isInteger, className, resetValue, setValueSpecification, observerContext, handleBlur, handleKeyDown, } = props;
122
- const [value, setValue] = useState(valueSpecification.values[0] === null
123
- ? ''
124
- : valueSpecification.values[0].toString());
116
+ }), onClick: toggleValue, disabled: readOnly, children: value ? _jsx(CheckSquareIcon, {}) : _jsx(SquareIcon, {}) }), _jsx("button", { className: "value-spec-editor__reset-btn", name: "Reset", title: "Reset", onClick: resetValue, disabled: readOnly, children: _jsx(RefreshIcon, {}) })] }));
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, readOnly, } = 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.values[0]) {
139
- instanceValue_setValue(valueSpecification, parsedValue, 0, observerContext);
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.values[0] !== null &&
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.values[0]) {
193
- const valueFromValueSpec = valueSpecification.values[0] !== null
194
- ? valueSpecification.values[0].toString()
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.hashCode}`;
200
- const inputName = `input-${valueSpecification.hashCode}`;
201
- const calculateButtonName = `calculate-${valueSpecification.hashCode}`;
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,22 @@ 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': !isValidInstanceValue(valueSpecification),
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
- }, 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 EnumValueInstanceValueEditor = observer((props) => {
218
- const { valueSpecification, className, resetValue, setValueSpecification, observerContext, handleBlur, } = props;
219
- const applicationStore = useApplicationStore();
220
- const enumType = guaranteeType(valueSpecification.genericType?.value.rawType, Enumeration);
221
- const enumValue = valueSpecification.values[0] === undefined
222
- ? null
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}`;
209
+ }, name: inputName, disabled: readOnly }), _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, disabled: readOnly, children: _jsx(CalculateIcon, {}) }) })] }), _jsx("button", { className: "value-spec-editor__reset-btn", name: resetButtonName, title: "Reset", onClick: resetValue, disabled: readOnly, children: _jsx(RefreshIcon, {}) })] }));
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, lightMode, readOnly, } = props;
215
+ const enumValue = valueSelector(valueSpecification);
216
+ const resetButtonName = `reset-${valueSelector(valueSpecification)}`;
217
+ const inputName = `input-${valueSelector(valueSpecification)}`;
230
218
  const changeValue = (val) => {
231
- instanceValue_setValue(valueSpecification, EnumValueExplicitReference.create(val.value), 0, observerContext);
232
- setValueSpecification(valueSpecification);
219
+ updateValueSpecification(valueSpecification, val.value);
233
220
  handleBlur?.();
234
221
  };
235
222
  const onBlur = (event) => {
@@ -238,8 +225,9 @@ const EnumValueInstanceValueEditor = observer((props) => {
238
225
  handleBlur?.();
239
226
  }
240
227
  };
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.name } : null, darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, hasError: !isValidInstanceValue(valueSpecification), placeholder: "Select value", autoFocus: true, inputName: inputName }), _jsx("button", { className: "value-spec-editor__reset-btn", name: resetButtonName, title: "Reset", onClick: resetValue, children: _jsx(RefreshIcon, {}) })] }));
242
- });
228
+ 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: !lightMode, hasError: errorChecker?.(valueSpecification), placeholder: "Select value", autoFocus: true, inputName: inputName, optionCustomization: selectorConfig?.optionCustomization, disabled: readOnly }), _jsx("button", { className: "value-spec-editor__reset-btn", name: resetButtonName, title: "Reset", onClick: resetValue, disabled: readOnly, children: _jsx(RefreshIcon, {}) })] }));
229
+ };
230
+ export const EnumInstanceValueEditor = observer(EnumInstanceValueEditorInner);
243
231
  const stringifyValue = (values) => {
244
232
  if (values.length === 0) {
245
233
  return '';
@@ -270,45 +258,60 @@ const getPlaceHolder = (expectedType) => {
270
258
  return 'Add';
271
259
  }
272
260
  }
273
- return 'Add';
261
+ else if (expectedType instanceof V1_PackageableType) {
262
+ switch (expectedType.fullPath) {
263
+ case PRIMITIVE_TYPE.DATE:
264
+ case PRIMITIVE_TYPE.STRICTDATE:
265
+ return 'yyyy-mm-dd';
266
+ case PRIMITIVE_TYPE.DATETIME:
267
+ case PRIMITIVE_TYPE.STRICTTIME:
268
+ return 'yyyy-mm-ddThh:mm:ss';
269
+ default:
270
+ return 'Add';
271
+ }
272
+ }
273
+ else {
274
+ throw new Error(`Cannot get placeholder for type ${expectedType}`);
275
+ }
274
276
  };
275
- const PrimitiveCollectionInstanceValueEditor = observer((props) => {
276
- const { valueSpecification, expectedType, saveEdit, selectorConfig, observerContext, } = props;
277
+ const PrimitiveCollectionInstanceValueEditorInner = (props) => {
278
+ const { valueSpecification, convertTextToValueSpecification, convertValueSpecificationToText, updateValueSpecification, saveEdit, selectorSearchConfig, selectorConfig, expectedType, lightMode, readOnly, } = props;
277
279
  // local state and variables
278
280
  const applicationStore = useApplicationStore();
279
281
  const inputRef = useRef(null);
280
282
  const [inputValue, setInputValue] = useState('');
281
283
  const [inputValueIsError, setInputValueIsError] = useState(false);
282
284
  const [selectedOptions, setSelectedOptions] = useState(valueSpecification.values
283
- .map((valueSpec) => getValueSpecificationStringValue(valueSpec, applicationStore))
285
+ .filter((value) => guaranteeNonNullable(value))
286
+ .map(convertValueSpecificationToText)
284
287
  .filter(isNonEmptyString)
285
288
  .map((value) => ({
286
289
  label: value,
287
290
  value,
288
291
  })));
289
292
  // typehead search setup
290
- const isTypeaheadSearchEnabled = expectedType === PrimitiveType.STRING && Boolean(selectorConfig);
293
+ const isTypeaheadSearchEnabled = expectedType === PrimitiveType.STRING && Boolean(selectorSearchConfig);
291
294
  const reloadValuesFunc = isTypeaheadSearchEnabled
292
- ? selectorConfig?.reloadValues
295
+ ? selectorSearchConfig?.reloadValues
293
296
  : undefined;
294
297
  const cleanUpReloadValuesFunc = isTypeaheadSearchEnabled
295
- ? selectorConfig?.cleanUpReloadValues
298
+ ? selectorSearchConfig?.cleanUpReloadValues
296
299
  : undefined;
297
300
  const isLoading = isTypeaheadSearchEnabled
298
- ? selectorConfig?.isLoading
301
+ ? selectorSearchConfig?.isLoading
299
302
  : undefined;
300
- const queryOptions = isTypeaheadSearchEnabled && selectorConfig?.values?.length
301
- ? selectorConfig.values.map((e) => ({
303
+ const queryOptions = isTypeaheadSearchEnabled && selectorSearchConfig?.values?.length
304
+ ? selectorSearchConfig.values.map((e) => ({
302
305
  value: e,
303
306
  label: e.toString(),
304
307
  }))
305
308
  : undefined;
306
309
  const noMatchMessage = isTypeaheadSearchEnabled && isLoading ? 'Loading...' : undefined;
307
- const copyButtonName = `copy-${valueSpecification.hashCode}`;
308
- const inputName = `input-${valueSpecification.hashCode}`;
310
+ const copyButtonName = `copy-${valueSpecification.values[0] ? convertValueSpecificationToText(valueSpecification.values[0]) : ''}`;
311
+ const inputName = `input-${valueSpecification.values[0] ? convertValueSpecificationToText(valueSpecification.values[0]) : ''}`;
309
312
  // helper functions
310
313
  const buildOptionForValueSpec = (value) => {
311
- const stringValue = guaranteeNonNullable(getValueSpecificationStringValue(value, applicationStore));
314
+ const stringValue = guaranteeNonNullable(convertValueSpecificationToText(value));
312
315
  return {
313
316
  label: stringValue,
314
317
  value: stringValue,
@@ -324,11 +327,10 @@ const PrimitiveCollectionInstanceValueEditor = observer((props) => {
324
327
  const convertInputValueToValueSpec = () => {
325
328
  const trimmedInputValue = inputValue.trim();
326
329
  if (trimmedInputValue.length) {
327
- const newValueSpec = convertTextToPrimitiveInstanceValue(expectedType, trimmedInputValue, observerContext);
330
+ const newValueSpec = convertTextToValueSpecification(expectedType, trimmedInputValue);
328
331
  if (newValueSpec === null ||
329
- getValueSpecificationStringValue(newValueSpec, applicationStore) ===
330
- undefined ||
331
- isValueAlreadySelected(guaranteeNonNullable(getValueSpecificationStringValue(newValueSpec, applicationStore)))) {
332
+ convertValueSpecificationToText(newValueSpec) === undefined ||
333
+ isValueAlreadySelected(guaranteeNonNullable(convertValueSpecificationToText(newValueSpec)))) {
332
334
  return null;
333
335
  }
334
336
  return newValueSpec;
@@ -381,10 +383,11 @@ const PrimitiveCollectionInstanceValueEditor = observer((props) => {
381
383
  const finalSelectedOptions = newValueSpec !== null
382
384
  ? [...selectedOptions, buildOptionForValueSpec(newValueSpec)]
383
385
  : selectedOptions;
384
- instanceValue_setValues(valueSpecification, finalSelectedOptions
386
+ const finalFormattedSelectedOptions = finalSelectedOptions
385
387
  .map((option) => option.value)
386
- .map((value) => convertTextToPrimitiveInstanceValue(expectedType, value, observerContext))
387
- .filter(isNonNullable), observerContext);
388
+ .map((value) => convertTextToValueSpecification(expectedType, value))
389
+ .filter(isNonNullable);
390
+ updateValueSpecification(valueSpecification, finalFormattedSelectedOptions);
388
391
  saveEdit();
389
392
  };
390
393
  const handleKeyDown = (event) => {
@@ -401,9 +404,9 @@ const PrimitiveCollectionInstanceValueEditor = observer((props) => {
401
404
  }
402
405
  const newValues = uniq(uniq(parsedData)
403
406
  .map((value) => {
404
- const newValueSpec = convertTextToPrimitiveInstanceValue(expectedType, value, observerContext);
407
+ const newValueSpec = convertTextToValueSpecification(expectedType, value);
405
408
  return newValueSpec
406
- ? getValueSpecificationStringValue(newValueSpec, applicationStore)
409
+ ? convertValueSpecificationToText(newValueSpec)
407
410
  : null;
408
411
  })
409
412
  .filter(isNonNullable)).filter((value) => !isValueAlreadySelected(value));
@@ -422,33 +425,30 @@ const PrimitiveCollectionInstanceValueEditor = observer((props) => {
422
425
  return (_jsxs("div", { className: "value-spec-editor", onBlur: onBlur, children: [_jsx(CustomSelectorInput, { className: clsx('value-spec-editor__primitive-collection-selector', {
423
426
  'value-spec-editor__primitive-collection-selector--error': inputValueIsError,
424
427
  }), options: queryOptions, inputValue: inputValue, isMulti: true, menuIsOpen: isTypeaheadSearchEnabled &&
425
- 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: {
428
+ inputValue.length >= DEFAULT_TYPEAHEAD_SEARCH_MINIMUM_SEARCH_LENGTH, autoFocus: true, inputRef: inputRef, onChange: changeValue, onInputChange: handleInputChange, onKeyDown: handleKeyDown, onPaste: handlePaste, value: selectedOptions, darkMode: !lightMode, isLoading: isLoading, noMatchMessage: noMatchMessage, placeholder: getPlaceHolder(expectedType), components: {
426
429
  DropdownIndicator: null,
427
- }, inputName: inputName }), _jsx("button", { className: "value-spec-editor__list-editor__copy-button",
430
+ }, inputName: inputName, optionCustomization: selectorConfig?.optionCustomization, disabled: readOnly }), _jsx("button", { className: "value-spec-editor__list-editor__copy-button",
428
431
  // eslint-disable-next-line no-void
429
- 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 EnumCollectionInstanceValueEditor = observer((props) => {
432
- const { valueSpecification, observerContext, saveEdit } = props;
432
+ 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, disabled: readOnly, children: _jsx(SaveIcon, {}) })] }));
433
+ };
434
+ export const PrimitiveCollectionInstanceValueEditor = observer(PrimitiveCollectionInstanceValueEditorInner);
435
+ const EnumCollectionInstanceValueEditorInner = (props) => {
436
+ const { valueSpecification, convertTextToValueSpecification, convertValueSpecificationToText, updateValueSpecification, saveEdit, expectedType, enumOptions, selectorConfig, lightMode, readOnly, } = props;
437
+ guaranteeNonNullable(enumOptions, 'Must pass enum options to EnumCollectionInstanceValueEditor');
433
438
  // local state and variables
434
- const applicationStore = useApplicationStore();
435
- const enumType = guaranteeType(valueSpecification.genericType?.value.rawType, Enumeration);
436
439
  const [inputValue, setInputValue] = useState('');
437
440
  const [inputValueIsError, setInputValueIsError] = useState(false);
438
441
  const [selectedOptions, setSelectedOptions] = useState(valueSpecification.values
439
- .filter((valueSpec) => valueSpec.values[0]?.value !== undefined)
440
- .map((valueSpec) => ({
441
- label: at(valueSpec.values, 0).value.name,
442
- value: at(valueSpec.values, 0).value,
443
- })));
444
- const availableOptions = enumType.values
445
- .filter((value) => !selectedOptions.some((selectedValue) => selectedValue.value.name === value.name))
442
+ .filter((value) => guaranteeNonNullable(value))
443
+ .map(convertValueSpecificationToText)
444
+ .filter(isNonEmptyString)
446
445
  .map((value) => ({
447
- label: value.name,
448
- value: value,
449
- }));
450
- const copyButtonName = `copy-${valueSpecification.hashCode}`;
451
- const inputName = `input-${valueSpecification.hashCode}`;
446
+ label: value,
447
+ value,
448
+ })));
449
+ const availableOptions = enumOptions?.filter((value) => !selectedOptions.some((selectedValue) => selectedValue.value === value.value));
450
+ const copyButtonName = `copy-${valueSpecification.values[0] ? convertValueSpecificationToText(valueSpecification.values[0]) : ''}`;
451
+ const inputName = `input-${valueSpecification.values[0] ? convertValueSpecificationToText(valueSpecification.values[0]) : ''}`;
452
452
  // helper functions
453
453
  const isValueAlreadySelected = (value) => selectedOptions.map((option) => option.value).includes(value);
454
454
  /**
@@ -459,14 +459,12 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
459
459
  */
460
460
  const convertInputValueToEnum = () => {
461
461
  const trimmedInputValue = inputValue.trim();
462
- if (trimmedInputValue.length) {
463
- const newEnum = convertTextToEnum(trimmedInputValue, enumType);
464
- if (newEnum === undefined || isValueAlreadySelected(newEnum)) {
465
- return null;
466
- }
467
- return newEnum;
462
+ if (!trimmedInputValue.length ||
463
+ isValueAlreadySelected(trimmedInputValue) ||
464
+ !enumOptions?.some((option) => option.value === trimmedInputValue)) {
465
+ return null;
468
466
  }
469
- return null;
467
+ return trimmedInputValue;
470
468
  };
471
469
  const addInputValueToSelectedOptions = () => {
472
470
  const newEnum = convertInputValueToEnum();
@@ -474,7 +472,7 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
474
472
  setSelectedOptions([
475
473
  ...selectedOptions,
476
474
  {
477
- label: newEnum.name,
475
+ label: newEnum,
478
476
  value: newEnum,
479
477
  },
480
478
  ]);
@@ -491,7 +489,7 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
491
489
  setInputValue('');
492
490
  }
493
491
  else if (actionChange.action === 'remove-value' &&
494
- actionChange.removedValue.value.name === inputValue) {
492
+ actionChange.removedValue.value === inputValue) {
495
493
  setInputValueIsError(false);
496
494
  }
497
495
  };
@@ -513,25 +511,20 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
513
511
  if (!parsedData) {
514
512
  return;
515
513
  }
516
- const newValues = uniq(uniq(parsedData)
517
- .map((value) => convertTextToEnum(value, enumType))
518
- .filter(isNonNullable)).filter((value) => !isValueAlreadySelected(value));
514
+ const newValues = uniq(uniq(parsedData).filter((value) => enumOptions?.some((option) => option.value === value))).filter((value) => !isValueAlreadySelected(value));
519
515
  setSelectedOptions([
520
516
  ...selectedOptions,
521
- ...newValues.map((value) => ({ label: value.name, value })),
517
+ ...newValues.map((value) => ({ label: value, value })),
522
518
  ]);
523
519
  event.preventDefault();
524
520
  };
525
- const copyValueToClipboard = async () => navigator.clipboard.writeText(selectedOptions.map((option) => option.value.name).join(','));
521
+ const copyValueToClipboard = async () => navigator.clipboard.writeText(selectedOptions.map((option) => option.value).join(','));
526
522
  const updateValueSpecAndSaveEdit = () => {
527
523
  const result = selectedOptions
528
- .map((value) => {
529
- const enumValueInstanceValue = new EnumValueInstanceValue(GenericTypeExplicitReference.create(new GenericType(enumType)));
530
- instanceValue_setValues(enumValueInstanceValue, [EnumValueExplicitReference.create(value.value)], observerContext);
531
- return enumValueInstanceValue;
532
- })
524
+ .map((option) => option.value)
525
+ .map((value) => convertTextToValueSpecification(expectedType, value))
533
526
  .filter(isNonNullable);
534
- instanceValue_setValues(valueSpecification, result, observerContext);
527
+ updateValueSpecification(valueSpecification, result);
535
528
  saveEdit();
536
529
  };
537
530
  const onBlur = (event) => {
@@ -542,15 +535,16 @@ const EnumCollectionInstanceValueEditor = observer((props) => {
542
535
  };
543
536
  return (_jsxs("div", { className: "value-spec-editor", onBlur: onBlur, children: [_jsx(CustomSelectorInput, { className: clsx('value-spec-editor__enum-collection-selector', {
544
537
  '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",
538
+ }), options: availableOptions, inputValue: inputValue, isMulti: true, autoFocus: true, onChange: changeValue, onInputChange: handleInputChange, onKeyDown: handleKeyDown, onPaste: handlePaste, value: selectedOptions, darkMode: !lightMode, placeholder: "Add", menuIsOpen: true, inputName: inputName, optionCustomization: selectorConfig?.optionCustomization, disabled: readOnly }), _jsx("button", { className: "value-spec-editor__list-editor__copy-button",
546
539
  // eslint-disable-next-line no-void
547
- 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
- });
540
+ 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, disabled: readOnly, children: _jsx(SaveIcon, {}) })] }));
541
+ };
542
+ export const EnumCollectionInstanceValueEditor = observer(EnumCollectionInstanceValueEditorInner);
549
543
  const COLLECTION_PREVIEW_CHAR_LIMIT = 50;
550
- const CollectionValueInstanceValueEditor = observer((props) => {
551
- const { valueSpecification, expectedType, className, setValueSpecification, selectorConfig, observerContext, } = props;
544
+ const CollectionValueInstanceValueEditorInner = (props) => {
545
+ const { valueSpecification, convertTextToValueSpecification, convertValueSpecificationToText, updateValueSpecification, stringifyCollectionValueSpecification, errorChecker, className, selectorSearchConfig, selectorConfig, expectedType, enumOptions, lightMode, readOnly, } = props;
552
546
  const [editable, setEditable] = useState(false);
553
- const valueText = stringifyValue(valueSpecification.values);
547
+ const valueText = stringifyCollectionValueSpecification(valueSpecification);
554
548
  const previewText = `List(${valueSpecification.values.length === 0
555
549
  ? 'empty'
556
550
  : valueSpecification.values.length})${valueSpecification.values.length === 0
@@ -562,74 +556,156 @@ const CollectionValueInstanceValueEditor = observer((props) => {
562
556
  const saveEdit = () => {
563
557
  if (editable) {
564
558
  setEditable(false);
565
- setValueSpecification(valueSpecification);
566
559
  }
567
560
  };
568
561
  if (editable) {
569
- return (_jsx(_Fragment, { children: _jsx("div", { className: clsx('value-spec-editor', className), children: expectedType instanceof Enumeration ? (_jsx(EnumCollectionInstanceValueEditor, { valueSpecification: valueSpecification, observerContext: observerContext, saveEdit: saveEdit })) : (_jsx(PrimitiveCollectionInstanceValueEditor, { valueSpecification: valueSpecification, expectedType: expectedType, saveEdit: saveEdit, selectorConfig: selectorConfig, observerContext: observerContext })) }) }));
562
+ 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, lightMode: lightMode, readOnly: readOnly })) : (_jsx(PrimitiveCollectionInstanceValueEditor, { valueSpecification: valueSpecification, updateValueSpecification: updateValueSpecification, convertTextToValueSpecification: convertTextToValueSpecification, convertValueSpecificationToText: convertValueSpecificationToText, expectedType: expectedType, saveEdit: saveEdit, selectorSearchConfig: selectorSearchConfig, selectorConfig: selectorConfig, lightMode: lightMode, readOnly: readOnly })) }) }));
570
563
  }
571
- 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': !isValidInstanceValue(valueSpecification),
564
+ return (_jsxs("div", { className: clsx('value-spec-editor', className), onClick: readOnly ? () => { } : enableEdit, title: readOnly ? '' : 'Click to edit', style: { cursor: readOnly ? 'not-allowed' : '' }, children: [_jsx("div", { className: clsx('value-spec-editor__list-editor__preview', {
565
+ 'value-spec-editor__list-editor__preview--error': errorChecker?.(valueSpecification),
573
566
  }), children: previewText }), _jsx("button", { className: "value-spec-editor__list-editor__edit-icon", children: _jsx(PencilIcon, {}) })] }));
574
- });
567
+ };
568
+ export const CollectionValueInstanceValueEditor = observer(CollectionValueInstanceValueEditorInner);
575
569
  const UnsupportedValueSpecificationEditor = () => (_jsx("div", { className: "value-spec-editor--unsupported", children: "unsupported" }));
576
- const DateInstanceValueEditor = observer((props) => {
577
- const { valueSpecification, setValueSpecification, graph, observerContext, typeCheckOption, resetValue, handleBlur, displayAsEditableValue, } = props;
578
- return (_jsxs("div", { className: "value-spec-editor", children: [_jsx(CustomDatePicker, { valueSpecification: valueSpecification, graph: graph, observerContext: observerContext, typeCheckOption: typeCheckOption, setValueSpecification: setValueSpecification, hasError: valueSpecification instanceof PrimitiveInstanceValue &&
579
- !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
- });
570
+ const DateInstanceValueEditorInner = (props) => {
571
+ const { valueSpecification, valueSelector, updateValueSpecification, resetValue, handleBlur, typeCheckOption, displayAsEditableValue, className, readOnly, } = props;
572
+ return (_jsxs("div", { className: clsx('value-spec-editor', className), children: [_jsx(CustomDatePicker, { valueSpecification: valueSpecification, valueSelector: valueSelector, typeCheckOption: typeCheckOption, updateValueSpecification: updateValueSpecification, hasError: valueSpecification instanceof PrimitiveInstanceValue &&
573
+ !isValidInstanceValue(valueSpecification), handleBlur: handleBlur, displayAsEditableValue: displayAsEditableValue, readOnly: readOnly }), !displayAsEditableValue && (_jsx("button", { className: "value-spec-editor__reset-btn", name: "Reset", title: "Reset", onClick: resetValue, disabled: readOnly, children: _jsx(RefreshIcon, {}) }))] }));
574
+ };
575
+ export const DateInstanceValueEditor = observer(DateInstanceValueEditorInner);
581
576
  /**
582
577
  * TODO we should pass in the props `resetValueSpecification`. Reset
583
578
  * should be part of this editor. Also through here we can call `observe_` accordingly.
584
579
  *
585
580
  * See https://github.com/finos/legend-studio/pull/1021
586
581
  */
587
- export const BasicValueSpecificationEditor = forwardRef(function _BasicValueSpecificationEditor(props, ref) {
588
- const { className, valueSpecification, graph, observerContext, typeCheckOption, setValueSpecification, resetValue, selectorConfig, isConstant, handleBlur, handleKeyDown, displayDateEditorAsEditableValue, } = props;
582
+ export const BasicValueSpecificationEditor = forwardRef(function BasicValueSpecificationEditorInner(props, ref) {
583
+ const { className, valueSpecification, graph, observerContext, typeCheckOption, setValueSpecification, resetValue, selectorSearchConfig, selectorConfig, isConstant, handleBlur, handleKeyDown, displayDateEditorAsEditableValue, readOnly, } = props;
584
+ const applicationStore = useApplicationStore();
585
+ const errorChecker = (_valueSpecification) => !isValidInstanceValue(_valueSpecification);
586
+ const dateValueSelector = (_valueSpecification) => {
587
+ return _valueSpecification instanceof SimpleFunctionExpression
588
+ ? ''
589
+ : _valueSpecification.values[0];
590
+ };
591
+ const dateUpdateValueSpecification = (_valueSpecification, value, options) => {
592
+ if (value instanceof CustomDateOption) {
593
+ setValueSpecification(buildPureAdjustDateFunction(value, graph, observerContext));
594
+ }
595
+ else if (value instanceof CustomFirstDayOfOption) {
596
+ setValueSpecification(buildPureDateFunctionExpression(value, graph, observerContext));
597
+ }
598
+ else if (value instanceof CustomPreviousDayOfWeekOption) {
599
+ setValueSpecification(buildPureDateFunctionExpression(value, graph, observerContext));
600
+ }
601
+ else if (value instanceof DatePickerOption) {
602
+ setValueSpecification(buildPureDateFunctionExpression(value, graph, observerContext));
603
+ }
604
+ else {
605
+ if (_valueSpecification instanceof SimpleFunctionExpression) {
606
+ setValueSpecification(buildPrimitiveInstanceValue(graph, guaranteeNonNullable(options?.primitiveTypeEnum), value, observerContext));
607
+ }
608
+ else if (_valueSpecification instanceof InstanceValue) {
609
+ instanceValue_setValue(_valueSpecification, value, 0, observerContext);
610
+ if (_valueSpecification.genericType.value.rawType.path !==
611
+ guaranteeNonNullable(options?.primitiveTypeEnum)) {
612
+ valueSpecification_setGenericType(_valueSpecification, GenericTypeExplicitReference.create(new GenericType(getPrimitiveTypeInstanceFromEnum(guaranteeNonNullable(options?.primitiveTypeEnum)))));
613
+ }
614
+ setValueSpecification(_valueSpecification);
615
+ }
616
+ else if (options?.primitiveTypeEnum === PRIMITIVE_TYPE.LATESTDATE) {
617
+ setValueSpecification(buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.LATESTDATE, value, observerContext));
618
+ }
619
+ }
620
+ };
589
621
  if (valueSpecification instanceof PrimitiveInstanceValue) {
590
622
  const _type = valueSpecification.genericType.value.rawType;
623
+ // eslint-disable-next-line comma-spacing
624
+ const valueSelector = (val) => val.values[0];
625
+ // eslint-disable-next-line comma-spacing
626
+ const updateValueSpecification = (_valueSpecification, value) => {
627
+ instanceValue_setValue(_valueSpecification, value, 0, observerContext);
628
+ setValueSpecification(_valueSpecification);
629
+ };
591
630
  switch (_type.path) {
592
631
  case PRIMITIVE_TYPE.STRING:
593
- return (_jsx(StringPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification, setValueSpecification: setValueSpecification, className: className, resetValue: resetValue, selectorConfig: selectorConfig, observerContext: observerContext, ref: ref, handleBlur: handleBlur, handleKeyDown: handleKeyDown }));
632
+ 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, lightMode: applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, readOnly: readOnly }));
594
633
  case PRIMITIVE_TYPE.BOOLEAN:
595
- return (_jsx(BooleanPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification, setValueSpecification: setValueSpecification, className: className, resetValue: resetValue, observerContext: observerContext }));
634
+ return (_jsx(BooleanPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification, valueSelector: valueSelector, updateValueSpecification: updateValueSpecification, className: className, resetValue: resetValue, readOnly: readOnly }));
596
635
  case PRIMITIVE_TYPE.NUMBER:
597
636
  case PRIMITIVE_TYPE.FLOAT:
598
637
  case PRIMITIVE_TYPE.DECIMAL:
599
638
  case PRIMITIVE_TYPE.BINARY:
600
639
  case PRIMITIVE_TYPE.BYTE:
601
640
  case PRIMITIVE_TYPE.INTEGER:
602
- return (_jsx(NumberPrimitiveInstanceValueEditor, { valueSpecification: valueSpecification, isInteger: _type.path === PRIMITIVE_TYPE.INTEGER, setValueSpecification: setValueSpecification, className: className, resetValue: resetValue, observerContext: observerContext, ref: ref, handleBlur: handleBlur, handleKeyDown: handleKeyDown }));
641
+ 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, readOnly: readOnly }));
603
642
  case PRIMITIVE_TYPE.DATE:
604
643
  case PRIMITIVE_TYPE.STRICTDATE:
605
644
  case PRIMITIVE_TYPE.DATETIME:
606
645
  case PRIMITIVE_TYPE.LATESTDATE:
607
- return (_jsx(DateInstanceValueEditor, { valueSpecification: valueSpecification, graph: graph, observerContext: observerContext, typeCheckOption: typeCheckOption, className: className, setValueSpecification: setValueSpecification, resetValue: resetValue, handleBlur: handleBlur, displayAsEditableValue: displayDateEditorAsEditableValue }));
646
+ return (_jsx(DateInstanceValueEditor, { valueSpecification: valueSpecification, valueSelector: dateValueSelector, typeCheckOption: typeCheckOption, className: className, updateValueSpecification: dateUpdateValueSpecification, resetValue: resetValue, handleBlur: handleBlur, displayAsEditableValue: displayDateEditorAsEditableValue, errorChecker: (_valueSpecification) => _valueSpecification instanceof PrimitiveInstanceValue &&
647
+ errorChecker(_valueSpecification), readOnly: readOnly }));
608
648
  default:
609
649
  return _jsx(UnsupportedValueSpecificationEditor, {});
610
650
  }
611
651
  }
612
652
  else if (valueSpecification instanceof EnumValueInstanceValue) {
613
- return (_jsx(EnumValueInstanceValueEditor, { valueSpecification: valueSpecification, className: className, resetValue: resetValue, setValueSpecification: setValueSpecification, observerContext: observerContext, handleBlur: handleBlur }));
653
+ const enumType = guaranteeType(valueSpecification.genericType?.value.rawType, Enumeration);
654
+ const options = enumType.values.map((value) => ({
655
+ label: value.name,
656
+ value: value.name,
657
+ }));
658
+ 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) => {
659
+ const enumValue = guaranteeNonNullable(enumType.values.find((val) => val.name === value), `Unable to find enum value ${value} in enumeration ${enumType.name}`);
660
+ instanceValue_setValue(_valueSpecification, EnumValueExplicitReference.create(enumValue), 0, observerContext);
661
+ setValueSpecification(_valueSpecification);
662
+ }, errorChecker: (_valueSpecification) => !isValidInstanceValue(_valueSpecification), handleBlur: handleBlur, selectorConfig: selectorConfig, lightMode: applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, readOnly: readOnly }));
614
663
  }
615
664
  else if (valueSpecification instanceof CollectionInstanceValue &&
616
665
  valueSpecification.genericType) {
666
+ const updateValueSpecification = (collectionValueSpecification, valueSpecifications) => {
667
+ instanceValue_setValues(collectionValueSpecification, valueSpecifications, observerContext);
668
+ setValueSpecification(collectionValueSpecification);
669
+ };
670
+ const convertTextToValueSpecification = (type, text) => {
671
+ if (type instanceof Enumeration) {
672
+ const enumValue = convertTextToEnum(text, type);
673
+ if (enumValue) {
674
+ const enumValueInstanceValue = new EnumValueInstanceValue(GenericTypeExplicitReference.create(new GenericType(type)));
675
+ instanceValue_setValues(enumValueInstanceValue, [EnumValueExplicitReference.create(enumValue)], observerContext);
676
+ return observe_ValueSpecification(enumValueInstanceValue, observerContext);
677
+ }
678
+ }
679
+ else {
680
+ const primitiveVal = convertTextToPrimitiveInstanceValue(guaranteeType(type, Type), text, observerContext);
681
+ if (primitiveVal) {
682
+ return observe_ValueSpecification(primitiveVal, observerContext);
683
+ }
684
+ }
685
+ return null;
686
+ };
687
+ const enumOptions = typeCheckOption.expectedType instanceof Enumeration
688
+ ? typeCheckOption.expectedType.values.map((enumValue) => ({
689
+ label: enumValue.name,
690
+ value: enumValue.name,
691
+ }))
692
+ : undefined;
617
693
  // NOTE: since when we fill in the arguments, `[]` (or `nullish` value in Pure)
618
694
  // is used for parameters we don't handle, we should not attempt to support empty collection
619
695
  // without generic type here as that is equivalent to `[]`
620
- return (_jsx(CollectionValueInstanceValueEditor, { valueSpecification: valueSpecification, graph: graph, expectedType: typeCheckOption.expectedType, className: className, setValueSpecification: setValueSpecification, selectorConfig: selectorConfig, observerContext: observerContext }));
696
+ 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, lightMode: applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, readOnly: readOnly }));
621
697
  }
622
698
  // property expression
623
699
  else if (valueSpecification instanceof VariableExpression) {
624
700
  return (_jsx(VariableExpressionParameterEditor, { valueSpecification: valueSpecification, className: className, resetValue: resetValue, isConstant: Boolean(isConstant) }));
625
701
  }
626
702
  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 }));
703
+ 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, readOnly: readOnly }));
628
704
  }
629
705
  else if (valueSpecification instanceof SimpleFunctionExpression) {
630
706
  if (isSubType(typeCheckOption.expectedType, PrimitiveType.DATE)) {
631
707
  if (isUsedDateFunctionSupportedInFormMode(valueSpecification)) {
632
- return (_jsx(DateInstanceValueEditor, { valueSpecification: valueSpecification, graph: graph, observerContext: observerContext, typeCheckOption: typeCheckOption, className: className, setValueSpecification: setValueSpecification, resetValue: resetValue, handleBlur: handleBlur, displayAsEditableValue: displayDateEditorAsEditableValue }));
708
+ return (_jsx(DateInstanceValueEditor, { valueSpecification: valueSpecification, valueSelector: dateValueSelector, typeCheckOption: typeCheckOption, className: className, updateValueSpecification: dateUpdateValueSpecification, resetValue: resetValue, handleBlur: handleBlur, displayAsEditableValue: displayDateEditorAsEditableValue, readOnly: readOnly }));
633
709
  }
634
710
  else {
635
711
  return _jsx(UnsupportedValueSpecificationEditor, {});
@@ -643,15 +719,18 @@ export const BasicValueSpecificationEditor = forwardRef(function _BasicValueSpec
643
719
  const simplifiedValue = simplifyValueExpression(valueSpecification, observerContext);
644
720
  if (simplifiedValue instanceof PrimitiveInstanceValue &&
645
721
  isSubType(simplifiedValue.genericType.value.rawType, PrimitiveType.NUMBER)) {
646
- return (_jsx(NumberPrimitiveInstanceValueEditor, { valueSpecification: simplifiedValue, isInteger: simplifiedValue.genericType.value.rawType ===
647
- PrimitiveType.INTEGER, setValueSpecification: setValueSpecification, className: className, resetValue: resetValue, observerContext: observerContext, ref: ref, handleBlur: handleBlur, handleKeyDown: handleKeyDown }));
722
+ return (_jsx(NumberPrimitiveInstanceValueEditor, { valueSpecification: simplifiedValue, valueSelector: (val) => val.values[0], isInteger: simplifiedValue.genericType.value.rawType ===
723
+ PrimitiveType.INTEGER, updateValueSpecification: (_valueSpecification, value) => {
724
+ instanceValue_setValue(_valueSpecification, value, 0, observerContext);
725
+ setValueSpecification(_valueSpecification);
726
+ }, className: className, resetValue: resetValue, ref: ref, handleBlur: handleBlur, handleKeyDown: handleKeyDown, readOnly: readOnly }));
648
727
  }
649
728
  }
650
729
  }
651
730
  return _jsx(UnsupportedValueSpecificationEditor, {});
652
731
  });
653
732
  export const EditableBasicValueSpecificationEditor = observer((props) => {
654
- const { valueSpecification, setValueSpecification, graph, observerContext, typeCheckOption, resetValue, selectorConfig, isConstant, initializeAsEditable, } = props;
733
+ const { valueSpecification, setValueSpecification, graph, observerContext, typeCheckOption, resetValue, selectorSearchConfig, selectorConfig, isConstant, initializeAsEditable, readOnly, } = props;
655
734
  const applicationStore = useApplicationStore();
656
735
  const [isEditingValue, setIsEditingValue] = useState(initializeAsEditable ?? false);
657
736
  const inputRef = useRef(null);
@@ -669,15 +748,17 @@ export const EditableBasicValueSpecificationEditor = observer((props) => {
669
748
  const valueSpecStringValue = getValueSpecificationStringValue(valueSpecification, applicationStore, {
670
749
  omitEnumOwnerName: true,
671
750
  });
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) => {
751
+ 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
752
  if (event.key === 'Enter') {
674
753
  setIsEditingValue(false);
675
754
  }
676
- }, displayDateEditorAsEditableValue: true })) : (_jsx("div", { className: "value-spec-editor__editable__display", children: _jsx("span", { className: clsx('value-spec-editor__editable__display--content editable-value', {
755
+ }, displayDateEditorAsEditableValue: true, readOnly: readOnly })) : (_jsx("div", { className: "value-spec-editor__editable__display", children: _jsx("span", { className: clsx('value-spec-editor__editable__display--content editable-value', {
677
756
  'value-spec-editor__editable__display--content--error': valueSpecification instanceof InstanceValue &&
678
757
  !isValidInstanceValue(valueSpecification),
679
- }), onClick: () => {
680
- setIsEditingValue(true);
681
- }, children: `"${valueSpecStringValue !== undefined ? valueSpecStringValue : ''}"` }) }));
758
+ }), onClick: readOnly
759
+ ? () => { }
760
+ : () => {
761
+ setIsEditingValue(true);
762
+ }, style: { cursor: readOnly ? 'not-allowed' : '' }, children: `"${valueSpecStringValue !== undefined ? valueSpecStringValue : ''}"` }) }));
682
763
  });
683
764
  //# sourceMappingURL=BasicValueSpecificationEditor.js.map