@antscorp/antsomi-ui 1.3.5-beta.222 → 1.3.5-beta.224

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.
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ export interface AccountListingProps {
3
+ className?: string;
4
+ apiConfig: {
5
+ domain: string;
6
+ token: string;
7
+ userId: number;
8
+ portalId?: number;
9
+ languageCode?: string;
10
+ appCode?: string;
11
+ };
12
+ showAllAccount?: boolean;
13
+ currentAccount?: number | 'ALL_ACCOUNT';
14
+ onLabelChange?: (label: string) => void;
15
+ onChange?: (userId: number | 'ALL_ACCOUNT') => void;
16
+ }
17
+ export declare const AccountListing: React.FC<AccountListingProps>;
@@ -0,0 +1,72 @@
1
+ import Icon from '@antscorp/icons';
2
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
3
+ import { Input, Text } from '@antscorp/antsomi-ui/es/components/atoms';
4
+ import { AccountItem } from './components';
5
+ import { AccountSelectionStyled } from './styled';
6
+ import { PORTALS_IDS } from '@antscorp/antsomi-ui/es/constants';
7
+ import { searchStringQuery } from '@antscorp/antsomi-ui/es/utils';
8
+ import { useGetAccountList, useGetPermissionAccountList, useGetRecentAccount } from '../../..';
9
+ export const AccountListing = props => {
10
+ const { className, apiConfig, showAllAccount = true, currentAccount, onLabelChange, onChange, } = props;
11
+ const { domain, token, userId, appCode, portalId } = apiConfig;
12
+ const { data } = useGetAccountList({
13
+ apiConfig,
14
+ options: {
15
+ enabled: portalId !== PORTALS_IDS.SANDBOX_76753,
16
+ },
17
+ });
18
+ const { data: permissionAccountList } = useGetPermissionAccountList({
19
+ args: {
20
+ _account_id: userId,
21
+ _user_id: userId,
22
+ _app_code: appCode || '',
23
+ _token: token,
24
+ domain,
25
+ appCode: appCode || '',
26
+ fullParent: true,
27
+ menuCode: appCode || '',
28
+ },
29
+ options: {
30
+ enabled: portalId === PORTALS_IDS.SANDBOX_76753,
31
+ },
32
+ });
33
+ const { data: recentData } = useGetRecentAccount({
34
+ apiConfig,
35
+ options: {
36
+ enabled: portalId !== PORTALS_IDS.SANDBOX_76753,
37
+ },
38
+ });
39
+ const accountData = useMemo(() => {
40
+ if (portalId === PORTALS_IDS.SANDBOX_76753) {
41
+ return ((permissionAccountList === null || permissionAccountList === void 0 ? void 0 : permissionAccountList.map(account => ({
42
+ email: account.email,
43
+ userId: account.user_id,
44
+ userName: account.full_name,
45
+ status: 1,
46
+ }))) || []);
47
+ }
48
+ return (data === null || data === void 0 ? void 0 : data.entries) || [];
49
+ }, [data === null || data === void 0 ? void 0 : data.entries, permissionAccountList, portalId]);
50
+ const [searchValue, setSearchValue] = useState('');
51
+ const currentAccountInfo = useMemo(() => accountData === null || accountData === void 0 ? void 0 : accountData.find(account => account.userId === currentAccount), [accountData, currentAccount]);
52
+ // HACK: this use for popover input label
53
+ const inputLabel = currentAccount === 'ALL_ACCOUNT' ? 'All account' : currentAccountInfo === null || currentAccountInfo === void 0 ? void 0 : currentAccountInfo.userName;
54
+ useEffect(() => {
55
+ if (onLabelChange)
56
+ onLabelChange(inputLabel);
57
+ }, [inputLabel]);
58
+ const handleSelectAccount = useCallback((userId) => {
59
+ if (onChange)
60
+ onChange(userId);
61
+ }, [onChange]);
62
+ return (React.createElement(AccountSelectionStyled, { className: className },
63
+ React.createElement(Input, { placeholder: "Search", suffix: React.createElement(Icon, { type: "icon-ants-search-2", style: { fontSize: '24px' } }), value: searchValue, onChange: event => setSearchValue(event.target.value) }),
64
+ !!(recentData === null || recentData === void 0 ? void 0 : recentData.value) && (React.createElement(React.Fragment, null,
65
+ React.createElement(Text, { className: "recent-text" }, "Recent"),
66
+ React.createElement("ul", null, recentData === null || recentData === void 0 ? void 0 : recentData.value.map(accountId => accountData === null || accountData === void 0 ? void 0 : accountData.find(account => account.userId === accountId)).filter(Boolean).map(account => (React.createElement(AccountItem, { key: account.userId, userName: account.userName, userId: account.userId, onClick: handleSelectAccount, isSelected: currentAccount === account.userId })))))),
67
+ React.createElement("div", { className: "antsomi-scroll-box account-list" },
68
+ React.createElement("ul", { className: "scroll-content" }, accountData === null || accountData === void 0 ? void 0 : accountData.filter(account => !(recentData === null || recentData === void 0 ? void 0 : recentData.value.includes(account.userId)) &&
69
+ searchStringQuery(account.userName, searchValue)).map(account => (React.createElement(AccountItem, { key: account.userId, userName: account.userName, userId: account.userId, onClick: handleSelectAccount, isSelected: currentAccount === account.userId }))))),
70
+ showAllAccount ? (React.createElement(Text, { className: `all-account ${currentAccount === 'ALL_ACCOUNT' ? 'is-selected' : ''}`, onClick: () => handleSelectAccount('ALL_ACCOUNT') },
71
+ React.createElement("strong", null, "All account"))) : null));
72
+ };
@@ -1,18 +1,8 @@
1
1
  import React from 'react';
2
2
  import { PopoverProps } from 'antd';
3
- export interface AccountSelectionProps {
3
+ import { AccountListingProps } from './AccountListing';
4
+ export interface AccountSelectionProps extends Omit<AccountListingProps, 'onChange' | 'onLabelChange'> {
4
5
  show?: boolean;
5
- className?: string;
6
- apiConfig: {
7
- domain: string;
8
- token: string;
9
- userId: number;
10
- portalId?: number;
11
- languageCode?: string;
12
- appCode?: string;
13
- };
14
- showAllAccount?: boolean;
15
- currentAccount?: number | 'ALL_ACCOUNT';
16
6
  inputStyle?: 'select' | 'input';
17
7
  inputClassName?: string;
18
8
  onChange?: (userId: number | 'ALL_ACCOUNT') => void;
@@ -1,72 +1,31 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import Icon from '@antscorp/icons';
2
- import React, { useCallback, useMemo, useState } from 'react';
3
- import { Input, Popover, Text } from '@antscorp/antsomi-ui/es/components/atoms';
4
- import { AccountItem } from './components';
5
- import { AccountSelectionStyled, PopoverFieldStyled } from './styled';
6
- import { useGetAccountList, useGetPermissionAccountList, useGetRecentAccount } from '../../..';
13
+ import React, { useCallback, useState } from 'react';
14
+ import { Popover } from '@antscorp/antsomi-ui/es/components/atoms';
15
+ import { PopoverFieldStyled } from './styled';
7
16
  import { Tooltip } from 'antd';
8
- import { searchStringQuery } from '@antscorp/antsomi-ui/es/utils';
9
- import { PORTALS_IDS } from '@antscorp/antsomi-ui/es/constants';
17
+ import { AccountListing } from './AccountListing';
10
18
  export const AccountSelection = props => {
11
- const { show = true, className, apiConfig, showAllAccount = true, currentAccount, inputStyle = 'input', inputClassName, onChange, getPopupContainer, zIndex, } = props;
12
- const { domain, token, userId, appCode, portalId } = apiConfig;
13
- const { data } = useGetAccountList({
14
- apiConfig,
15
- options: {
16
- enabled: portalId !== PORTALS_IDS.SANDBOX_76753,
17
- },
18
- });
19
- const { data: permissionAccountList } = useGetPermissionAccountList({
20
- args: {
21
- _account_id: userId,
22
- _user_id: userId,
23
- _app_code: appCode || '',
24
- _token: token,
25
- domain,
26
- appCode: appCode || '',
27
- fullParent: true,
28
- menuCode: appCode || '',
29
- },
30
- options: {
31
- enabled: portalId === PORTALS_IDS.SANDBOX_76753,
32
- },
33
- });
34
- const { data: recentData } = useGetRecentAccount({
35
- apiConfig,
36
- options: {
37
- enabled: portalId !== PORTALS_IDS.SANDBOX_76753,
38
- },
39
- });
40
- const accountData = useMemo(() => {
41
- if (portalId === PORTALS_IDS.SANDBOX_76753) {
42
- return ((permissionAccountList === null || permissionAccountList === void 0 ? void 0 : permissionAccountList.map(account => ({
43
- email: account.email,
44
- userId: account.user_id,
45
- userName: account.full_name,
46
- status: 1,
47
- }))) || []);
48
- }
49
- return (data === null || data === void 0 ? void 0 : data.entries) || [];
50
- }, [data === null || data === void 0 ? void 0 : data.entries, permissionAccountList, portalId]);
51
- const currentAccountInfo = useMemo(() => accountData === null || accountData === void 0 ? void 0 : accountData.find(account => account.userId === currentAccount), [accountData, currentAccount]);
19
+ const { show = true, inputStyle = 'input', inputClassName, onChange, getPopupContainer, zIndex } = props, accountListingProps = __rest(props, ["show", "inputStyle", "inputClassName", "onChange", "getPopupContainer", "zIndex"]);
20
+ const [inputLabel, setInputLabel] = useState('');
52
21
  const [open, setOpen] = useState(false);
53
- const [searchValue, setSearchValue] = useState('');
22
+ // const [searchValue, setSearchValue] = useState<string>('');
54
23
  const handleSelectAccount = useCallback((userId) => {
55
24
  setOpen(false);
56
25
  if (onChange)
57
26
  onChange(userId);
58
27
  }, [onChange]);
59
- const inputLabel = currentAccount === 'ALL_ACCOUNT' ? 'All account' : currentAccountInfo === null || currentAccountInfo === void 0 ? void 0 : currentAccountInfo.userName;
60
- return (show && (React.createElement(Popover, { content: React.createElement(AccountSelectionStyled, { className: className },
61
- React.createElement(Input, { placeholder: "Search", suffix: React.createElement(Icon, { type: "icon-ants-search-2", style: { fontSize: '24px' } }), value: searchValue, onChange: event => setSearchValue(event.target.value) }),
62
- !!(recentData === null || recentData === void 0 ? void 0 : recentData.value) && (React.createElement(React.Fragment, null,
63
- React.createElement(Text, { className: "recent-text" }, "Recent"),
64
- React.createElement("ul", null, recentData === null || recentData === void 0 ? void 0 : recentData.value.map(accountId => accountData === null || accountData === void 0 ? void 0 : accountData.find(account => account.userId === accountId)).filter(Boolean).map(account => (React.createElement(AccountItem, { key: account.userId, userName: account.userName, userId: account.userId, onClick: handleSelectAccount, isSelected: currentAccount === account.userId })))))),
65
- React.createElement("div", { className: "antsomi-scroll-box account-list" },
66
- React.createElement("ul", { className: "scroll-content" }, accountData === null || accountData === void 0 ? void 0 : accountData.filter(account => !(recentData === null || recentData === void 0 ? void 0 : recentData.value.includes(account.userId)) &&
67
- searchStringQuery(account.userName, searchValue)).map(account => (React.createElement(AccountItem, { key: account.userId, userName: account.userName, userId: account.userId, onClick: handleSelectAccount, isSelected: currentAccount === account.userId }))))),
68
- showAllAccount ? (React.createElement(Text, { className: `all-account ${currentAccount === 'ALL_ACCOUNT' ? 'is-selected' : ''}`, onClick: () => handleSelectAccount('ALL_ACCOUNT') },
69
- React.createElement("strong", null, "All account"))) : null), trigger: "click", overlayInnerStyle: { padding: 0 },
28
+ return (show && (React.createElement(Popover, { content: React.createElement(AccountListing, Object.assign({}, accountListingProps, { onChange: handleSelectAccount, onLabelChange: newLabel => setInputLabel(newLabel) })), trigger: "click", overlayInnerStyle: { padding: 0 },
70
29
  // getPopupContainer={triggerNode => triggerNode}
71
30
  getPopupContainer: getPopupContainer, placement: "bottomLeft", arrow: false, open: open, onOpenChange: setOpen, zIndex: zIndex || 1300 },
72
31
  React.createElement(PopoverFieldStyled, { className: `${inputStyle || ''} ${inputClassName || ''}` },
@@ -1 +1,2 @@
1
1
  export { AccountSelection, type AccountSelectionProps } from './AccountSelection';
2
+ export { AccountListing } from './AccountListing';
@@ -1 +1,2 @@
1
1
  export { AccountSelection } from './AccountSelection';
2
+ export { AccountListing } from './AccountListing';
@@ -4,6 +4,10 @@ declare const DRAWER_LARGE_MAX_WIDTH = "calc(100vw - 70px)";
4
4
  declare const DRAWER_SMALL_MAX_WIDTH = "calc(100vw - 70px)";
5
5
  declare const DRAWER_SMALL_MIN_WIDTH = "calc(100vw - 310px)";
6
6
  declare const BREAK_POINT = "1440px";
7
- declare const LAYER_2_MIN_WIDTH = "740px";
8
- declare const LAYER_2_MAX_WIDTH = "calc(100vw - 46px)";
9
- export { DRAWER_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_LARGE_MAX_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, BREAK_POINT, LAYER_2_MAX_WIDTH, LAYER_2_MIN_WIDTH, };
7
+ declare const DRAWER_DETAIL_DIMENSION: {
8
+ LAYER_2: {
9
+ minWidth: string;
10
+ maxWidth: string;
11
+ };
12
+ };
13
+ export { DRAWER_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_LARGE_MAX_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, BREAK_POINT, DRAWER_DETAIL_DIMENSION, };
@@ -6,4 +6,10 @@ const DRAWER_SMALL_MIN_WIDTH = 'calc(100vw - 310px)';
6
6
  const BREAK_POINT = '1440px';
7
7
  const LAYER_2_MIN_WIDTH = '740px';
8
8
  const LAYER_2_MAX_WIDTH = 'calc(100vw - 46px)';
9
- export { DRAWER_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_LARGE_MAX_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, BREAK_POINT, LAYER_2_MAX_WIDTH, LAYER_2_MIN_WIDTH, };
9
+ const DRAWER_DETAIL_DIMENSION = {
10
+ LAYER_2: {
11
+ minWidth: LAYER_2_MIN_WIDTH,
12
+ maxWidth: LAYER_2_MAX_WIDTH,
13
+ },
14
+ };
15
+ export { DRAWER_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_LARGE_MAX_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, BREAK_POINT, DRAWER_DETAIL_DIMENSION, };
@@ -1,3 +1,3 @@
1
1
  export { DrawerDetail } from './DrawerDetail';
2
- export { LAYER_2_MAX_WIDTH, LAYER_2_MIN_WIDTH } from './constants';
2
+ export { DRAWER_DETAIL_DIMENSION } from './constants';
3
3
  export type * from './types';
@@ -1,3 +1,3 @@
1
1
  export { DrawerDetail } from './DrawerDetail';
2
2
  // Constants
3
- export { LAYER_2_MAX_WIDTH, LAYER_2_MIN_WIDTH } from './constants';
3
+ export { DRAWER_DETAIL_DIMENSION } from './constants';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.222",
3
+ "version": "1.3.5-beta.224",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",