@antscorp/antsomi-ui 1.3.5-beta.977 → 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.
@@ -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,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, sourceOptions = [], codeOptions = [], onChange, onChangeSelectSource, } = props;
17
17
  const [form] = Form.useForm();
18
18
  // States
19
19
  const [openModal, setOpenModal] = useState(false);
@@ -26,6 +26,12 @@ 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]);
31
37
  const onOpenModal = useCallback(() => {
@@ -79,9 +85,10 @@ const InputSelectAttribute = (props) => {
79
85
  sources: attributeState.source || sourceOptions[0]?.value,
80
86
  code: attributeState.code || codeOptions[0]?.value,
81
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 => {
82
- setAttributeState(state => ({ ...state, source: newValue }));
88
+ setAttributeState(state => ({ ...state, code: '', source: newValue }));
89
+ onChangeSelectSource(newValue);
83
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 => {
84
- setAttributeState(state => ({ ...state, code: newValue }));
91
+ setAttributeState(state => ({ ...state, source: newValue }));
85
92
  } }) })] }) })] }));
86
93
  };
87
94
  export default memo(InputSelectAttribute);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.977",
3
+ "version": "1.3.5-beta.978",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",