@antscorp/antsomi-ui 1.3.5-beta.976 → 1.3.5-beta.977

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.
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { PayloadInfo } from '@antscorp/antsomi-ui/es/types';
3
2
  export type TDisplayFormat = 'number' | 'percentage' | 'currency' | 'datetime';
4
3
  type DisplayFormatProps = {
@@ -2,18 +2,19 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  // Libraries
3
3
  import { memo, useCallback, 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 } = props;
17
+ const [form] = Form.useForm();
17
18
  // States
18
19
  const [openModal, setOpenModal] = useState(false);
19
20
  const [attributeState, setAttributeState] = useState(() => {
@@ -36,10 +37,21 @@ const InputSelectAttribute = (props) => {
36
37
  const onHideModal = useCallback(() => {
37
38
  setOpenModal(false);
38
39
  }, []);
39
- const onOk = useCallback(() => {
40
- setOpenModal(false);
41
- onChange({ value: attributeState, valueType: 'select' });
42
- }, [attributeState, onChange]);
40
+ const onOk = async () => {
41
+ try {
42
+ // Validate form fields before getting values
43
+ const values = await form.validateFields();
44
+ const newValue = {
45
+ source: values.sources,
46
+ code: values.code,
47
+ };
48
+ setOpenModal(false);
49
+ onChange({ value: newValue, valueType: 'select' });
50
+ }
51
+ catch (errorInfo) {
52
+ console.error('Validation Failed:', errorInfo);
53
+ }
54
+ };
43
55
  const onChangeInput = useCallback((val) => {
44
56
  onChange({ value: val, valueType: 'input' });
45
57
  }, [onChange]);
@@ -63,10 +75,13 @@ const InputSelectAttribute = (props) => {
63
75
  }
64
76
  return element;
65
77
  };
66
- return (_jsxs(_Fragment, { children: [renderInput(), errorMsg ? (_jsx(Typography.Text, { style: { marginLeft: 8, color: THEME.token?.red8, marginTop: 5 }, children: errorMsg })) : null, _jsx(Modal, { title: translate(translations._PREDICT_MODEL_SELECT_ATTRIBUTE, 'Select attribute'), okText: translate(translations._ACT_APPLY, 'Apply'), open: openModal, onOk: onOk, onCancel: onHideModal, children: _jsxs(Flex, { vertical: true, gap: 15, children: [_jsxs(Flex, { gap: 10, children: [_jsxs(Typography.Text, { style: { lineHeight: '30px', flexBasis: 130 }, children: [translate(translations._TITL_PERSONALIZATION_TYPE, 'Content Source'), _jsx("span", { style: { color: THEME.token?.red8 }, children: "\u00A0 *" })] }), _jsx(Select, { suffixIcon: _jsx(Icon, { type: "icon-ants-expand-more", style: { fontSize: '20px', color: THEME.token?.colorIcon } }), style: { flex: 1 }, options: sourceOptions, value: attributeState.source, onChange: newValue => {
67
- setAttributeState(state => ({ ...state, source: newValue }));
68
- } })] }), _jsxs(Flex, { gap: 10, children: [_jsxs(Typography.Text, { style: { lineHeight: '30px', flexBasis: 130 }, children: [label || 'Allocated Code', _jsx("span", { style: { color: THEME.token?.red8 }, children: "\u00A0 *" })] }), _jsx(Select, { suffixIcon: _jsx(Icon, { type: "icon-ants-expand-more", style: { fontSize: '20px', color: THEME.token?.colorIcon } }), style: { flex: 1 }, value: attributeState.code, options: codeOptions, onChange: newValue => {
69
- setAttributeState(state => ({ ...state, code: newValue }));
70
- } })] })] }) })] }));
78
+ 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: {
79
+ sources: attributeState.source || sourceOptions[0]?.value,
80
+ code: attributeState.code || codeOptions[0]?.value,
81
+ }, 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
+ } }) }), _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 => {
84
+ setAttributeState(state => ({ ...state, code: newValue }));
85
+ } }) })] }) })] }));
71
86
  };
72
87
  export default memo(InputSelectAttribute);
@@ -3,5 +3,4 @@
3
3
  * Asynchronously loads the component for TemplateListing
4
4
  *
5
5
  */
6
- /// <reference types="react" />
7
6
  export declare const TemplateListing: (props: import("./types").TemplateListingProps<{}>) => JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.976",
3
+ "version": "1.3.5-beta.977",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",