@antscorp/antsomi-ui 1.3.6-beta.1 → 1.3.6-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -32,23 +32,23 @@ const InputSelectAttribute = (props) => {
|
|
|
32
32
|
}
|
|
33
33
|
return upperFirst(translate(translations._ITEM_NAME_ATTRIBUTE, 'attribute'));
|
|
34
34
|
}, [sourceValue]);
|
|
35
|
-
const
|
|
35
|
+
const mapCodeBySource = useMemo(() => {
|
|
36
36
|
if (typeof value === 'string')
|
|
37
37
|
return {};
|
|
38
|
-
return keyBy(get(mapCodeOptions, value?.
|
|
38
|
+
return keyBy(get(mapCodeOptions, value?.source, []), 'value');
|
|
39
39
|
}, [mapCodeOptions, value]);
|
|
40
|
-
const
|
|
40
|
+
const getCodeDefaultBySource = useCallback((source) => get(mapCodeOptions, [source, '0', 'value'], ''), [mapCodeOptions]);
|
|
41
41
|
const onOpenModal = useCallback(() => {
|
|
42
42
|
if (value && typeof value !== 'string') {
|
|
43
43
|
form.setFieldsValue({ source: value?.source, code: value?.code });
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
const source = sourceOptions[0]?.value || '';
|
|
47
|
-
const code =
|
|
47
|
+
const code = getCodeDefaultBySource(source);
|
|
48
48
|
form.setFieldsValue({ source, code });
|
|
49
49
|
}
|
|
50
50
|
setOpenModal(true);
|
|
51
|
-
}, [value, form, sourceOptions,
|
|
51
|
+
}, [value, form, sourceOptions, getCodeDefaultBySource]);
|
|
52
52
|
const onDeselect = useCallback(() => {
|
|
53
53
|
onChange({ value: '', valueType: 'input' });
|
|
54
54
|
}, [onChange]);
|
|
@@ -82,10 +82,10 @@ const InputSelectAttribute = (props) => {
|
|
|
82
82
|
const onValuesChange = useCallback((changedValues) => {
|
|
83
83
|
// If source changed -> set new code based on new source
|
|
84
84
|
if (changedValues?.source) {
|
|
85
|
-
const newCode =
|
|
85
|
+
const newCode = getCodeDefaultBySource(changedValues.source);
|
|
86
86
|
form.setFieldValue('code', newCode);
|
|
87
87
|
}
|
|
88
|
-
}, [form,
|
|
88
|
+
}, [form, getCodeDefaultBySource]);
|
|
89
89
|
const renderInput = () => {
|
|
90
90
|
let element = null;
|
|
91
91
|
const isObjValue = value && typeof value !== 'string';
|
|
@@ -97,7 +97,7 @@ const InputSelectAttribute = (props) => {
|
|
|
97
97
|
height: 32,
|
|
98
98
|
padding: '4px 12px 4px 4px',
|
|
99
99
|
borderBottom: `1px solid ${errorMsg ? THEME.token?.colorError : THEME.token?.blue1}`,
|
|
100
|
-
}, children: [_jsx("div", { style: { width: '100%', cursor: 'pointer' }, onClick: onOpenModal, children: isObjValue && (_jsx(Tag, { isError: isErrorTag, children: isErrorTag ? (_jsxs(Flex, { gap: 5, align: "center", children: ["Unknown", _jsx(Tooltip, { title: "The used dynamic content is removed", children: _jsx(ErrorIcon, { size: 16 }) })] })) : (get(
|
|
100
|
+
}, children: [_jsx("div", { style: { width: '100%', cursor: 'pointer' }, onClick: onOpenModal, children: isObjValue && (_jsx(Tag, { isError: isErrorTag, children: isErrorTag ? (_jsxs(Flex, { gap: 5, align: "center", children: ["Unknown", _jsx(Tooltip, { title: "The used dynamic content is removed", children: _jsx(ErrorIcon, { size: 16 }) })] })) : (get(mapCodeBySource, [value?.code, 'label'], value?.code)) })) }), _jsx(Icon, { type: "icon-ants-remove", style: { fontSize: 10, color: '#222', cursor: 'pointer' }, onClick: onDeselect })] }));
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
103
103
|
element = (_jsx(StyledSelect, { mode: "multiple", options: [{ value: '', label: 'Or select a field' }], notFoundContent: null, onSelect: onOpenModal, style: { width: '100%', borderTop: 'none', borderLeft: 'none', borderRight: 'none' }, onDeselect: onDeselect, autoClearSearchValue: false, searchValue: typeof value === 'string' ? value : '', onSearch: onChangeInput, status: errorMsg ? 'error' : undefined, placeholder: typeof value === 'string' ? value : translate(translations.inputYourValue.title), "$isPlaceholder": !value, "$isError": !!errorMsg, dropdownStyle: {
|