@antscorp/antsomi-ui 1.3.5-beta.976 → 1.3.5-beta.978
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/es/components/molecules/AddDynamicContent/components/DisplayFormat/DisplayFormat.d.ts +0 -1
- package/es/components/molecules/InputSelectAttribute/index.d.ts +1 -0
- package/es/components/molecules/InputSelectAttribute/index.js +35 -13
- package/es/components/template/TemplateListing/Loadable.d.ts +0 -1
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ export interface InputSelectAttributeProps {
|
|
|
19
19
|
value: Value;
|
|
20
20
|
valueType: ValueType;
|
|
21
21
|
}) => void;
|
|
22
|
+
onChangeSelectSource: (value: string) => void;
|
|
22
23
|
}
|
|
23
24
|
declare const _default: import("react").MemoExoticComponent<(props: InputSelectAttributeProps) => import("react/jsx-runtime").JSX.Element>;
|
|
24
25
|
export default _default;
|
|
@@ -1,19 +1,20 @@
|
|
|
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
|
+
import { Form, Select, Typography } from 'antd';
|
|
5
6
|
// Translations
|
|
6
7
|
import { translate, translations } from '@antscorp/antsomi-ui/es/locales';
|
|
7
8
|
// Components
|
|
8
9
|
import Icon from '@antscorp/icons';
|
|
10
|
+
import { ModalV2 } from '../ModalV2';
|
|
9
11
|
import { StyledTag as Tag } from '@antscorp/antsomi-ui/es/components/molecules/SelectV2/styled';
|
|
10
|
-
import { Flex, Select, Typography } from 'antd';
|
|
11
12
|
import { StyledSelect } from './styled';
|
|
12
|
-
import { Modal } from '../Modal';
|
|
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, sourceOptions = [], codeOptions = [], onChange, onChangeSelectSource, } = props;
|
|
17
|
+
const [form] = Form.useForm();
|
|
17
18
|
// States
|
|
18
19
|
const [openModal, setOpenModal] = useState(false);
|
|
19
20
|
const [attributeState, setAttributeState] = useState(() => {
|
|
@@ -25,6 +26,12 @@ const InputSelectAttribute = (props) => {
|
|
|
25
26
|
code: '',
|
|
26
27
|
};
|
|
27
28
|
});
|
|
29
|
+
// Effects
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (attributeState.code === '') {
|
|
32
|
+
form.setFieldsValue({ code: codeOptions[0]?.value });
|
|
33
|
+
}
|
|
34
|
+
}, [attributeState, codeOptions, form]);
|
|
28
35
|
// Memoized
|
|
29
36
|
const mapCodeOpts = useMemo(() => keyBy(codeOptions, 'value'), [codeOptions]);
|
|
30
37
|
const onOpenModal = useCallback(() => {
|
|
@@ -36,10 +43,21 @@ const InputSelectAttribute = (props) => {
|
|
|
36
43
|
const onHideModal = useCallback(() => {
|
|
37
44
|
setOpenModal(false);
|
|
38
45
|
}, []);
|
|
39
|
-
const onOk =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
const onOk = async () => {
|
|
47
|
+
try {
|
|
48
|
+
// Validate form fields before getting values
|
|
49
|
+
const values = await form.validateFields();
|
|
50
|
+
const newValue = {
|
|
51
|
+
source: values.sources,
|
|
52
|
+
code: values.code,
|
|
53
|
+
};
|
|
54
|
+
setOpenModal(false);
|
|
55
|
+
onChange({ value: newValue, valueType: 'select' });
|
|
56
|
+
}
|
|
57
|
+
catch (errorInfo) {
|
|
58
|
+
console.error('Validation Failed:', errorInfo);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
43
61
|
const onChangeInput = useCallback((val) => {
|
|
44
62
|
onChange({ value: val, valueType: 'input' });
|
|
45
63
|
}, [onChange]);
|
|
@@ -63,10 +81,14 @@ const InputSelectAttribute = (props) => {
|
|
|
63
81
|
}
|
|
64
82
|
return element;
|
|
65
83
|
};
|
|
66
|
-
return (_jsxs(_Fragment, { children: [renderInput(), errorMsg ? (_jsx(Typography.Text, { style: { marginLeft: 8, color: THEME.token?.red8, marginTop: 5 }, children: errorMsg })) : null, _jsx(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
return (_jsxs(_Fragment, { children: [renderInput(), errorMsg ? (_jsx(Typography.Text, { style: { marginLeft: 8, color: THEME.token?.red8, marginTop: 5 }, children: errorMsg })) : null, _jsx(ModalV2, { title: translate(translations._PREDICT_MODEL_SELECT_ATTRIBUTE, 'Select attribute'), okText: translate(translations._ACT_APPLY, 'Apply'), open: openModal, onOk: onOk, onCancel: onHideModal, destroyOnClose: true, children: _jsxs(Form, { colon: false, form: form, initialValues: {
|
|
85
|
+
sources: attributeState.source || sourceOptions[0]?.value,
|
|
86
|
+
code: attributeState.code || codeOptions[0]?.value,
|
|
87
|
+
}, 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 => {
|
|
88
|
+
setAttributeState(state => ({ ...state, code: '', source: newValue }));
|
|
89
|
+
onChangeSelectSource(newValue);
|
|
90
|
+
} }) }), _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, onChange: newValue => {
|
|
91
|
+
setAttributeState(state => ({ ...state, source: newValue }));
|
|
92
|
+
} }) })] }) })] }));
|
|
71
93
|
};
|
|
72
94
|
export default memo(InputSelectAttribute);
|