@antscorp/antsomi-ui 1.3.5-beta.997 → 1.3.5-beta.999
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 +5 -6
- package/es/components/molecules/InputSelectAttribute/index.js +49 -36
- package/es/components/template/TemplateListing/Loadable.d.ts +0 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export type ValueType = 'input' | 'select';
|
|
3
|
-
type Value =
|
|
3
|
+
type Value = {
|
|
4
4
|
source: string;
|
|
5
|
-
code:
|
|
6
|
-
} |
|
|
5
|
+
code: any;
|
|
6
|
+
} | string;
|
|
7
7
|
type Option = {
|
|
8
8
|
[key: string]: any;
|
|
9
9
|
label: string;
|
|
@@ -11,16 +11,15 @@ type Option = {
|
|
|
11
11
|
};
|
|
12
12
|
export interface InputSelectAttributeProps {
|
|
13
13
|
sourceOptions: Option[];
|
|
14
|
-
|
|
15
|
-
codeOptionsInitial?: Option[];
|
|
14
|
+
mapCodeOptions: Record<string, Option[]>;
|
|
16
15
|
label?: string;
|
|
16
|
+
isErrorTag?: boolean;
|
|
17
17
|
errorMsg?: string;
|
|
18
18
|
value: Value;
|
|
19
19
|
onChange: (newValueData: {
|
|
20
20
|
value: Value;
|
|
21
21
|
valueType: ValueType;
|
|
22
22
|
}) => void;
|
|
23
|
-
onChangeSelectSource: (value: string) => void;
|
|
24
23
|
}
|
|
25
24
|
declare const _default: import("react").MemoExoticComponent<(props: InputSelectAttributeProps) => import("react/jsx-runtime").JSX.Element>;
|
|
26
25
|
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// Libraries
|
|
3
|
-
import { memo, useCallback,
|
|
4
|
-
import { get,
|
|
3
|
+
import { memo, useCallback, useMemo, useState } from 'react';
|
|
4
|
+
import { get, keyBy, upperFirst } from 'lodash';
|
|
5
5
|
import { Flex, Form, Select, Tooltip, Typography } from 'antd';
|
|
6
6
|
// Translations
|
|
7
7
|
import { translate, translations } from '@antscorp/antsomi-ui/es/locales';
|
|
@@ -15,62 +15,81 @@ import { Dashboard30Icon, ErrorIcon } from '../../icons';
|
|
|
15
15
|
// Constants
|
|
16
16
|
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
17
17
|
const InputSelectAttribute = (props) => {
|
|
18
|
-
const { value, errorMsg, label,
|
|
18
|
+
const { value, errorMsg, label, isErrorTag, sourceOptions = [], mapCodeOptions = {}, onChange, } = props;
|
|
19
19
|
const [form] = Form.useForm();
|
|
20
|
+
const sourceValue = Form.useWatch('source', form);
|
|
20
21
|
// States
|
|
21
22
|
const [openModal, setOpenModal] = useState(false);
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
return
|
|
23
|
+
const codeOptions = useMemo(() => {
|
|
24
|
+
if (sourceValue) {
|
|
25
|
+
return get(mapCodeOptions, sourceValue, []);
|
|
25
26
|
}
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// Effects
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (attributeState.code === '' ||
|
|
34
|
-
!codeOptions.find(option => option.value === attributeState.code)) {
|
|
35
|
-
form.setFieldsValue({ code: codeOptions[0]?.value });
|
|
27
|
+
return [];
|
|
28
|
+
}, [sourceValue, mapCodeOptions]);
|
|
29
|
+
const initCodeTitleField = useMemo(() => {
|
|
30
|
+
if (sourceValue === 'allocated_code') {
|
|
31
|
+
return 'Allocated Code';
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
33
|
+
return upperFirst(translate(translations._ITEM_NAME_ATTRIBUTE, 'attribute'));
|
|
34
|
+
}, [sourceValue]);
|
|
35
|
+
const mapCode = useMemo(() => {
|
|
36
|
+
if (typeof value === 'string')
|
|
37
|
+
return {};
|
|
38
|
+
return keyBy(get(mapCodeOptions, value?.code, []), 'value');
|
|
39
|
+
}, [mapCodeOptions, value]);
|
|
40
|
+
const getCodeBySource = useCallback((source) => get(mapCodeOptions, [source, '0', 'value'], ''), [mapCodeOptions]);
|
|
41
41
|
const onOpenModal = useCallback(() => {
|
|
42
|
+
if (value && typeof value !== 'string') {
|
|
43
|
+
form.setFieldsValue({ source: value?.source, code: value?.code });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const source = sourceOptions[0]?.value || '';
|
|
47
|
+
const code = getCodeBySource(source);
|
|
48
|
+
form.setFieldsValue({ source, code });
|
|
49
|
+
}
|
|
42
50
|
setOpenModal(true);
|
|
43
|
-
}, []);
|
|
51
|
+
}, [value, form, sourceOptions, getCodeBySource]);
|
|
44
52
|
const onDeselect = useCallback(() => {
|
|
45
53
|
onChange({ value: '', valueType: 'input' });
|
|
46
54
|
}, [onChange]);
|
|
47
55
|
const onHideModal = useCallback(() => {
|
|
48
56
|
setOpenModal(false);
|
|
49
57
|
}, []);
|
|
58
|
+
const onAfterClose = useCallback(() => {
|
|
59
|
+
form.resetFields();
|
|
60
|
+
}, [form]);
|
|
50
61
|
const onOk = async () => {
|
|
51
62
|
try {
|
|
52
63
|
// Validate form fields before getting values
|
|
53
64
|
const values = await form.validateFields();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
if (typeof values !== 'string') {
|
|
66
|
+
const newValue = {
|
|
67
|
+
source: values?.source,
|
|
68
|
+
code: values?.code,
|
|
69
|
+
};
|
|
70
|
+
onChange({ value: newValue, valueType: 'select' });
|
|
71
|
+
}
|
|
58
72
|
setOpenModal(false);
|
|
59
|
-
onChange({ value: newValue, valueType: 'select' });
|
|
60
73
|
}
|
|
61
74
|
catch (errorInfo) {
|
|
75
|
+
// eslint-disable-next-line no-console
|
|
62
76
|
console.error('Validation Failed:', errorInfo);
|
|
63
77
|
}
|
|
64
78
|
};
|
|
65
79
|
const onChangeInput = useCallback((val) => {
|
|
66
80
|
onChange({ value: val, valueType: 'input' });
|
|
67
81
|
}, [onChange]);
|
|
82
|
+
const onValuesChange = useCallback((changedValues) => {
|
|
83
|
+
// If source changed -> set new code based on new source
|
|
84
|
+
if (changedValues?.source) {
|
|
85
|
+
const newCode = getCodeBySource(changedValues.source);
|
|
86
|
+
form.setFieldValue('code', newCode);
|
|
87
|
+
}
|
|
88
|
+
}, [form, getCodeBySource]);
|
|
68
89
|
const renderInput = () => {
|
|
69
90
|
let element = null;
|
|
70
91
|
const isObjValue = value && typeof value !== 'string';
|
|
71
92
|
if (openModal || isObjValue) {
|
|
72
|
-
const isErrorTag = (isObjValue &&
|
|
73
|
-
isUndefined(get(mapCodeOriginOpts, [value.code])));
|
|
74
93
|
element = (_jsxs("div", { style: {
|
|
75
94
|
display: 'flex',
|
|
76
95
|
alignItems: 'center',
|
|
@@ -78,7 +97,7 @@ const InputSelectAttribute = (props) => {
|
|
|
78
97
|
height: 32,
|
|
79
98
|
padding: '4px 12px 4px 4px',
|
|
80
99
|
borderBottom: `1px solid ${errorMsg ? THEME.token?.colorError : THEME.token?.blue1}`,
|
|
81
|
-
}, 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(mapCode, [value?.code, 'label'], value?.code)) })) }), _jsx(Icon, { type: "icon-ants-remove", style: { fontSize: 10, color: '#222', cursor: 'pointer' }, onClick: onDeselect })] }));
|
|
82
101
|
}
|
|
83
102
|
else {
|
|
84
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: {
|
|
@@ -87,12 +106,6 @@ const InputSelectAttribute = (props) => {
|
|
|
87
106
|
}
|
|
88
107
|
return element;
|
|
89
108
|
};
|
|
90
|
-
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, centered: true, children: _jsxs(Form, { colon: false, form: form,
|
|
91
|
-
sources: attributeState.source || sourceOptions[0]?.value,
|
|
92
|
-
code: attributeState.code || codeOptions[0]?.value,
|
|
93
|
-
}, 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, placeholder: "Please select an item", value: attributeState.source, onChange: newValue => {
|
|
94
|
-
setAttributeState(state => ({ ...state, code: '', source: newValue }));
|
|
95
|
-
onChangeSelectSource(newValue);
|
|
96
|
-
} }) }), _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 } }), notFoundContent: _jsx(EmptyData, { size: "small", icon: _jsx(Dashboard30Icon, {}), description: "No personalized content in this journey" }), placeholder: "Please select an item", value: attributeState.code, options: codeOptions }) })] }) })] }));
|
|
109
|
+
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, afterClose: onAfterClose, destroyOnClose: true, centered: true, children: _jsxs(Form, { colon: false, form: form, onValuesChange: onValuesChange, children: [_jsx(Form.Item, { label: translate(translations._TITL_PERSONALIZATION_TYPE, 'Content Source'), name: "source", 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, placeholder: "Please select an item" }) }), _jsx(Form.Item, { label: label || initCodeTitleField, 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 } }), notFoundContent: _jsx(EmptyData, { size: "small", icon: _jsx(Dashboard30Icon, {}), description: "No personalized content in this journey" }), placeholder: "Please select an item", options: codeOptions }) })] }) })] }));
|
|
97
110
|
};
|
|
98
111
|
export default memo(InputSelectAttribute);
|