@evoke-platform/ui-components 1.0.0-dev.228 → 1.0.0-dev.229
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.js +16 -3
- package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.test.js +1 -2
- package/dist/published/components/custom/FormField/FormField.js +1 -1
- package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.js +10 -8
- package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.test.js +17 -0
- package/package.json +1 -1
@@ -8,8 +8,8 @@ const BooleanSelect = (props) => {
|
|
8
8
|
setValue(defaultValue);
|
9
9
|
}, [defaultValue]);
|
10
10
|
const handleChange = (event, selected) => {
|
11
|
-
setValue(selected.
|
12
|
-
props.onChange(property.id, selected.
|
11
|
+
setValue(selected.value);
|
12
|
+
props.onChange(property.id, selected.value, property);
|
13
13
|
};
|
14
14
|
const booleanOptions = [
|
15
15
|
{
|
@@ -21,6 +21,19 @@ const BooleanSelect = (props) => {
|
|
21
21
|
value: false,
|
22
22
|
},
|
23
23
|
];
|
24
|
-
return readOnly ? (React.createElement(InputFieldComponent, { ...props })) : (React.createElement(Autocomplete, { id: id, renderInput: (params) => (React.createElement(TextField, { ...params,
|
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 ?? {}) }));
|
25
38
|
};
|
26
39
|
export default BooleanSelect;
|
@@ -18,6 +18,5 @@ test('returns selected option', async () => {
|
|
18
18
|
await user.click(inputField);
|
19
19
|
const yesOption = await screen.findByRole('option', { name: 'Yes' });
|
20
20
|
await user.click(yesOption);
|
21
|
-
expect(onChangeMock).toBeCalledWith('theQuestion',
|
22
|
-
booleanProperty);
|
21
|
+
expect(onChangeMock).toBeCalledWith('theQuestion', true, booleanProperty);
|
23
22
|
});
|
@@ -37,7 +37,7 @@ const FormField = (props) => {
|
|
37
37
|
}
|
38
38
|
switch (property.type) {
|
39
39
|
case 'boolean':
|
40
|
-
control =
|
40
|
+
control = React.createElement(BooleanSelect, { ...commonProps, defaultValue: defaultValue });
|
41
41
|
break;
|
42
42
|
case 'date':
|
43
43
|
control = React.createElement(DatePickerSelect, { ...commonProps });
|
package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { isEmpty } from 'lodash';
|
1
2
|
import React, { useEffect, useState } from 'react';
|
2
3
|
import InputMask from 'react-input-mask';
|
3
4
|
import NumberFormat from 'react-number-format';
|
@@ -39,14 +40,15 @@ const InputFieldComponent = (props) => {
|
|
39
40
|
: property.type === 'integer'
|
40
41
|
? { inputProps: { min, max } }
|
41
42
|
: null;
|
42
|
-
|
43
|
-
|
44
|
-
//
|
45
|
-
//
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
return property.enum && !readOnly ? (React.createElement(Autocomplete, { id: id,
|
44
|
+
// note: this is different between widgets and builder
|
45
|
+
// builder had select options being {label, value}
|
46
|
+
// widgets had it like this, as strings w/isOptionEqualToValue
|
47
|
+
options: typeof defaultValue === 'string' &&
|
48
|
+
!isEmpty(defaultValue) &&
|
49
|
+
!property.enum.find((val) => val === defaultValue)
|
50
|
+
? [...property.enum, defaultValue]
|
51
|
+
: property.enum, onChange: handleSelectChange, renderInput: (params) => (React.createElement(TextField, { ...params, value: value, error: error, errorMessage: errorMessage, fullWidth: true, onBlur: onBlur, size: size ?? 'medium', placeholder: placeholder })), disableClearable: true, value: value, isOptionEqualToValue: (option, value) => {
|
50
52
|
return option.value === value;
|
51
53
|
}, error: error, required: required, inputValue: inputValue ?? '', onInputChange: handleInputValueChange, ...(additionalProps ?? {}) })) : !mask ? (React.createElement(TextField, { id: id, sx: {
|
52
54
|
background: 'white',
|
package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.test.js
CHANGED
@@ -40,4 +40,21 @@ describe('Autocomplete', () => {
|
|
40
40
|
await user.click(option2);
|
41
41
|
expect(onChangeMock).toBeCalledWith('enumField', 'option 2', enumProperty);
|
42
42
|
});
|
43
|
+
test('does not include blank default value in options', async () => {
|
44
|
+
const user = userEvent.setup();
|
45
|
+
const onChangeMock = jest.fn((name, value, property) => { });
|
46
|
+
render(React.createElement(InputField, { id: "testInput", property: enumProperty, onChange: onChangeMock, defaultValue: null }));
|
47
|
+
const input = screen.getByRole('combobox');
|
48
|
+
await user.click(input);
|
49
|
+
const blankOption = screen.queryByRole('option', { name: '' });
|
50
|
+
expect(blankOption).not.toBeInTheDocument();
|
51
|
+
});
|
52
|
+
test('includes default value in options', async () => {
|
53
|
+
const user = userEvent.setup();
|
54
|
+
const onChangeMock = jest.fn((name, value, property) => { });
|
55
|
+
render(React.createElement(InputField, { id: "testInput", property: enumProperty, onChange: onChangeMock, defaultValue: 'Default' }));
|
56
|
+
const input = screen.getByRole('combobox');
|
57
|
+
await user.click(input);
|
58
|
+
await screen.findByRole('option', { name: 'Default' });
|
59
|
+
});
|
43
60
|
});
|