@antscorp/antsomi-ui 1.3.5-beta.977 → 1.3.5-beta.979
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.
|
@@ -12,6 +12,7 @@ type Option = {
|
|
|
12
12
|
export interface InputSelectAttributeProps {
|
|
13
13
|
sourceOptions: Option[];
|
|
14
14
|
codeOptions: Option[];
|
|
15
|
+
listSourceInit: Option[];
|
|
15
16
|
label?: string;
|
|
16
17
|
errorMsg?: string;
|
|
17
18
|
value: Value;
|
|
@@ -19,6 +20,7 @@ export interface InputSelectAttributeProps {
|
|
|
19
20
|
value: Value;
|
|
20
21
|
valueType: ValueType;
|
|
21
22
|
}) => void;
|
|
23
|
+
onChangeSelectSource: (value: string) => void;
|
|
22
24
|
}
|
|
23
25
|
declare const _default: import("react").MemoExoticComponent<(props: InputSelectAttributeProps) => import("react/jsx-runtime").JSX.Element>;
|
|
24
26
|
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// Libraries
|
|
3
|
-
import { memo, useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import { memo, useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
4
|
import { get, keyBy } from 'lodash';
|
|
5
5
|
import { Form, Select, Typography } from 'antd';
|
|
6
6
|
// Translations
|
|
@@ -13,7 +13,7 @@ import { StyledSelect } from './styled';
|
|
|
13
13
|
// Constants
|
|
14
14
|
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
15
15
|
const InputSelectAttribute = (props) => {
|
|
16
|
-
const { value, errorMsg, label, sourceOptions = [], codeOptions = [], onChange } = props;
|
|
16
|
+
const { value, errorMsg, label, listSourceInit = [], sourceOptions = [], codeOptions = [], onChange, onChangeSelectSource, } = props;
|
|
17
17
|
const [form] = Form.useForm();
|
|
18
18
|
// States
|
|
19
19
|
const [openModal, setOpenModal] = useState(false);
|
|
@@ -26,8 +26,15 @@ const InputSelectAttribute = (props) => {
|
|
|
26
26
|
code: '',
|
|
27
27
|
};
|
|
28
28
|
});
|
|
29
|
+
// Effects
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (attributeState.code === '') {
|
|
32
|
+
form.setFieldsValue({ code: codeOptions[0]?.value });
|
|
33
|
+
}
|
|
34
|
+
}, [attributeState, codeOptions, form]);
|
|
29
35
|
// Memoized
|
|
30
36
|
const mapCodeOpts = useMemo(() => keyBy(codeOptions, 'value'), [codeOptions]);
|
|
37
|
+
const listSourceInitOpts = useMemo(() => keyBy(listSourceInit, 'value'), [listSourceInit]);
|
|
31
38
|
const onOpenModal = useCallback(() => {
|
|
32
39
|
setOpenModal(true);
|
|
33
40
|
}, []);
|
|
@@ -66,7 +73,7 @@ const InputSelectAttribute = (props) => {
|
|
|
66
73
|
height: 32,
|
|
67
74
|
padding: '4px 12px 4px 4px',
|
|
68
75
|
borderBottom: `1px solid ${errorMsg ? THEME.token?.colorError : THEME.token?.blue1}`,
|
|
69
|
-
}, children: [_jsx("div", { style: { width: '100%', cursor: 'pointer' }, onClick: onOpenModal, children: isObjValue && _jsx(Tag, { children: get(mapCodeOpts, [value.code, 'label'], value.code) }) }), _jsx(Icon, { type: "icon-ants-remove", style: { fontSize: 10, color: '#222', cursor: 'pointer' }, onClick: onDeselect })] }));
|
|
76
|
+
}, children: [_jsx("div", { style: { width: '100%', cursor: 'pointer' }, onClick: onOpenModal, children: isObjValue && (_jsx(Tag, { children: get(mapCodeOpts, [value.code, 'label'], get(listSourceInitOpts, [value.code, 'label'])) })) }), _jsx(Icon, { type: "icon-ants-remove", style: { fontSize: 10, color: '#222', cursor: 'pointer' }, onClick: onDeselect })] }));
|
|
70
77
|
}
|
|
71
78
|
else {
|
|
72
79
|
element = (_jsx(StyledSelect, { mode: "multiple", options: [{ value: '', label: translate(translations.orSelectAField.title) }], 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: {
|
|
@@ -79,9 +86,8 @@ const InputSelectAttribute = (props) => {
|
|
|
79
86
|
sources: attributeState.source || sourceOptions[0]?.value,
|
|
80
87
|
code: attributeState.code || codeOptions[0]?.value,
|
|
81
88
|
}, children: [_jsx(Form.Item, { label: translate(translations._TITL_PERSONALIZATION_TYPE, 'Content Source'), name: "sources", required: true, labelCol: { span: 6 }, labelAlign: "left", rules: [{ required: true, message: 'Please select field!' }], children: _jsx(Select, { suffixIcon: _jsx(Icon, { type: "icon-ants-expand-more", style: { fontSize: '20px', color: THEME.token?.colorIcon } }), options: sourceOptions, value: attributeState.source, onChange: newValue => {
|
|
82
|
-
setAttributeState(state => ({ ...state, source: newValue }));
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} }) })] }) })] }));
|
|
89
|
+
setAttributeState(state => ({ ...state, code: '', source: newValue }));
|
|
90
|
+
onChangeSelectSource(newValue);
|
|
91
|
+
} }) }), _jsx(Form.Item, { label: label || 'Allocated Code', required: true, labelCol: { span: 6 }, labelAlign: "left", name: "code", rules: [{ required: true, message: 'Please select field!' }], children: _jsx(Select, { suffixIcon: _jsx(Icon, { type: "icon-ants-expand-more", style: { fontSize: '20px', color: THEME.token?.colorIcon } }), value: attributeState.code, options: codeOptions }) })] }) })] }));
|
|
86
92
|
};
|
|
87
93
|
export default memo(InputSelectAttribute);
|