@antscorp/antsomi-ui 1.3.5-beta.996 → 1.3.5-beta.998
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/DrawerDetail/DrawerDetail.js +2 -2
- package/es/components/molecules/DrawerDetail/types.d.ts +3 -0
- package/es/components/molecules/InputSelectAttribute/index.d.ts +5 -6
- package/es/components/molecules/InputSelectAttribute/index.js +44 -37
- package/es/components/template/TemplateListing/Loadable.d.ts +0 -1
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ import { safeParseJson } from '@antscorp/antsomi-ui/es/utils';
|
|
|
16
16
|
import { POST_MESSAGE_TYPES } from '@antscorp/antsomi-ui/es/constants';
|
|
17
17
|
export const DrawerDetail = props => {
|
|
18
18
|
// Props
|
|
19
|
-
const { width, fullScreen: fullScreenProp = false, children, menuProps, closeIconProps, maxWidth, minWidth, defaultSize = 'max', headerProps, name, destroyOnClose = true, mask = false, onToggleCollapse, closable = false, ...restProps } = props;
|
|
19
|
+
const { width, fullScreen: fullScreenProp = false, children, menuProps, closeIconProps, maxWidth, minWidth, defaultSize = 'max', headerProps, name, destroyOnClose = true, mask = false, classNames, onToggleCollapse, closable = false, ...restProps } = props;
|
|
20
20
|
const { show: showMenu = true, showExpandButton = true, showClose = true, items, selectedKeys, footer, onClick = () => { }, } = menuProps || {};
|
|
21
21
|
const { children: headerChildren, ...restOfHeaderProps } = headerProps || {};
|
|
22
22
|
const { onClose = () => { } } = props;
|
|
@@ -129,7 +129,7 @@ export const DrawerDetail = props => {
|
|
|
129
129
|
}, destroyOnClose: destroyOnClose, ...restProps, children: [showCloseIcon && (_jsx("div", { className: "close-btn", ...restOfCloseIcon, onClick: e => {
|
|
130
130
|
onCloseIconClick(e);
|
|
131
131
|
onClose(e);
|
|
132
|
-
}, children: _jsx(Icon, { type: "icon-ants-remove-slim", size: 14 }) })), showExpandButton && !fullScreen && (_jsx(ToggleDrawerSizeButton, { style: {
|
|
132
|
+
}, children: _jsx(Icon, { type: "icon-ants-remove-slim", size: 14 }) })), showExpandButton && !fullScreen && (_jsx(ToggleDrawerSizeButton, { className: classNames?.btnToogleSize, style: {
|
|
133
133
|
...(!showMenu && { background: '#ffffff' }),
|
|
134
134
|
}, onClick: () => handleToggleDrawerSize(), collapse: collapseDrawer })), showMenu && (_jsxs(LeftMenu, { "data-test": "left-menu", className: "animate__animated animate__fadeIn", children: [_jsxs("div", { children: [showClose && (_jsx(CloseBtn, { "data-test": "close-btn", onClick: onClose, children: _jsx(Icon, { type: "icon-ants-remove-slim", size: 14 }) })), _jsx(Flex, { vertical: true, gap: 10, align: "center", justify: "center", children: items?.map((item) => (_jsx(Tooltip, { title: item?.label, mouseEnterDelay: 0.3, placement: "right", children: _jsx(MenuItem, { className: selectedKeys?.includes(item.key) ? 'active' : '', onClick: () => onClick && onClick(item), children: item.icon }, item?.key) }, item?.key))) })] }), _jsx(MenuFooter, { children: footer })] })), _jsxs(Content, { className: "drawer-detail-content", children: [headerProps?.children && (_jsx(DrawerHeader, { align: "center", ...restOfHeaderProps, children: headerChildren })), children] })] }));
|
|
135
135
|
};
|
|
@@ -11,6 +11,9 @@ export interface DrawerDetailProps extends Omit<DrawerProps, 'closeIcon' | 'titl
|
|
|
11
11
|
headerProps?: DrawerHeaderProps;
|
|
12
12
|
menuProps?: DrawerDetailMenuProps;
|
|
13
13
|
closeIconProps?: DrawerDetailCloseIconProps;
|
|
14
|
+
classNames?: DrawerProps['classNames'] & {
|
|
15
|
+
btnToogleSize?: string;
|
|
16
|
+
};
|
|
14
17
|
onToggleCollapse?: (collapsed: boolean) => void;
|
|
15
18
|
}
|
|
16
19
|
export interface DrawerDetailCloseIconProps extends React.HtmlHTMLAttributes<HTMLDivElement> {
|
|
@@ -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 } 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,75 @@ 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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
!codeOptions.find(option => option.value === attributeState.code)) {
|
|
35
|
-
form.setFieldsValue({ code: codeOptions[0]?.value });
|
|
36
|
-
}
|
|
37
|
-
}, [attributeState, codeOptions, form]);
|
|
38
|
-
// Memoized
|
|
39
|
-
const mapCodeOpts = useMemo(() => keyBy(codeOptions, 'value'), [codeOptions]);
|
|
40
|
-
const mapCodeOriginOpts = useMemo(() => keyBy(codeOptionsInitial, 'value'), [codeOptionsInitial]);
|
|
27
|
+
return [];
|
|
28
|
+
}, [sourceValue, mapCodeOptions]);
|
|
29
|
+
const mapCode = useMemo(() => {
|
|
30
|
+
if (typeof value === 'string')
|
|
31
|
+
return {};
|
|
32
|
+
return keyBy(get(mapCodeOptions, value?.code, []), 'value');
|
|
33
|
+
}, [mapCodeOptions, value]);
|
|
34
|
+
const getCodeBySource = useCallback((source) => get(mapCodeOptions, [source, '0', 'value'], ''), [mapCodeOptions]);
|
|
41
35
|
const onOpenModal = useCallback(() => {
|
|
36
|
+
if (typeof value !== 'string') {
|
|
37
|
+
form.setFieldsValue({ source: value?.source, code: value?.code });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const source = sourceOptions[0]?.value || '';
|
|
41
|
+
const code = getCodeBySource(source);
|
|
42
|
+
form.setFieldsValue({ source, code });
|
|
43
|
+
}
|
|
42
44
|
setOpenModal(true);
|
|
43
|
-
}, []);
|
|
45
|
+
}, [value, form, sourceOptions, getCodeBySource]);
|
|
44
46
|
const onDeselect = useCallback(() => {
|
|
45
47
|
onChange({ value: '', valueType: 'input' });
|
|
46
48
|
}, [onChange]);
|
|
47
49
|
const onHideModal = useCallback(() => {
|
|
48
50
|
setOpenModal(false);
|
|
49
51
|
}, []);
|
|
52
|
+
const onAfterClose = useCallback(() => {
|
|
53
|
+
form.resetFields();
|
|
54
|
+
}, [form]);
|
|
50
55
|
const onOk = async () => {
|
|
51
56
|
try {
|
|
52
57
|
// Validate form fields before getting values
|
|
53
58
|
const values = await form.validateFields();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
if (typeof values !== 'string') {
|
|
60
|
+
const newValue = {
|
|
61
|
+
source: values?.source,
|
|
62
|
+
code: values?.code,
|
|
63
|
+
};
|
|
64
|
+
onChange({ value: newValue, valueType: 'select' });
|
|
65
|
+
}
|
|
58
66
|
setOpenModal(false);
|
|
59
|
-
onChange({ value: newValue, valueType: 'select' });
|
|
60
67
|
}
|
|
61
68
|
catch (errorInfo) {
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
62
70
|
console.error('Validation Failed:', errorInfo);
|
|
63
71
|
}
|
|
64
72
|
};
|
|
65
73
|
const onChangeInput = useCallback((val) => {
|
|
66
74
|
onChange({ value: val, valueType: 'input' });
|
|
67
75
|
}, [onChange]);
|
|
76
|
+
const onValuesChange = useCallback((changedValues) => {
|
|
77
|
+
// If source changed -> set new code based on new source
|
|
78
|
+
if (changedValues?.source) {
|
|
79
|
+
const newCode = getCodeBySource(changedValues.source);
|
|
80
|
+
form.setFieldValue('code', newCode);
|
|
81
|
+
}
|
|
82
|
+
}, [form, getCodeBySource]);
|
|
68
83
|
const renderInput = () => {
|
|
69
84
|
let element = null;
|
|
70
85
|
const isObjValue = value && typeof value !== 'string';
|
|
71
86
|
if (openModal || isObjValue) {
|
|
72
|
-
const isErrorTag = (isObjValue &&
|
|
73
|
-
isUndefined(get(mapCodeOriginOpts, [value.code])));
|
|
74
87
|
element = (_jsxs("div", { style: {
|
|
75
88
|
display: 'flex',
|
|
76
89
|
alignItems: 'center',
|
|
@@ -78,7 +91,7 @@ const InputSelectAttribute = (props) => {
|
|
|
78
91
|
height: 32,
|
|
79
92
|
padding: '4px 12px 4px 4px',
|
|
80
93
|
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(
|
|
94
|
+
}, 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
95
|
}
|
|
83
96
|
else {
|
|
84
97
|
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 +100,6 @@ const InputSelectAttribute = (props) => {
|
|
|
87
100
|
}
|
|
88
101
|
return element;
|
|
89
102
|
};
|
|
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 }) })] }) })] }));
|
|
103
|
+
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 || '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", options: codeOptions }) })] }) })] }));
|
|
97
104
|
};
|
|
98
105
|
export default memo(InputSelectAttribute);
|