@antscorp/antsomi-ui 1.3.5-beta.971 → 1.3.5-beta.972

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.
@@ -12,6 +12,7 @@ type Option = {
12
12
  export interface InputSelectAttributeProps {
13
13
  sourceOptions: Option[];
14
14
  codeOptions: Option[];
15
+ label?: string;
15
16
  errorMsg?: string;
16
17
  value: Value;
17
18
  onChange: (newValueData: {
@@ -1,6 +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, useState } from 'react';
3
+ import { memo, useCallback, useMemo, useState } from 'react';
4
+ import { get, keyBy } from 'lodash';
4
5
  // Translations
5
6
  import { translate, translations } from '@antscorp/antsomi-ui/es/locales';
6
7
  // Components
@@ -12,7 +13,7 @@ import { Modal } from '../Modal';
12
13
  // Constants
13
14
  import { THEME } from '@antscorp/antsomi-ui/es/constants';
14
15
  const InputSelectAttribute = (props) => {
15
- const { value, errorMsg, sourceOptions, codeOptions, onChange } = props;
16
+ const { value, errorMsg, label, sourceOptions, codeOptions, onChange } = props;
16
17
  // States
17
18
  const [openModal, setOpenModal] = useState(false);
18
19
  const [attributeState, setAttributeState] = useState(() => {
@@ -24,6 +25,8 @@ const InputSelectAttribute = (props) => {
24
25
  code: '',
25
26
  };
26
27
  });
28
+ // Memoized
29
+ const mapCodeOpts = useMemo(() => keyBy(codeOptions, 'value'), [codeOptions]);
27
30
  const onOpenModal = useCallback(() => {
28
31
  setOpenModal(true);
29
32
  }, []);
@@ -51,7 +54,7 @@ const InputSelectAttribute = (props) => {
51
54
  height: 32,
52
55
  padding: '4px 12px 4px 4px',
53
56
  borderBottom: `1px solid ${errorMsg ? THEME.token?.colorError : THEME.token?.blue1}`,
54
- }, children: [_jsx("div", { style: { width: '100%', cursor: 'pointer' }, onClick: onOpenModal, children: isObjValue && _jsx(Tag, { children: value.code }) }), _jsx(Icon, { type: "icon-ants-remove", style: { fontSize: 10, color: '#222', cursor: 'pointer' }, onClick: onDeselect })] }));
57
+ }, children: [_jsx("div", { style: { width: '100%', cursor: 'pointer' }, onClick: onOpenModal, children: isObjValue && _jsx(Tag, { children: get(mapCodeOpts, [value.code, 'label'], value.code) }) }), _jsx(Icon, { type: "icon-ants-remove", style: { fontSize: 10, color: '#222', cursor: 'pointer' }, onClick: onDeselect })] }));
55
58
  }
56
59
  else {
57
60
  element = (_jsx(StyledSelect, { mode: "multiple", options: [{ value: '', label: translate(translations.orSelectAField.title) }], 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: {
@@ -62,7 +65,7 @@ const InputSelectAttribute = (props) => {
62
65
  };
63
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 => {
64
67
  setAttributeState(state => ({ ...state, source: newValue }));
65
- } })] }), _jsxs(Flex, { gap: 10, children: [_jsxs(Typography.Text, { style: { lineHeight: '30px', flexBasis: 130 }, children: ["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 => {
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 => {
66
69
  setAttributeState(state => ({ ...state, code: newValue }));
67
70
  } })] })] }) })] }));
68
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.971",
3
+ "version": "1.3.5-beta.972",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",