@evoke-platform/ui-components 1.5.0-testing.1 → 1.5.0-testing.11

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 (24) hide show
  1. package/dist/published/components/custom/CriteriaBuilder/CriteriaBuilder.js +6 -6
  2. package/dist/published/components/custom/CriteriaBuilder/ValueEditor.d.ts +2 -3
  3. package/dist/published/components/custom/CriteriaBuilder/ValueEditor.js +87 -62
  4. package/dist/published/components/custom/Form/Common/FormComponentWrapper.js +18 -17
  5. package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.d.ts +1 -1
  6. package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.js +7 -10
  7. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/RelatedObjectInstance.js +3 -3
  8. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/DocumentViewerCell.d.ts +13 -0
  9. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/DocumentViewerCell.js +115 -0
  10. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableField.js +25 -26
  11. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableFieldComponent.js +1 -1
  12. package/dist/published/components/custom/Form/utils.js +1 -1
  13. package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.js +24 -21
  14. package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.test.js +50 -8
  15. package/dist/published/components/custom/FormField/FormField.d.ts +4 -1
  16. package/dist/published/components/custom/FormField/FormField.js +5 -2
  17. package/dist/published/components/custom/Menubar/Menubar.d.ts +14 -1
  18. package/dist/published/components/custom/Menubar/Menubar.js +9 -2
  19. package/dist/published/components/custom/Menubar/Menubar.test.js +5 -0
  20. package/dist/published/stories/CriteriaBuilder.stories.js +6 -0
  21. package/dist/published/stories/Form.stories.js +7 -2
  22. package/dist/published/stories/FormField.stories.js +2 -0
  23. package/dist/published/stories/MenuBar.stories.js +13 -18
  24. package/package.json +6 -4
@@ -155,7 +155,7 @@ const customSelector = (props) => {
155
155
  }));
156
156
  }
157
157
  else if (inputType === 'integer' || inputType === 'number') {
158
- opts = options.filter((option) => ['=', '!=', '<', '<=', '>', '>=', 'null', 'notNull'].includes(option.name));
158
+ opts = options.filter((option) => ['=', '!=', '<', '<=', '>', '>=', 'null', 'notNull', 'in', 'notIn'].includes(option.name));
159
159
  // checks if it is a single-select property
160
160
  }
161
161
  else if (inputType === 'string' && isArray(props.fieldData?.values)) {
@@ -164,7 +164,7 @@ const customSelector = (props) => {
164
164
  else if (inputType === 'string') {
165
165
  opts = options.filter((option) => !['>', '<', '<=', '>='].includes(option.name));
166
166
  }
167
- else if (inputType === 'image') {
167
+ else if (inputType === 'image' || inputType === 'boolean') {
168
168
  opts = options.filter((option) => ['=', '!=', 'null', 'notNull'].includes(option.name));
169
169
  }
170
170
  break;
@@ -267,12 +267,12 @@ export const valueEditor = (props) => {
267
267
  const CriteriaBuilder = (props) => {
268
268
  const { properties, criteria, setCriteria, originalCriteria, enablePresetValues, presetValues, operators, disabled, disabledCriteria, hideBorder, presetGroupLabel, customValueEditor, treeViewOpts, disableRegexEscapeChars, } = props;
269
269
  const [propertyTreeMap, setPropertyTreeMap] = useState();
270
- const processRules = (rules, isSavedValue) => {
270
+ const processRules = (rules) => {
271
271
  return rules.map((rule) => {
272
272
  if ('rules' in rule) {
273
273
  return {
274
274
  ...rule,
275
- rules: processRules(rule.rules, isSavedValue),
275
+ rules: processRules(rule.rules),
276
276
  };
277
277
  }
278
278
  else {
@@ -345,7 +345,7 @@ const CriteriaBuilder = (props) => {
345
345
  return updatedQuery
346
346
  ? {
347
347
  ...updatedQuery,
348
- rules: processRules(updatedQuery.rules, true),
348
+ rules: processRules(updatedQuery.rules),
349
349
  }
350
350
  : { combinator: 'and', rules: [] };
351
351
  };
@@ -371,7 +371,7 @@ const CriteriaBuilder = (props) => {
371
371
  const handleQueryChange = (q) => {
372
372
  const processedQuery = {
373
373
  ...q,
374
- rules: processRules(q.rules, false),
374
+ rules: processRules(q.rules),
375
375
  };
376
376
  setQuery(processedQuery);
377
377
  const newCriteria = JSON.parse(formatQuery(processedQuery, {
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
- import { ValueEditorProps as ValueEditorBaseProps } from 'react-querybuilder';
3
- import { AutocompleteOption } from '../../core';
2
+ import { Option, ValueEditorProps as ValueEditorBaseProps } from 'react-querybuilder';
4
3
  export type ValueEditorProps = ValueEditorBaseProps & {
5
- values?: AutocompleteOption[] | any[];
4
+ values?: Option[];
6
5
  };
7
6
  declare const ValueEditor: (props: ValueEditorProps) => React.JSX.Element;
8
7
  export default ValueEditor;
@@ -1,8 +1,8 @@
1
1
  import { Instant, LocalDate, LocalDateTime, LocalTime, ZoneId } from '@js-joda/core';
2
- import { ClearRounded, CodeRounded } from '@mui/icons-material';
3
2
  import { Box, darken, lighten, styled } from '@mui/material';
4
3
  import { TimePicker } from '@mui/x-date-pickers';
5
4
  import React, { useEffect, useRef, useState } from 'react';
5
+ import { ClearRounded, CodeRounded } from '../../../icons';
6
6
  import { InvalidDate } from '../../../util';
7
7
  import { Autocomplete, Chip, DatePicker, DateTimePicker, IconButton, LocalizationProvider, Menu, MenuItem, TextField, Typography, } from '../../core';
8
8
  import { NumericFormat } from '../FormField/InputFieldComponent';
@@ -18,16 +18,22 @@ const GroupHeader = styled('div')(({ theme }) => ({
18
18
  : darken(theme.palette.primary.main, 0.8),
19
19
  }));
20
20
  const GroupItems = styled('ul')({ padding: 0 });
21
+ const isPresetValue = (value) => typeof value === 'string' && value.startsWith('{{{') && value.endsWith('}}}');
21
22
  const ValueEditor = (props) => {
22
23
  const { handleOnChange, value, operator, context, level, rule, fieldData } = props;
23
24
  let inputType = props.inputType;
24
- let values = props.values;
25
+ let values = (props.values ?? [])
26
+ .map((item) => ({
27
+ value: item.name,
28
+ label: item.label,
29
+ }))
30
+ .sort((a, b) => a.label.localeCompare(b.label));
25
31
  const property = context.propertyTreeMap?.[rule.field];
26
32
  // for tree view / related object properties, the properties are stored in the propertyTreeMap upon selection
27
33
  if (!!context.treeViewOpts && !!property) {
28
34
  inputType = property.type;
29
35
  if (property.enum) {
30
- values = property.enum.map((item) => ({ name: item, label: item }));
36
+ values = property.enum.map((item) => ({ value: item, label: item }));
31
37
  }
32
38
  }
33
39
  const [invalidDateTime, setInvalidDateTime] = useState(false);
@@ -37,10 +43,17 @@ const ValueEditor = (props) => {
37
43
  // Manages input value for Autocomplete when using 'in/not in' operators, ensuring correct handling on blur.
38
44
  const [inputValue, setInputValue] = useState('');
39
45
  const disabled = ['null', 'notNull'].includes(operator);
40
- const presetValues = context.presetValues?.filter((val) => !val.type || val.type === inputType) ?? [];
41
- const isPresetValue = (value) => value?.startsWith('{{{') && value?.endsWith('}}}');
42
- const presetDisplayValue = presetValues?.find((option) => option.value.name === value)?.label;
43
- const isPresetValueSelected = presetValues && typeof value === 'string' && isPresetValue(value) && !!presetDisplayValue;
46
+ const presetValues = context.presetValues
47
+ ?.filter((val) => !val.type || val.type === inputType)
48
+ ?.map((val) => {
49
+ return {
50
+ label: val.label,
51
+ value: val.value?.name,
52
+ sublabel: val.value?.sublabel,
53
+ type: val.type,
54
+ };
55
+ })
56
+ ?.sort((a, b) => a.label.localeCompare(b.label)) ?? [];
44
57
  let readOnly = context.disabled;
45
58
  if (!readOnly && context.disabledCriteria) {
46
59
  readOnly =
@@ -54,11 +67,12 @@ const ValueEditor = (props) => {
54
67
  '& .MuiAutocomplete-tag': { backgroundColor: '#edeff1' },
55
68
  },
56
69
  };
70
+ const isMultipleOperator = ['in', 'notIn'].includes(operator);
57
71
  useEffect(() => {
58
- if (!['in', 'notIn'].includes(operator) && Array.isArray(value)) {
72
+ if (!isMultipleOperator && Array.isArray(value)) {
59
73
  handleOnChange('');
60
74
  }
61
- else if (['in', 'notIn'].includes(operator) && !Array.isArray(value)) {
75
+ else if (isMultipleOperator && !Array.isArray(value)) {
62
76
  handleOnChange([]);
63
77
  }
64
78
  }, [operator]);
@@ -75,6 +89,7 @@ const ValueEditor = (props) => {
75
89
  };
76
90
  const clearValue = () => {
77
91
  handleOnChange('');
92
+ setInputValue('');
78
93
  };
79
94
  const setPresetValue = (value) => {
80
95
  handleOnChange(value);
@@ -126,9 +141,6 @@ const ValueEditor = (props) => {
126
141
  }
127
142
  }
128
143
  const getEditor = () => {
129
- if (isPresetValueSelected) {
130
- return;
131
- }
132
144
  if (disabled) {
133
145
  return React.createElement(React.Fragment, null);
134
146
  }
@@ -180,18 +192,36 @@ const ValueEditor = (props) => {
180
192
  React.createElement(TextField, { ...params, disabled: disabled, onClick: onClick, placeholder: "Value", size: "small", inputRef: inputRef, error: invalidDateTime }))), readOnly: readOnly })));
181
193
  }
182
194
  else if (inputType === 'number' || inputType === 'integer') {
183
- const isMultiple = ['in', 'notIn'].includes(operator);
184
- const options = presetValues;
185
- if (isMultiple) {
186
- return (React.createElement(Autocomplete, { freeSolo: true, multiple: true, options: options, getOptionLabel: (option) => typeof option === 'object' && option?.label ? option.label : String(option), value: Array.isArray(value) ? (disabled ? [] : value) : [], disabled: disabled,
187
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
188
- onChange: (event, newValue) => {
189
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
190
- const uniqueSelections = newValue.map((item) => item.value ?? Number(item));
191
- handleOnChange(uniqueSelections.length ? uniqueSelections : '');
192
- },
193
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
194
- isOptionEqualToValue: (option, value) => option === value, renderInput: (params) => (React.createElement(TextField, { label: params.label, ...params, size: "small" })), groupBy: (option) => isPresetValue(option.value?.name) ? context.presetGroupLabel || 'Preset Values' : 'Options', renderGroup: groupRenderGroup, sx: styles.input, readOnly: readOnly }));
195
+ if (isMultipleOperator) {
196
+ const options = presetValues;
197
+ return (React.createElement(Autocomplete, { freeSolo: true, multiple: true, options: options, value: Array.isArray(value)
198
+ ? disabled
199
+ ? []
200
+ : value.map((v) => {
201
+ const found = options.find((o) => o.value === v);
202
+ return found ? found : { label: v, value: v };
203
+ })
204
+ : [], disabled: disabled, onChange: (event, newValue) => {
205
+ const uniqueSelections = newValue
206
+ .map((item) => {
207
+ if (typeof item === 'object' && 'value' in item) {
208
+ return item.value;
209
+ }
210
+ else if (typeof item === 'string') {
211
+ if (isPresetValue(item)) {
212
+ return item;
213
+ }
214
+ else if (item.match(/^(\+|-){0,1}\d*(\.\d+)?$/)) {
215
+ const value = Number(item);
216
+ return Number.isNaN(value) ? '' : value;
217
+ }
218
+ return '';
219
+ }
220
+ return item;
221
+ })
222
+ .filter((item) => item !== '');
223
+ handleOnChange(uniqueSelections.length ? Array.from(new Set(uniqueSelections)) : '');
224
+ }, isOptionEqualToValue: (option, value) => option.value === value.value, renderInput: (params) => (React.createElement(TextField, { label: params.label, ...params, size: "small" })), groupBy: (option) => isPresetValue(option.value) ? context.presetGroupLabel || 'Preset Values' : 'Options', renderGroup: groupRenderGroup, sx: styles.input, readOnly: readOnly }));
195
225
  }
196
226
  else {
197
227
  return (React.createElement(TextField, { inputRef: inputRef, value: ['null', 'notNull'].includes(operator) ? '' : value, disabled: disabled || ['null', 'notNull'].includes(operator), onChange: (e) => {
@@ -206,29 +236,39 @@ const ValueEditor = (props) => {
206
236
  : { type: 'number' }), placeholder: "Value", size: "small", onClick: onClick, sx: styles.input, readOnly: readOnly }));
207
237
  }
208
238
  }
239
+ else if (inputType === 'boolean') {
240
+ const options = [{ label: 'True', value: true }, { label: 'False', value: false }, ...presetValues];
241
+ return (React.createElement(Autocomplete, { options: options, value: options.find((opt) => opt.value === value) ?? value, onChange: (event, newValue) => {
242
+ handleOnChange(newValue ? newValue.value : '');
243
+ }, isOptionEqualToValue: (option, value) => option.value === value.value, renderInput: (params) => (React.createElement(TextField, { inputRef: inputRef, label: params.label, ...params, size: "small" })), groupBy: (option) => isPresetValue(option.value) ? context.presetGroupLabel || 'Preset Values' : 'Options', renderGroup: groupRenderGroup, sortBy: "NONE", sx: styles.input, readOnly: readOnly }));
244
+ }
209
245
  else {
210
- const isMultiple = inputType === 'array' || ['in', 'notIn'].includes(operator);
211
- const options = [
212
- ...(values?.sort((a, b) => a.label.localeCompare(b.label)) ?? []),
213
- ...(presetValues?.sort((a, b) => a.label.localeCompare(b.label)) ?? []),
214
- ];
215
- if (isMultiple || values?.length) {
216
- return (React.createElement(Autocomplete, { freeSolo: inputType !== 'array' && fieldData.valueEditorType !== 'select', multiple: isMultiple, options: options, value: isMultiple ? (Array.isArray(value) ? value : []) : Array.isArray(value) ? '' : value,
217
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
218
- onChange: (event, newValue) => {
246
+ const isMultiple = inputType === 'array' || isMultipleOperator || values?.length;
247
+ if (isMultiple) {
248
+ const options = [...values, ...presetValues];
249
+ return (React.createElement(Autocomplete, { freeSolo: inputType !== 'array' && fieldData.valueEditorType !== 'select', multiple: isMultiple, options: options, value: isMultiple
250
+ ? Array.isArray(value)
251
+ ? value.map((item) => {
252
+ const found = options.find((o) => o.value === item);
253
+ return found ? found : { label: item, value: item };
254
+ })
255
+ : []
256
+ : Array.isArray(value)
257
+ ? ''
258
+ : value, onChange: (event, newValue) => {
219
259
  let value;
220
260
  if (isMultiple) {
221
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
222
- const values = newValue.map((item) => item.name || item.value?.name || item);
261
+ const values = newValue.map((item) => typeof item === 'string' ? item : item.value);
223
262
  value = Array.from(new Set(values));
224
263
  }
225
264
  else {
226
- value = newValue?.name ?? newValue?.value?.name ?? '';
265
+ value =
266
+ typeof newValue === 'string' ? newValue : newValue.value;
227
267
  }
228
268
  handleOnChange(value);
229
269
  }, onBlur: () => {
230
270
  if (inputValue &&
231
- (options.some((option) => option.name === inputValue) || !options.length) &&
271
+ (options.some((option) => option.value === inputValue) || !options.length) &&
232
272
  (operator === 'in' || operator === 'notIn')) {
233
273
  const newValues = Array.isArray(value) ? [...value, inputValue] : [inputValue];
234
274
  handleOnChange(Array.from(new Set(newValues)));
@@ -237,7 +277,7 @@ const ValueEditor = (props) => {
237
277
  }, onKeyDown: (event) => {
238
278
  if (event.key === 'Enter' &&
239
279
  inputValue &&
240
- (options.some((option) => option.name === inputValue) || !options.length) &&
280
+ (options.some((option) => option.value === inputValue) || !options.length) &&
241
281
  (operator === 'in' || operator === 'notIn')) {
242
282
  const newValues = Array.isArray(value) ? [...value, inputValue] : [inputValue];
243
283
  handleOnChange(Array.from(new Set(newValues)));
@@ -245,32 +285,16 @@ const ValueEditor = (props) => {
245
285
  }
246
286
  }, onInputChange: (event, newInputValue) => {
247
287
  setInputValue(newInputValue);
248
- }, inputValue: inputValue, renderInput: (params) => (React.createElement(TextField, { inputRef: inputRef, label: params?.label, ...params, size: "small" })),
249
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
- getOptionLabel: (option) => {
251
- if (typeof option === 'string') {
252
- const found = options.find((o) => option === o.name || option === o.value?.name);
253
- return found?.label || option;
254
- }
255
- return option?.label;
256
- },
257
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
258
- isOptionEqualToValue: (option, value) => {
259
- if (typeof value === 'string') {
260
- return option?.name === value || option?.value?.name === value;
261
- }
262
- else {
263
- return option?.label === value?.label;
264
- }
265
- }, groupBy: (option) => isPresetValue(option.value?.name) ? context.presetGroupLabel || 'Preset Values' : 'Options', renderGroup: groupRenderGroup, sortBy: "NONE", sx: styles.input, readOnly: readOnly }));
288
+ }, inputValue: inputValue, renderInput: (params) => (React.createElement(TextField, { inputRef: inputRef, label: params.label, ...params, size: "small" })), isOptionEqualToValue: (option, value) => option?.value === value.value, groupBy: (option) => isPresetValue(option.value) ? context.presetGroupLabel || 'Preset Values' : 'Options', renderGroup: groupRenderGroup, sortBy: "NONE", sx: styles.input, readOnly: readOnly }));
266
289
  }
267
290
  else {
268
291
  return (React.createElement(TextField, { inputRef: inputRef, value: ['null', 'notNull'].includes(operator) ? '' : value, disabled: ['null', 'notNull'].includes(operator), onChange: (e) => handleOnChange(e.target.value), onClick: onClick, placeholder: "Value", size: "small", sx: styles.input, readOnly: readOnly }));
269
292
  }
270
293
  }
271
294
  };
295
+ const presetDisplayValue = React.useMemo(() => presetValues?.find((option) => option.value === value)?.label || value, [presetValues, value]);
272
296
  return (React.createElement(React.Fragment, null,
273
- isPresetValueSelected ? (React.createElement(Box, { ref: inputRef, sx: {
297
+ isPresetValue(value) ? (React.createElement(Box, { ref: inputRef, sx: {
274
298
  width: '33%',
275
299
  display: 'flex',
276
300
  justifyContent: 'space-between',
@@ -291,10 +315,11 @@ const ValueEditor = (props) => {
291
315
  !readOnly && (React.createElement(IconButton, { onClick: clearValue, sx: { padding: '3px', margin: '3px' } },
292
316
  React.createElement(ClearRounded, { fontSize: "small", sx: { color: 'rgba(0, 0, 0, 0.54)' } }))))) : (getEditor()),
293
317
  !!presetValues?.length && (React.createElement(Menu, { open: openPresetValues, anchorEl: inputRef?.current, PaperProps: { sx: { borderRadius: '8px', width: inputRef?.current?.offsetWidth } }, onClose: onClose }, presetValues &&
294
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
295
- presetValues.map((option) => (React.createElement(MenuItem, { ...props, onClick: () => setPresetValue(option.value.name), sx: { padding: '8px', minHeight: '25px' } },
296
- React.createElement(Box, { padding: 0, margin: 0 },
297
- React.createElement(Typography, { fontSize: '14px', fontWeight: 500, sx: { lineHeight: '20px' } }, option.label),
298
- option.value.sublabel && (React.createElement(Typography, { fontSize: '14px', fontWeight: 500, color: 'rgba(145, 158, 171)', sx: { lineHeight: '20px' } }, option.value.sublabel))))))))));
318
+ presetValues.map((option) => {
319
+ return (React.createElement(MenuItem, { ...props, onClick: () => setPresetValue(option.value), sx: { padding: '8px', minHeight: '25px' } },
320
+ React.createElement(Box, { padding: 0, margin: 0 },
321
+ React.createElement(Typography, { fontSize: '14px', fontWeight: 500, sx: { lineHeight: '20px' } }, option.label),
322
+ !!option.sublabel && (React.createElement(Typography, { fontSize: '14px', fontWeight: 500, color: 'rgba(145, 158, 171)', sx: { lineHeight: '20px' } }, option.sublabel)))));
323
+ })))));
299
324
  };
300
325
  export default ValueEditor;
@@ -67,25 +67,26 @@ export const FormComponentWrapper = (props) => {
67
67
  charCount = maxLength - charCount;
68
68
  return (React.createElement(Box, null,
69
69
  React.createElement(Box, { sx: { padding: '10px 0' } },
70
- React.createElement(Typography, { variant: "body2", color: viewOnly ? 'textSecondary' : 'textPrimary', component: "label", htmlFor: inputId, sx: { ...(displayOption === 'radioButton' && value && { marginRight: '8px' }) } },
71
- label,
72
- validate.required ? (React.createElement(Typography, { component: 'span', sx: { color: 'red', fontSize: '12px' } },
73
- ` *`,
74
- ' ')) : null,
75
- tooltip && (React.createElement(Tooltip, { placement: "right", title: tooltip },
76
- React.createElement(IconButton, null,
77
- React.createElement(Help, { sx: { fontSize: '14px' } }))))),
78
- displayOption === 'radioButton' && onChange && !viewOnly && !readOnly && value && (React.createElement(Tooltip, { title: `Clear` },
79
- React.createElement("span", null,
80
- React.createElement(IconButton, { "aria-label": `Clear`, sx: { padding: '0px' }, onClick: () => {
81
- property && onChange(property.id, '');
82
- } },
83
- React.createElement(HighlightOffOutlined, { sx: clearBtnStyles }))))),
84
- React.createElement(Box, { sx: { ...(displayOption === 'radioButton' && { display: 'flex' }) } },
85
- React.createElement(Typography, { variant: "caption", sx: descriptionStyles }, description)),
70
+ property?.type !== 'boolean' && (React.createElement(React.Fragment, null,
71
+ React.createElement(Typography, { variant: "body2", color: viewOnly ? 'textSecondary' : 'textPrimary', component: "label", htmlFor: inputId, sx: { ...(displayOption === 'radioButton' && value && { marginRight: '8px' }) } },
72
+ label,
73
+ validate.required ? (React.createElement(Typography, { component: 'span', sx: { color: 'red', fontSize: '12px' } },
74
+ ` *`,
75
+ ' ')) : null,
76
+ tooltip && (React.createElement(Tooltip, { placement: "right", title: tooltip },
77
+ React.createElement(IconButton, null,
78
+ React.createElement(Help, { sx: { fontSize: '14px' } }))))),
79
+ displayOption === 'radioButton' && onChange && !viewOnly && !readOnly && value && (React.createElement(Tooltip, { title: `Clear` },
80
+ React.createElement("span", null,
81
+ React.createElement(IconButton, { "aria-label": `Clear`, sx: { padding: '0px' }, onClick: () => {
82
+ property && onChange(property.id, '');
83
+ } },
84
+ React.createElement(HighlightOffOutlined, { sx: clearBtnStyles }))))),
85
+ React.createElement(Box, { sx: { ...(displayOption === 'radioButton' && { display: 'flex' }) } },
86
+ React.createElement(Typography, { variant: "caption", sx: descriptionStyles }, description)))),
86
87
  React.createElement(Box, { sx: { display: 'flex', flexDirection: 'row' } },
87
88
  React.createElement(PrefixSuffix, { prefix: prefix, height: fieldHeight }),
88
- React.createElement(Box, { sx: { width: '100%', paddingTop: '6px' } }, children),
89
+ React.createElement(Box, { sx: { width: '100%', paddingTop: property?.type !== 'boolean' ? '6px' : undefined } }, children),
89
90
  React.createElement(PrefixSuffix, { suffix: suffix, height: fieldHeight }))),
90
91
  React.createElement(Box, { sx: underFieldStyles },
91
92
  React.createElement(Box, { sx: { width: '100%', display: 'flex', justifyContent: 'space-between' } },
@@ -35,7 +35,7 @@ export declare class FormFieldComponent extends ReactComponent {
35
35
  */
36
36
  manageFormErrors(): void;
37
37
  beforeSubmit(): void;
38
- handleComponentChange: (components: any, value: any) => void;
38
+ handleAddressChange: (components: any, value: any) => void;
39
39
  handleChange: (key: string, value: any) => void;
40
40
  attachReact(element: Element): void;
41
41
  }
@@ -61,13 +61,13 @@ export class FormFieldComponent extends ReactComponent {
61
61
  selectOptions,
62
62
  inputMaskPlaceholderChar: component.inputMaskPlaceholderChar || '_',
63
63
  }, options, data);
64
- this.handleComponentChange = (components, value) => {
64
+ this.handleAddressChange = (components, value) => {
65
65
  if (isArray(components)) {
66
66
  if (components.filter((component) => Object.hasOwnProperty.call(component, 'components'))) {
67
67
  components
68
68
  .filter((component) => Object.hasOwnProperty.call(component, 'components'))
69
69
  .forEach((comp) => {
70
- this.handleComponentChange(comp.components, value);
70
+ this.handleAddressChange(comp.components, value);
71
71
  });
72
72
  }
73
73
  components
@@ -93,12 +93,7 @@ export class FormFieldComponent extends ReactComponent {
93
93
  else {
94
94
  selectedValue = value.line1;
95
95
  label = value.line1;
96
- this.handleComponentChange(this.root.components, value);
97
- this.root.components
98
- .filter((component) => Object.prototype.hasOwnProperty.call(component, 'components'))
99
- .forEach((section) => {
100
- this.handleComponentChange(section.components, value);
101
- });
96
+ this.handleAddressChange(this.root.components, value);
102
97
  }
103
98
  }
104
99
  else if (this.component.property.type === 'choices' || this.component.property.type === 'array') {
@@ -152,7 +147,9 @@ export class FormFieldComponent extends ReactComponent {
152
147
  this.on('changed-' + this.component.key, (value) => {
153
148
  this.setValue(value ?? '');
154
149
  this.updateValue(value, { modified: true });
155
- this.attach(this.element);
150
+ if (this.element) {
151
+ this.attach(this.element);
152
+ }
156
153
  });
157
154
  }
158
155
  if (this.component.type === 'Date') {
@@ -465,6 +462,6 @@ export class FormFieldComponent extends ReactComponent {
465
462
  falsePositiveMaskError &&
466
463
  isEmpty(this.errorDetails) &&
467
464
  this.emit('changed-' + this.component.key, e.target.value);
468
- }, ...this.component, id: inputId, defaultValue: this.dataValue, mask: this.component.inputMask, error: this.hasErrors(), size: this.component.fieldHeight ?? 'medium' }))), root);
465
+ }, ...this.component, id: inputId, defaultValue: this.dataValue, mask: this.component.inputMask, error: this.hasErrors(), size: this.component.fieldHeight ?? 'medium', required: this.component.validate?.required }))), root);
469
466
  }
470
467
  }
@@ -41,7 +41,7 @@ export const RelatedObjectInstance = (props) => {
41
41
  handleClose();
42
42
  setErrors([]);
43
43
  };
44
- const createNewInstance = async (submission) => {
44
+ const createNewInstance = async (submission, setSubmitting) => {
45
45
  if (!relatedObject) {
46
46
  // Handle the case where relatedObject is undefined
47
47
  return { isSuccessful: false };
@@ -74,12 +74,12 @@ export const RelatedObjectInstance = (props) => {
74
74
  setSnackbarError({
75
75
  showAlert: true,
76
76
  message: err.response?.data?.error?.details?.[0]?.message ??
77
- err.data?.error?.message ??
77
+ err.response?.data?.error?.message ??
78
78
  `An error occurred. The new instance was not created.`,
79
79
  isError: true,
80
80
  });
81
81
  error = err.response?.data?.error;
82
- onClose();
82
+ setSubmitting && setSubmitting(false);
83
83
  }
84
84
  return { isSuccessful, error };
85
85
  };
@@ -0,0 +1,13 @@
1
+ import { ApiServices, ObjectInstance } from '@evoke-platform/context';
2
+ import React from 'react';
3
+ export type DocumentViewerCellProps = {
4
+ instance: ObjectInstance;
5
+ propertyId: string;
6
+ apiServices: ApiServices;
7
+ setSnackbarError: (error: {
8
+ showAlert: boolean;
9
+ message?: string;
10
+ isError?: boolean;
11
+ }) => void;
12
+ };
13
+ export declare const DocumentViewerCell: (props: DocumentViewerCellProps) => React.JSX.Element;
@@ -0,0 +1,115 @@
1
+ import React, { useState } from 'react';
2
+ import { AutorenewRounded, FileWithExtension, LaunchRounded } from '../../../../../icons';
3
+ import { Button, Menu, MenuItem, Typography } from '../../../../core';
4
+ import { Grid } from '../../../../layout';
5
+ import { getPrefixedUrl } from '../../utils';
6
+ export const DocumentViewerCell = (props) => {
7
+ const { instance, propertyId, apiServices, setSnackbarError } = props;
8
+ const [anchorEl, setAnchorEl] = useState(null);
9
+ const [isLoading, setIsLoading] = useState(false);
10
+ const downloadDocument = async (doc, instance) => {
11
+ setIsLoading(true);
12
+ try {
13
+ const documentResponse = await apiServices.get(getPrefixedUrl(`/objects/${instance.objectId}/instances/${instance.id}/documents/${doc.id}/content`), { responseType: 'blob' });
14
+ const contentType = documentResponse.type;
15
+ const blob = new Blob([documentResponse], { type: contentType });
16
+ const url = URL.createObjectURL(blob);
17
+ // Let the browser handle whether to open the document to view in a new tab or download it.
18
+ window.open(url, '_blank');
19
+ setIsLoading(false);
20
+ URL.revokeObjectURL(url);
21
+ }
22
+ catch (error) {
23
+ const status = error.status;
24
+ let message = 'An error occurred while downloading the document.';
25
+ if (status === 403) {
26
+ message = 'You do not have permission to download this document.';
27
+ }
28
+ else if (status === 404) {
29
+ message = 'Document not found.';
30
+ }
31
+ setIsLoading(false);
32
+ setSnackbarError({
33
+ showAlert: true,
34
+ message,
35
+ isError: true,
36
+ });
37
+ }
38
+ };
39
+ return (React.createElement(React.Fragment, null, instance[propertyId]?.length ? (React.createElement(React.Fragment, null,
40
+ React.createElement(Button, { sx: {
41
+ display: 'flex',
42
+ alignItems: 'center',
43
+ justifyContent: 'flex-start',
44
+ padding: '6px 10px',
45
+ }, color: 'inherit', onClick: async (event) => {
46
+ event.stopPropagation();
47
+ const documents = instance[propertyId];
48
+ if (documents.length === 1) {
49
+ await downloadDocument(documents[0], instance);
50
+ }
51
+ else {
52
+ setAnchorEl(event.currentTarget);
53
+ }
54
+ }, variant: "text", "aria-haspopup": "menu", "aria-controls": `document-menu-${instance.id}-${propertyId}`, "aria-expanded": anchorEl ? 'true' : 'false' },
55
+ isLoading ? (React.createElement(AutorenewRounded, { sx: {
56
+ color: '#637381',
57
+ width: '20px',
58
+ height: '20px',
59
+ } })) : (React.createElement(LaunchRounded, { sx: {
60
+ color: '#637381',
61
+ width: '20px',
62
+ height: '20px',
63
+ } })),
64
+ React.createElement(Typography, { sx: {
65
+ marginLeft: '8px',
66
+ fontWeight: 400,
67
+ fontSize: '14px',
68
+ } }, isLoading ? 'Preparing document...' : 'View Document')),
69
+ React.createElement("section", { role: "region", "aria-label": "Document Menu" },
70
+ React.createElement(Menu, { id: `document-menu-${instance.id}-${propertyId}`, anchorEl: anchorEl, open: Boolean(anchorEl), onClose: () => {
71
+ setAnchorEl(null);
72
+ }, sx: {
73
+ '& .MuiPaper-root': {
74
+ borderRadius: '12px',
75
+ boxShadow: 'rgba(145, 158, 171, 0.2)',
76
+ },
77
+ }, variant: 'menu', slotProps: {
78
+ paper: {
79
+ tabIndex: 0,
80
+ style: {
81
+ maxHeight: 200,
82
+ maxWidth: 300,
83
+ minWidth: 300,
84
+ },
85
+ },
86
+ } }, instance[propertyId].map((document) => (React.createElement(MenuItem, { key: document.id, onClick: async (e) => {
87
+ setAnchorEl(null);
88
+ await downloadDocument(document, instance);
89
+ }, "aria-label": document.name },
90
+ React.createElement(Grid, { item: true, sx: {
91
+ display: 'flex',
92
+ justifyContent: 'center',
93
+ padding: '7px',
94
+ } },
95
+ React.createElement(FileWithExtension, { fontFamily: "Arial", fileExtension: document.name?.split('.')?.pop() ?? '', sx: {
96
+ height: '1rem',
97
+ width: '1rem',
98
+ } })),
99
+ React.createElement(Grid, { item: true, xs: 12, sx: {
100
+ width: '100%',
101
+ overflow: 'hidden',
102
+ textOverflow: 'ellipsis',
103
+ } },
104
+ React.createElement(Typography, { noWrap: true, sx: {
105
+ fontSize: '14px',
106
+ fontWeight: 700,
107
+ color: '#212B36',
108
+ lineHeight: '15px',
109
+ width: '100%',
110
+ } }, document.name))))))))) : (React.createElement(Typography, { sx: {
111
+ fontStyle: 'italic',
112
+ marginLeft: '12px',
113
+ fontSize: '14px',
114
+ } }, "No documents"))));
115
+ };
@@ -9,6 +9,7 @@ import { Button, IconButton, Skeleton, Snackbar, Table, TableBody, TableCell, Ta
9
9
  import { Box } from '../../../../layout';
10
10
  import { getPrefixedUrl, normalizeDateTime } from '../../utils';
11
11
  import { ActionDialog } from './ActionDialog';
12
+ import { DocumentViewerCell } from './DocumentViewerCell';
12
13
  const styles = {
13
14
  addButton: {
14
15
  backgroundColor: 'rgba(0, 117, 167, 0.08)',
@@ -250,13 +251,13 @@ const RepeatableField = (props) => {
250
251
  isSuccessful = true;
251
252
  }
252
253
  catch (err) {
254
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
255
+ error = err.response?.data?.error;
253
256
  setSnackbarError({
254
257
  showAlert: true,
255
- message: `An error occurred while creating an instance`,
258
+ message: error?.message ?? `An error occurred while creating an instance`,
256
259
  isError: true,
257
260
  });
258
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
259
- error = err.response?.data?.error;
260
261
  setSubmitting && setSubmitting(false);
261
262
  }
262
263
  }
@@ -284,13 +285,15 @@ const RepeatableField = (props) => {
284
285
  isSuccessful = true;
285
286
  }
286
287
  catch (err) {
288
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
289
+ error = err.response?.data?.error;
287
290
  setSnackbarError({
288
291
  showAlert: true,
289
- message: `An error occurred while ${actionType === 'delete' ? ' deleting' : ' updating'} an instance`,
292
+ message: error?.message ??
293
+ `An error occurred while ${actionType === 'delete' ? ' deleting' : ' updating'} an instance`,
290
294
  isError: true,
291
295
  });
292
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
293
- error = err.response?.data?.error;
296
+ setSubmitting && setSubmitting(false);
294
297
  }
295
298
  }
296
299
  return { isSuccessful, error };
@@ -334,9 +337,9 @@ const RepeatableField = (props) => {
334
337
  };
335
338
  const getValue = (relatedInstance, propertyId, propertyType) => {
336
339
  const value = get(relatedInstance, propertyId);
337
- // If the property is not date-like or document then just return the
340
+ // If the property is not date-like then just return the
338
341
  // value found at the given path.
339
- if (!['date', 'date-time', 'time', 'document'].includes(propertyType)) {
342
+ if (!['date', 'date-time', 'time'].includes(propertyType)) {
340
343
  return value;
341
344
  }
342
345
  // If the date-like value is empty then there is no need to format.
@@ -356,9 +359,6 @@ const RepeatableField = (props) => {
356
359
  if (propertyType === 'time') {
357
360
  return DateTime.fromISO(stringValue).toLocaleString(DateTime.TIME_SIMPLE);
358
361
  }
359
- if (property.type === 'document') {
360
- return Array.isArray(value) ? value.map((v) => v.name).join(', ') : value;
361
- }
362
362
  };
363
363
  const columns = retrieveViewLayout();
364
364
  return loading ? (React.createElement(React.Fragment, null,
@@ -376,23 +376,22 @@ const RepeatableField = (props) => {
376
376
  React.createElement(TableHead, { sx: { backgroundColor: '#F4F6F8' } },
377
377
  React.createElement(TableRow, null,
378
378
  columns?.map((prop) => React.createElement(TableCell, { sx: styles.tableCell }, prop.name)),
379
- React.createElement(TableCell, { sx: { ...styles.tableCell, width: '80px' } }))),
379
+ canUpdateProperty && React.createElement(TableCell, { sx: { ...styles.tableCell, width: '80px' } }))),
380
380
  React.createElement(TableBody, null, relatedInstances?.map((relatedInstance, index) => (React.createElement(TableRow, { key: relatedInstance.id },
381
381
  columns?.map((prop) => {
382
- return (React.createElement(TableCell, { sx: { color: '#212B36', fontSize: '16px' } },
383
- React.createElement(Typography, { key: prop.id, sx: prop.id === 'name'
384
- ? {
385
- '&:hover': {
386
- textDecoration: 'underline',
387
- cursor: 'pointer',
388
- },
389
- }
390
- : {}, onClick: canUpdateProperty && prop.id === 'name'
391
- ? () => editRow(relatedInstance.id)
392
- : undefined },
393
- getValue(relatedInstance, prop.id, prop.type),
394
- prop.type === 'user' &&
395
- users?.find((user) => get(relatedInstance, `${prop.id.split('.')[0]}.id`) === user.id)?.status === 'Inactive' && React.createElement("span", null, ' (Inactive)'))));
382
+ return (React.createElement(TableCell, { sx: { color: '#212B36', fontSize: '16px' } }, prop.type === 'document' ? (React.createElement(DocumentViewerCell, { instance: relatedInstance, propertyId: prop.id, apiServices: apiServices, setSnackbarError: setSnackbarError })) : (React.createElement(Typography, { key: prop.id, sx: prop.id === 'name'
383
+ ? {
384
+ '&:hover': {
385
+ textDecoration: 'underline',
386
+ cursor: 'pointer',
387
+ },
388
+ }
389
+ : {}, onClick: canUpdateProperty && prop.id === 'name'
390
+ ? () => editRow(relatedInstance.id)
391
+ : undefined },
392
+ getValue(relatedInstance, prop.id, prop.type),
393
+ prop.type === 'user' &&
394
+ users?.find((user) => get(relatedInstance, `${prop.id.split('.')[0]}.id`) === user.id)?.status === 'Inactive' && (React.createElement("span", null, ' (Inactive)'))))));
396
395
  }),
397
396
  canUpdateProperty && (React.createElement(TableCell, { sx: { width: '80px' } },
398
397
  React.createElement(IconButton, { "aria-label": `edit-collection-instance-${index}`, onClick: () => editRow(relatedInstance.id) },
@@ -59,7 +59,7 @@ export class RepeatableFieldComponent extends ReactComponent {
59
59
  }
60
60
  }
61
61
  this.updatedCriteria = updateCriteriaInputs(this.criteria ?? {}, data, this.component.user);
62
- this.attachReact(this.element);
62
+ this.attach(this.element);
63
63
  });
64
64
  }
65
65
  }
@@ -127,7 +127,7 @@ export function convertFormToComponents(entries, parameters, object) {
127
127
  conditional: convertVisibilityToConditional(entry.visibility),
128
128
  };
129
129
  }
130
- else {
130
+ else if (entry.type === 'input') {
131
131
  const displayOptions = entry.display;
132
132
  const parameter = parameters.find((parameter) => parameter.id === entry.parameterId);
133
133
  if (!parameter) {
@@ -1,39 +1,42 @@
1
+ import parse from 'html-react-parser';
1
2
  import React, { useEffect, useState } from 'react';
2
- import { Autocomplete, TextField } from '../../../core';
3
+ import { Help } from '../../../../icons';
4
+ import { Autocomplete, Checkbox, FormControl, FormControlLabel, FormHelperText, IconButton, Switch, TextField, Tooltip, Typography, } from '../../../core';
3
5
  import InputFieldComponent from '../InputFieldComponent/InputFieldComponent';
6
+ const descriptionStyles = {
7
+ color: '#999 !important',
8
+ whiteSpace: 'normal',
9
+ paddingBottom: '4px',
10
+ marginX: 0,
11
+ };
4
12
  const BooleanSelect = (props) => {
5
- const { id, property, defaultValue, error, errorMessage, readOnly, size, placeholder, onBlur, additionalProps } = props;
13
+ const { id, property, defaultValue, error, errorMessage, readOnly, size, displayOption, label, required, tooltip, description, placeholder, onBlur, additionalProps, } = props;
6
14
  const [value, setValue] = useState(defaultValue);
7
15
  useEffect(() => {
8
16
  setValue(defaultValue);
9
17
  }, [defaultValue]);
10
- const handleChange = (event, selected) => {
11
- setValue(selected.value);
12
- props.onChange(property.id, selected.value, property);
18
+ const handleChange = (value) => {
19
+ setValue(value);
20
+ props.onChange(property.id, value, property);
13
21
  };
14
22
  const booleanOptions = [
15
23
  {
16
- label: 'Yes',
24
+ label: 'True',
17
25
  value: true,
18
26
  },
19
27
  {
20
- label: 'No',
28
+ label: 'False',
21
29
  value: false,
22
30
  },
23
31
  ];
24
- return readOnly ? (React.createElement(InputFieldComponent, { ...props })) : (React.createElement(Autocomplete, { id: id, renderInput: (params) => (React.createElement(TextField, { ...params, error: error, errorMessage: errorMessage, onBlur: onBlur, fullWidth: true, sx: { background: 'white' }, size: size ?? 'medium', placeholder: placeholder })), value: value, onChange: handleChange, isOptionEqualToValue: (option, val) => {
25
- if (typeof val === 'boolean') {
26
- return option.value === val;
27
- }
28
- return option.value === val?.value;
29
- }, getOptionLabel: (option) => {
30
- if (typeof option === 'boolean') {
31
- const opt = booleanOptions.find((o) => o.value === option);
32
- return opt ? opt.label : option;
33
- }
34
- if (typeof option === 'string')
35
- return option;
36
- return option.label;
37
- }, options: booleanOptions, disableClearable: true, sx: { background: 'white', borderRadius: '8px' }, ...(additionalProps ?? {}) }));
32
+ return displayOption === 'dropdown' ? (readOnly ? (React.createElement(InputFieldComponent, { ...props })) : (React.createElement(Autocomplete, { renderInput: (params) => (React.createElement(TextField, { ...params, error: error, errorMessage: errorMessage, onBlur: onBlur, fullWidth: true, sx: { background: 'white' }, placeholder: placeholder, size: size ?? 'medium' })), value: booleanOptions.find((opt) => opt.value === value) ?? '', onChange: (e, selectedValue) => handleChange(selectedValue.value), isOptionEqualToValue: (option, val) => option?.value === val?.value, options: booleanOptions, disableClearable: true, sx: { background: 'white', borderRadius: '8px' }, ...(additionalProps ?? {}), sortBy: "NONE" }))) : (React.createElement(FormControl, { error: error, fullWidth: true },
33
+ React.createElement(FormControlLabel, { labelPlacement: "end", label: React.createElement(Typography, { variant: "body2", sx: { wordWrap: 'break-word', fontFamily: 'Public Sans' } },
34
+ label,
35
+ tooltip && (React.createElement(Tooltip, { placement: "right", title: tooltip },
36
+ React.createElement(IconButton, null,
37
+ React.createElement(Help, { sx: { fontSize: '14px' } })))),
38
+ required && (React.createElement(Typography, { variant: "body2", component: "span", color: "error", sx: { marginLeft: '4px', fontSize: '18px' } }, "*"))), control: displayOption === 'switch' ? (React.createElement(Switch, { id: id, "aria-checked": value, "aria-required": required, "aria-invalid": error, size: size ?? 'medium', name: property.id, checked: value, onChange: (e) => handleChange(e.target.checked), disabled: readOnly, sx: { alignSelf: 'start' } })) : (React.createElement(Checkbox, { id: id, "aria-checked": value, "aria-required": required, "aria-invalid": error, size: size ?? 'medium', checked: value, name: property.id, onChange: (e) => handleChange(e.target.checked), disabled: readOnly, sx: { alignSelf: 'start', padding: '4px 9px 9px 9px' } })) }),
39
+ error && React.createElement(FormHelperText, { sx: { marginX: 0 } }, errorMessage),
40
+ description && (React.createElement(FormHelperText, { sx: descriptionStyles, component: Typography }, parse(description)))));
38
41
  };
39
42
  export default BooleanSelect;
@@ -10,13 +10,55 @@ const booleanProperty = {
10
10
  name: 'Question',
11
11
  type: 'boolean',
12
12
  };
13
- it('returns selected option', async () => {
13
+ describe('BooleanSelect', () => {
14
14
  const user = userEvent.setup();
15
- const onChangeMock = vi.fn((name, value, property) => { });
16
- render(React.createElement(BooleanSelect, { id: "chooseYesOrNo", property: booleanProperty, onChange: onChangeMock }));
17
- const inputField = screen.getByRole('combobox');
18
- await user.click(inputField);
19
- const yesOption = await screen.findByRole('option', { name: 'Yes' });
20
- await user.click(yesOption);
21
- expect(onChangeMock).toBeCalledWith('theQuestion', true, booleanProperty);
15
+ it('returns selected option', async () => {
16
+ const user = userEvent.setup();
17
+ const onChangeMock = vi.fn((name, value, property) => { });
18
+ render(React.createElement(BooleanSelect, { id: "chooseTrueOrFalse", property: booleanProperty, onChange: onChangeMock, displayOption: "dropdown" }));
19
+ const inputField = screen.getByRole('combobox');
20
+ await user.click(inputField);
21
+ const trueOption = await screen.findByRole('option', { name: 'True' });
22
+ await user.click(trueOption);
23
+ expect(onChangeMock).toBeCalledWith('theQuestion', true, booleanProperty);
24
+ });
25
+ it('renders checkbox', () => {
26
+ const onChangeMock = vi.fn((name, value, property) => { });
27
+ render(React.createElement(BooleanSelect, { id: "checkbox", property: booleanProperty, onChange: onChangeMock, label: 'Field label', displayOption: "checkbox" }));
28
+ const checkbox = screen.queryByRole('checkbox', { name: /Field label/i });
29
+ expect(checkbox).to.be.not.null;
30
+ });
31
+ it('renders switch', () => {
32
+ const onChangeMock = vi.fn((name, value, property) => { });
33
+ render(React.createElement(BooleanSelect, { id: "switch", property: booleanProperty, onChange: onChangeMock, label: 'Field label', displayOption: "switch" }));
34
+ const switchComp = screen.queryByRole('checkbox', { name: /Field label/i });
35
+ expect(switchComp).to.be.not.null;
36
+ });
37
+ it('renders label', () => {
38
+ const onChangeMock = vi.fn((name, value, property) => { });
39
+ render(React.createElement(BooleanSelect, { id: "checkbox", property: booleanProperty, onChange: onChangeMock, label: 'Field label', displayOption: "checkbox" }));
40
+ const label = screen.queryByText(/Field label/i);
41
+ expect(label).to.be.not.null;
42
+ });
43
+ it('allows defaulting', () => {
44
+ const onChangeMock = vi.fn((name, value, property) => { });
45
+ render(React.createElement(BooleanSelect, { id: "checkbox", defaultValue: true, property: booleanProperty, onChange: onChangeMock, label: 'Field label', displayOption: "checkbox" }));
46
+ const checkbox = screen.getByRole('checkbox', { name: /Field label/i });
47
+ expect(checkbox.checked).to.be.true;
48
+ });
49
+ it('sets checkbox', async () => {
50
+ const onChangeMock = vi.fn((name, value, property) => { });
51
+ render(React.createElement(BooleanSelect, { id: "checkbox", property: booleanProperty, onChange: onChangeMock, label: 'Field label', displayOption: "checkbox" }));
52
+ const checkbox = screen.getByRole('checkbox', { name: /Field label/i });
53
+ await user.click(checkbox);
54
+ expect(checkbox.checked).to.be.true;
55
+ expect(onChangeMock).toBeCalledWith('theQuestion', true, booleanProperty);
56
+ });
57
+ it('unsets checkbox', async () => {
58
+ const onChangeMock = vi.fn((name, value, property) => { });
59
+ render(React.createElement(BooleanSelect, { id: "checkbox", defaultValue: true, property: booleanProperty, onChange: onChangeMock, label: 'Field label', displayOption: "checkbox" }));
60
+ const checkbox = screen.getByRole('checkbox', { name: /Field label/i });
61
+ await user.click(checkbox);
62
+ expect(checkbox.checked).to.be.false;
63
+ });
22
64
  });
@@ -29,8 +29,11 @@ export type FormFieldProps = {
29
29
  getOptionLabel?: (option: AutocompleteOption) => string;
30
30
  disableCloseOnSelect?: boolean;
31
31
  additionalProps?: Record<string, unknown>;
32
- displayOption?: 'dropdown' | 'radioButton';
32
+ displayOption?: 'dropdown' | 'radioButton' | 'switch' | 'checkbox';
33
33
  sortBy?: 'ASC' | 'DESC' | 'NONE';
34
+ label?: string;
35
+ description?: string;
36
+ tooltip?: string;
34
37
  };
35
38
  declare const FormField: (props: FormFieldProps) => React.JSX.Element;
36
39
  export default FormField;
@@ -8,7 +8,7 @@ import InputFieldComponent from './InputFieldComponent/InputFieldComponent';
8
8
  import Select from './Select/Select';
9
9
  import TimePickerSelect from './TimePickerSelect/TimePickerSelect';
10
10
  const FormField = (props) => {
11
- const { id, defaultValue, error, onChange, property, readOnly, selectOptions, required, size, placeholder, errorMessage, onBlur, mask, max, min, isMultiLineText, rows, inputMaskPlaceholderChar, queryAddresses, isOptionEqualToValue, renderOption, disableCloseOnSelect, getOptionLabel, additionalProps, displayOption, sortBy, } = props;
11
+ const { id, defaultValue, error, onChange, property, readOnly, selectOptions, required, size, placeholder, errorMessage, onBlur, mask, max, min, isMultiLineText, rows, inputMaskPlaceholderChar, queryAddresses, isOptionEqualToValue, renderOption, disableCloseOnSelect, getOptionLabel, additionalProps, displayOption, sortBy, label, description, tooltip, } = props;
12
12
  let control;
13
13
  const commonProps = {
14
14
  id: id ?? property.id,
@@ -32,6 +32,9 @@ const FormField = (props) => {
32
32
  additionalProps,
33
33
  displayOption,
34
34
  sortBy,
35
+ label,
36
+ description,
37
+ tooltip,
35
38
  };
36
39
  if (queryAddresses) {
37
40
  control = (React.createElement(AddressFieldComponent, { ...commonProps, mask: mask, inputMaskPlaceholderChar: inputMaskPlaceholderChar, isMultiLineText: isMultiLineText, rows: rows, queryAddresses: queryAddresses }));
@@ -39,7 +42,7 @@ const FormField = (props) => {
39
42
  }
40
43
  switch (property.type) {
41
44
  case 'boolean':
42
- control = React.createElement(BooleanSelect, { ...commonProps, defaultValue: defaultValue });
45
+ control = React.createElement(BooleanSelect, { ...commonProps });
43
46
  break;
44
47
  case 'date':
45
48
  control = React.createElement(DatePickerSelect, { ...commonProps });
@@ -1,9 +1,22 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  export type MenuBarProps = {
3
- showNotifications: boolean;
3
+ /** The URL of the logo image to display. */
4
4
  logo: string;
5
+ /** Alternative text for the logo image. */
5
6
  logoAltText?: string;
7
+ /** Navigation items to display on the right side of the menu bar. */
6
8
  navItems?: ReactNode;
9
+ /** The name of the environment to display instead of the logo. */
7
10
  envName?: string;
11
+ /** Navigation item to display before the logo. */
12
+ navBeforeLogo?: ReactNode;
13
+ /** Indicates whether to show notifications. Currently not supported. */
14
+ showNotifications?: boolean;
8
15
  };
16
+ /**
17
+ * Renders a customizable menu bar with navigation items, logo, etc.
18
+ *
19
+ * @param {MenuBarProps} props - Configuration props for the MenuBar component.
20
+ * @returns {JSX.Element} A menu bar component.
21
+ */
9
22
  export default function MenuBar(props: MenuBarProps): React.JSX.Element;
@@ -1,6 +1,12 @@
1
1
  import { AppBar, Box, CardMedia, Toolbar, Typography } from '@mui/material';
2
2
  import React from 'react';
3
3
  import UIThemeProvider, { useResponsive } from '../../../theme';
4
+ /**
5
+ * Renders a customizable menu bar with navigation items, logo, etc.
6
+ *
7
+ * @param {MenuBarProps} props - Configuration props for the MenuBar component.
8
+ * @returns {JSX.Element} A menu bar component.
9
+ */
4
10
  export default function MenuBar(props) {
5
11
  const { isXs: isMobileView } = useResponsive();
6
12
  const classes = {
@@ -9,7 +15,7 @@ export default function MenuBar(props) {
9
15
  flexGrow: 1,
10
16
  },
11
17
  logo: {
12
- paddingRight: '16px',
18
+ padding: '0 16px',
13
19
  height: '70px',
14
20
  maxWidth: isMobileView ? '220px' : null,
15
21
  objectFit: 'contain',
@@ -18,7 +24,8 @@ export default function MenuBar(props) {
18
24
  };
19
25
  return (React.createElement(UIThemeProvider, null,
20
26
  React.createElement(AppBar, { color: "inherit", position: "fixed", elevation: 0, sx: { zIndex: (theme) => theme.zIndex.drawer + 1, borderBottom: '1px solid #919EAB3D' } },
21
- React.createElement(Toolbar, { sx: { justifyContent: 'space-between' } },
27
+ React.createElement(Toolbar, { disableGutters: true, sx: { justifyContent: 'space-between', overflow: 'hidden', paddingRight: '14px' } },
28
+ props.navBeforeLogo && (React.createElement(Box, { sx: { height: '70px', borderRight: '1px solid #919EAB3D' } }, props.navBeforeLogo)),
22
29
  React.createElement(Box, { sx: classes.title }, !props.envName ? (React.createElement(CardMedia, { component: 'img', src: props.logo, alt: props.logoAltText, sx: classes.logo })) : (React.createElement(Box, { mt: 2 },
23
30
  React.createElement(Typography, { variant: "h5" },
24
31
  props?.envName,
@@ -11,3 +11,8 @@ it('render Menubar component without crashing', () => {
11
11
  render(React.createElement(Menubar, { showNotifications: true, navItems: navItems, logo: "" }));
12
12
  expect(screen.getAllByRole('link')).toHaveLength(3);
13
13
  });
14
+ it('renders navBeforeLogo correctly', () => {
15
+ const navBeforeLogo = React.createElement(Link, { href: "#" }, "Before");
16
+ render(React.createElement(Menubar, { showNotifications: true, navItems: null, navBeforeLogo: navBeforeLogo, logo: "" }));
17
+ expect(screen.getAllByRole('link')).toHaveLength(1);
18
+ });
@@ -95,6 +95,12 @@ const defaultProperties = [
95
95
  type: 'integer',
96
96
  required: false,
97
97
  },
98
+ {
99
+ id: 'canApply',
100
+ name: 'Can Apply',
101
+ type: 'boolean',
102
+ required: true,
103
+ },
98
104
  ];
99
105
  const CriteriaBuilderTemplate = (args) => {
100
106
  const [criteria, setCriteria] = React.useState(args.criteria);
@@ -24,6 +24,11 @@ const object = {
24
24
  name: 'Integer',
25
25
  type: 'integer',
26
26
  },
27
+ {
28
+ id: 'boolean',
29
+ name: 'Boolean',
30
+ type: 'boolean',
31
+ },
27
32
  ],
28
33
  actions: [
29
34
  {
@@ -55,7 +60,7 @@ FormWithButtons.args = {
55
60
  actionId: '_update',
56
61
  actionType: 'update',
57
62
  object: object,
58
- instance: { id: 'id', objectId: 'test', name: 'test', integer: 12, decimal: 12.5 },
63
+ instance: { id: 'id', objectId: 'test', name: 'test', integer: 12, decimal: 12.5, boolean: true },
59
64
  };
60
65
  const FormWithNoButtonsTemplate = (args) => {
61
66
  return (React.createElement("div", null,
@@ -76,7 +81,7 @@ FormWithNoButtons.args = {
76
81
  actionId: '_update',
77
82
  actionType: 'update',
78
83
  object: object,
79
- instance: { id: 'id', objectId: 'test', name: 'test', integer: 12, decimal: 12.5 },
84
+ instance: { id: 'id', objectId: 'test', name: 'test', integer: 12, decimal: 12.5, boolean: true },
80
85
  hideButtons: true,
81
86
  formRef: { current: {} },
82
87
  };
@@ -132,6 +132,8 @@ BooleanField.args = {
132
132
  required: true,
133
133
  readOnly: false,
134
134
  size: 'small',
135
+ displayOption: 'checkbox',
136
+ label: "<a href='#'>Label</a>",
135
137
  };
136
138
  export const FileUploadField = FormFieldTemplate.bind({});
137
139
  FileUploadField.args = {
@@ -1,25 +1,20 @@
1
- import { Link } from '@mui/material';
2
1
  import React from 'react';
3
2
  import { MenuBar as CustomMenuBar } from '../index';
4
3
  // eslint-disable-next-line @typescript-eslint/no-var-requires
5
4
  const logo = require('../assets/SA_logo.jpeg');
6
5
  export default {
7
- title: 'Data Display/MenuBar',
6
+ title: 'Custom/MenuBar',
8
7
  component: CustomMenuBar,
9
- argTypes: {
10
- navItems: {
11
- control: 'object',
12
- defaultValue: React.createElement(Link, null, "Object"),
13
- },
14
- showNotifications: {
15
- defaultValue: true,
16
- type: 'boolean',
17
- },
18
- logo: {
19
- defaultValue: logo,
20
- },
21
- envName: { defaultValue: 'System Automation' },
22
- },
23
8
  };
24
- const Template = (props) => React.createElement(CustomMenuBar, { ...props });
25
- export const MenuBar = Template.bind({});
9
+ const MenuBarTemplate = (args) => React.createElement(CustomMenuBar, { ...args });
10
+ export const MenuBar = MenuBarTemplate.bind({});
11
+ MenuBar.args = {
12
+ logo: logo,
13
+ logoAltText: 'System Automation',
14
+ navItems: (React.createElement(React.Fragment, null,
15
+ React.createElement("a", { href: "#" }, "Object1"),
16
+ React.createElement("a", { href: "#" }, "Object2"),
17
+ React.createElement("a", { href: "#" }, "Object3"))),
18
+ envName: 'System Automation',
19
+ showNotifications: true,
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.5.0-testing.1",
3
+ "version": "1.5.0-testing.11",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",
@@ -31,7 +31,8 @@
31
31
  "eslint": "eslint src",
32
32
  "eslint:fix": "npm run eslint -- --fix",
33
33
  "release": "commit-and-tag-version --releaseCommitMessageFormat \"chore(release): {{currentTag}} [skip ci]\"",
34
- "prepare": "husky install"
34
+ "prepare": "husky install",
35
+ "yalc:publish": "npm run build && yalc push --replace --sig"
35
36
  },
36
37
  "author": "",
37
38
  "license": "MIT",
@@ -81,10 +82,11 @@
81
82
  "rimraf": "^3.0.2",
82
83
  "typescript": "^4.7.3",
83
84
  "vitest": "^1.5.3",
84
- "webpack": "^5.74.0"
85
+ "webpack": "^5.74.0",
86
+ "yalc": "^1.0.0-pre.53"
85
87
  },
86
88
  "peerDependencies": {
87
- "@evoke-platform/context": "^1.1.0-testing.5",
89
+ "@evoke-platform/context": "^1.2.0-0",
88
90
  "react": "^18.1.0",
89
91
  "react-dom": "^18.1.0"
90
92
  },