@antscorp/antsomi-ui 1.3.5-beta.332 → 1.3.5-beta.334

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,2 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  export declare const Switch: import("react").ForwardRefExoticComponent<import("antd").SwitchProps & import("react").RefAttributes<HTMLElement>>;
3
+ export type { SwitchProps } from 'antd';
@@ -1,2 +1,3 @@
1
1
  import { Switch as AntdSwitch } from 'antd';
2
2
  export const Switch = AntdSwitch;
3
+ Switch.defaultProps = {};
@@ -1 +1,2 @@
1
1
  export { Switch } from './Switch';
2
+ export type { SwitchProps } from 'antd';
@@ -24,7 +24,6 @@ export { Icon } from './Icon';
24
24
  export { Text } from './Text';
25
25
  export { Popover } from './Popover';
26
26
  export { RequiredLabel } from './RequiredLabel';
27
- export { Switch } from './Switch';
28
27
  export { Slider } from './Slider';
29
28
  export { Spin } from './Spin';
30
29
  export { Alert } from './Alert';
@@ -41,6 +40,7 @@ export * from './MobileFrameV2';
41
40
  export * from './SlideBar';
42
41
  export * from './ReactIframe';
43
42
  export * from './Scrollbars';
43
+ export * from './Switch';
44
44
  export type { SliderProps } from './Slider';
45
45
  export type { PaginationProps } from './Pagination';
46
46
  export type { InputDynamicProps } from './InputDynamic';
@@ -24,7 +24,6 @@ export { Icon } from './Icon';
24
24
  export { Text } from './Text';
25
25
  export { Popover } from './Popover';
26
26
  export { RequiredLabel } from './RequiredLabel';
27
- export { Switch } from './Switch';
28
27
  export { Slider } from './Slider';
29
28
  export { Spin } from './Spin';
30
29
  export { Alert } from './Alert';
@@ -41,3 +40,4 @@ export * from './MobileFrameV2';
41
40
  export * from './SlideBar';
42
41
  export * from './ReactIframe';
43
42
  export * from './Scrollbars';
43
+ export * from './Switch';
@@ -9,6 +9,8 @@ interface EditableNameProps {
9
9
  required?: boolean;
10
10
  error?: string;
11
11
  value?: string;
12
+ style?: React.CSSProperties;
13
+ readonly?: boolean;
12
14
  onBlur?: React.FocusEventHandler<HTMLInputElement>;
13
15
  onChange?: (value: string) => void;
14
16
  }
@@ -6,7 +6,7 @@ import Icon from '@antscorp/icons';
6
6
  import { Spin } from '../../atoms';
7
7
  export const EditableName = React.forwardRef((props, ref) => {
8
8
  var _a;
9
- const { className, isLoading, defaultValue, required, error, value, onBlur, onChange } = props;
9
+ const { className, isLoading, defaultValue, required, error, value, style, readonly, onBlur, onChange, } = props;
10
10
  const [inputWidth, setInputWidth] = useState(1);
11
11
  const [internalValue, setInternalValue] = useState(value || defaultValue || '');
12
12
  const requiredError = useMemo(() => {
@@ -36,9 +36,9 @@ export const EditableName = React.forwardRef((props, ref) => {
36
36
  // NOTE: the defaultValue props should need use only one time and don't change in component life circle
37
37
  // eslint-disable-next-line react-hooks/exhaustive-deps
38
38
  }, [value]);
39
- return (React.createElement(InputWrapperStyled, { className: className || '' },
39
+ return (React.createElement(InputWrapperStyled, { className: className || '', style: style },
40
40
  React.createElement(Tooltip, { title: value || internalValue },
41
- React.createElement(Input, { ref: inputRef, style: { width: inputWidth + 2 }, defaultValue: defaultValue, value: value, onChange: event => {
41
+ React.createElement(Input, { readOnly: readonly, ref: inputRef, style: { width: inputWidth + 2 }, defaultValue: defaultValue, value: value, onChange: event => {
42
42
  var _a;
43
43
  const newValue = event.target.value;
44
44
  if (spanRef.current)
@@ -50,7 +50,7 @@ export const EditableName = React.forwardRef((props, ref) => {
50
50
  isLoading ? (React.createElement(Spin, { indicatorSize: 20, style: { paddingLeft: '5px', marginLeft: '10px' } })) : null,
51
51
  (error || requiredError) && !isLoading ? (React.createElement("div", { className: "suffix-icon-error" },
52
52
  React.createElement(Tooltip, { title: error || requiredError },
53
- React.createElement(Icon, { type: "icon-ants-warning-circle", style: { color: '#F44336', fontSize: '19.2px' } })))) : (React.createElement("div", { className: "suffix-icon" },
53
+ React.createElement(Icon, { type: "icon-ants-warning-circle", style: { color: '#F44336', fontSize: '19.2px' } })))) : readonly ? null : (React.createElement("div", { className: "suffix-icon" },
54
54
  React.createElement(Icon, { type: "icon-ants-pencil", style: { color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.blue7, fontSize: '24px' } }))),
55
55
  React.createElement("span", { ref: spanRef, className: "hidden-span" })));
56
56
  });
@@ -15,6 +15,9 @@ export const InputWrapperStyled = styled.div `
15
15
  &:has(input:focus) {
16
16
  border-bottom: 1px solid ${(_a = THEME.token) === null || _a === void 0 ? void 0 : _a.blue1};
17
17
  }
18
+ &:has(input[readonly]:focus) {
19
+ border-bottom: none;
20
+ }
18
21
 
19
22
  input {
20
23
  font-size: 20px !important;
@@ -30,7 +30,7 @@ export const HeaderV2 = memo(props => {
30
30
  const { auth, env: envContext, languageCode = 'en', appCode: contextAppCode, urlLogout: urlLogoutProvider = '', menuCode: contextMenuCode, } = useContextSelector(AppConfigContext, state => state);
31
31
  const { search } = useLocation();
32
32
  // const history = useHistory();
33
- const { navigate } = useCustomRouter();
33
+ const { replace } = useCustomRouter();
34
34
  // * Prefer to use Header in AppConfigContext
35
35
  const { className, style, breadcrumbs, pageTitle = '', accountSelection = {}, helpConfig, notificationConfig = {}, accountSharingConfig, useURLParam, config, } = props;
36
36
  /** General config for children component */
@@ -91,13 +91,13 @@ export const HeaderV2 = memo(props => {
91
91
  setSelectedAccount(userId);
92
92
  if (useURLParam) {
93
93
  if (userId === 'all') {
94
- urlParams.set('oid', userId);
94
+ urlParams.delete('oid');
95
95
  }
96
96
  else {
97
- urlParams.delete('oid');
97
+ urlParams.set('oid', userId);
98
98
  }
99
99
  // history.replace({ search: urlParams.toString() });
100
- navigate({ search: urlParams.toString() });
100
+ replace({ search: urlParams.toString() });
101
101
  }
102
102
  onSelectAccount === null || onSelectAccount === void 0 ? void 0 : onSelectAccount(userId);
103
103
  };
@@ -1,2 +1,3 @@
1
1
  export { useLeftMenu } from './useLeftMenu';
2
2
  export { useNavigatePath } from './useNavigatePath';
3
+ export { usePermission } from './usePermission';
@@ -1,2 +1,3 @@
1
1
  export { useLeftMenu } from './useLeftMenu';
2
2
  export { useNavigatePath } from './useNavigatePath';
3
+ export { usePermission } from './usePermission';
@@ -1,16 +1,14 @@
1
1
  // Libraries
2
- import { useCallback, useEffect, useMemo, useState } from 'react';
3
- import { isArray, sortBy } from 'lodash';
4
- // Queries
5
- import { useGetDashboard, useGetDestinationChannel, useGetListMenu, useGetListMenuPermission, } from '@antscorp/antsomi-ui/es/queries/LeftMenu';
2
+ import { useCallback, useEffect, useState } from 'react';
3
+ import { isArray } from 'lodash';
6
4
  // Utils
7
- import { findActiveAppCodeByChild, findActiveAppCodeByUrl, findLastMatchedItemByUrl, findPathOfActiveItem, flattenMenuArray, getMappingAppChildren, recursivePermissionMenu, } from '../utils';
5
+ import { findActiveAppCodeByChild, findActiveAppCodeByUrl } from '../utils';
8
6
  // Store
9
7
  import { useLeftMenuStore } from '../stores';
10
- import { POST_MESSAGE_TYPES } from '@antscorp/antsomi-ui/es/constants/postMessage';
11
8
  // Constants
12
- import { CDP_API, PERMISSION_API } from '@antscorp/antsomi-ui/es/constants';
13
9
  import { DASHBOARD_MODULE_CONFIG } from '../../../template/Layout/constants';
10
+ // Hooks
11
+ import { usePermission } from './usePermission';
14
12
  const initialState = {
15
13
  hoverItem: '',
16
14
  isExpandMenu: true,
@@ -23,96 +21,9 @@ export const useLeftMenu = (props) => {
23
21
  const activeAppCode = useLeftMenuStore(store => store.state.activeAppCode);
24
22
  const customActiveAppKey = useLeftMenuStore(store => store.state.customActiveAppKey);
25
23
  const setLeftMenuState = useLeftMenuStore(store => store.setState);
26
- const { auth, languageCode = 'en', env = 'development' } = appConfig || {};
24
+ const { auth } = appConfig || {};
27
25
  const [state, setState] = useState(initialState);
28
- const { data: menuList } = useGetListMenu({
29
- args: {
30
- auth: {
31
- token: '5474r2x214r2b4b4v2d4y444u2v5q2p5o4d4c4f424e4' || (auth === null || auth === void 0 ? void 0 : auth.token),
32
- url: 'https://sandbox-permission.ants.vn',
33
- portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
34
- userId: auth === null || auth === void 0 ? void 0 : auth.userId,
35
- accountId: auth === null || auth === void 0 ? void 0 : auth.accountId,
36
- },
37
- params: {
38
- type: 'menu-item-permission',
39
- },
40
- },
41
- });
42
- const { data: menuListPermission } = useGetListMenuPermission({
43
- args: {
44
- auth: {
45
- token: auth === null || auth === void 0 ? void 0 : auth.token,
46
- url: PERMISSION_API,
47
- userId: auth === null || auth === void 0 ? void 0 : auth.userId,
48
- accountId: auth === null || auth === void 0 ? void 0 : auth.userId,
49
- },
50
- params: {
51
- type: 'list-app',
52
- from: 'side',
53
- hasChild: true,
54
- languageCode,
55
- },
56
- },
57
- });
58
- const { data: dashboardData, refetch: refetchDashboard } = useGetDashboard({
59
- args: {
60
- auth: {
61
- token: auth === null || auth === void 0 ? void 0 : auth.token,
62
- url: `${CDP_API === null || CDP_API === void 0 ? void 0 : CDP_API[env]}/hub`,
63
- portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
64
- userId: auth === null || auth === void 0 ? void 0 : auth.userId,
65
- },
66
- params: {
67
- objectType,
68
- objectId,
69
- isGrouped,
70
- languageCode,
71
- },
72
- },
73
- });
74
- const { data: destinationChannel } = useGetDestinationChannel({
75
- args: {
76
- auth: {
77
- token: auth === null || auth === void 0 ? void 0 : auth.token,
78
- url: env ? `${CDP_API[env]}/hub` : '',
79
- userId: auth === null || auth === void 0 ? void 0 : auth.userId,
80
- portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
81
- },
82
- params: {
83
- objectType: 'DESTINATIONS',
84
- languageCode,
85
- },
86
- },
87
- });
88
- const flattenMenuPermission = flattenMenuArray(menuListPermission || [], 'childs');
89
- const permissionMenu = useMemo(() => recursivePermissionMenu(sortBy((menuList === null || menuList === void 0 ? void 0 : menuList.rows) || [], ['level_position']), flattenMenuPermission), [menuList === null || menuList === void 0 ? void 0 : menuList.rows, flattenMenuPermission]);
90
- const mappingChildrenMenu = useMemo(() => getMappingAppChildren({
91
- menuList: permissionMenu,
92
- auth,
93
- dashboardData,
94
- destinationChannelEntries: destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries,
95
- }), [auth, dashboardData, destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries, permissionMenu]);
96
- const receivePostMessage = (event) => {
97
- const { data } = event;
98
- const { type } = data || {};
99
- switch (type) {
100
- case POST_MESSAGE_TYPES.REFETCH_DASHBOARD_LIST: {
101
- refetchDashboard();
102
- break;
103
- }
104
- default:
105
- break;
106
- }
107
- };
108
- // Receive Post Message
109
- useEffect(() => {
110
- if (!isCustomized) {
111
- window.addEventListener('message', receivePostMessage);
112
- return () => window.removeEventListener('message', receivePostMessage);
113
- }
114
- // eslint-disable-next-line react-hooks/exhaustive-deps
115
- }, []);
26
+ const { mappingChildrenMenu, flattenMenuPermission, permissionMenu, activeItemPath } = usePermission();
116
27
  useEffect(() => {
117
28
  setLeftMenuState({
118
29
  appConfig,
@@ -171,30 +82,10 @@ export const useLeftMenu = (props) => {
171
82
  }, [activeAppCode, auth, hash, isCustomized, mappingChildrenMenu, pathname, setLeftMenuState]);
172
83
  useEffect(() => {
173
84
  if (!isCustomized) {
174
- const url = `${pathname}${hash}`;
175
85
  // Callback function using at Layout when url change
176
- const matchedCode = findLastMatchedItemByUrl({
177
- url,
178
- menuItems: mappingChildrenMenu,
179
- auth,
180
- });
181
- const activeItemPath = matchedCode
182
- ? findPathOfActiveItem({
183
- activeMenuItem: matchedCode,
184
- menuItems: mappingChildrenMenu,
185
- })
186
- : [];
187
86
  onActiveMenuCodeChange === null || onActiveMenuCodeChange === void 0 ? void 0 : onActiveMenuCodeChange(activeItemPath, flattenMenuPermission);
188
87
  }
189
- }, [
190
- auth,
191
- flattenMenuPermission,
192
- hash,
193
- isCustomized,
194
- mappingChildrenMenu,
195
- pathname,
196
- onActiveMenuCodeChange,
197
- ]);
88
+ }, [activeItemPath, flattenMenuPermission, isCustomized, onActiveMenuCodeChange]);
198
89
  const onToggleChildMenu = useCallback(() => {
199
90
  setState(prev => (Object.assign(Object.assign({}, prev), { isExpandMenu: !prev.isExpandMenu })));
200
91
  }, []);
@@ -1,21 +1,26 @@
1
1
  // Libraries
2
2
  import { useContextSelector } from 'use-context-selector';
3
- import { useCallback } from 'react';
3
+ import { useCallback, useMemo } from 'react';
4
4
  import { isNil } from 'lodash';
5
+ import { useLocation } from 'react-router-dom';
5
6
  // Contexts
6
7
  import { AppConfigContext } from '@antscorp/antsomi-ui/es/providers';
7
8
  // Utils
8
9
  import { getGeneratePath } from '../utils';
10
+ import { hasSelectAccountPermission } from '../../../template/Layout/utils';
9
11
  // Constants
10
12
  import { ENV } from '@antscorp/antsomi-ui/es/config';
11
- import { useLocation } from 'react-router-dom';
13
+ // Hooks
14
+ import { usePermission } from './usePermission';
12
15
  export const useNavigatePath = () => {
13
- // Contexts
14
16
  const { auth, env } = useContextSelector(AppConfigContext, state => state);
15
17
  const { search } = useLocation();
16
- const searchParams = search === '?' || !search ? '' : search;
17
18
  const isDev = env === ENV.DEV;
18
- // Callbacks
19
+ const { activeItemPath, flattenMenuPermission } = usePermission();
20
+ const hasRole = useMemo(() => hasSelectAccountPermission(activeItemPath, flattenMenuPermission), [activeItemPath, flattenMenuPermission]);
21
+ const urlParams = useMemo(() => new URLSearchParams(search), [search]);
22
+ const oidParam = hasRole ? urlParams.get('oid') : null;
23
+ const searchParams = oidParam ? `?oid=${oidParam}` : '';
19
24
  const isPushDifferentDomain = useCallback((domain, path) => {
20
25
  var _a, _b, _c, _d, _e, _f;
21
26
  if (isDev)
@@ -0,0 +1,6 @@
1
+ export declare const usePermission: () => {
2
+ mappingChildrenMenu: import("@antscorp/antsomi-ui/es/models/LeftMenu").TFeatureMenu[];
3
+ permissionMenu: import("@antscorp/antsomi-ui/es/models/LeftMenu").TFeatureMenu[];
4
+ activeItemPath: import("@antscorp/antsomi-ui/es/models/LeftMenu").TFeatureMenu[];
5
+ flattenMenuPermission: import("@antscorp/antsomi-ui/es/models/LeftMenu").FeatureMenuPermission[];
6
+ };
@@ -0,0 +1,120 @@
1
+ // Libraries
2
+ import { useEffect, useMemo } from 'react';
3
+ import { sortBy } from 'lodash';
4
+ // Queries
5
+ import { useGetDashboard, useGetDestinationChannel, useGetListMenu, useGetListMenuPermission, } from '@antscorp/antsomi-ui/es/queries/LeftMenu';
6
+ // Stores
7
+ import { useLeftMenuStore } from '../stores';
8
+ // Constants
9
+ import { CDP_API, PERMISSION_API, POST_MESSAGE_TYPES } from '@antscorp/antsomi-ui/es/constants';
10
+ // Utils
11
+ import { findLastMatchedItemByUrl, findPathOfActiveItem, flattenMenuArray, getMappingAppChildren, recursivePermissionMenu, } from '../utils';
12
+ export const usePermission = () => {
13
+ const appConfig = useLeftMenuStore(store => store.state.appConfig);
14
+ const isCustomized = useLeftMenuStore(store => store.state.isCustomized);
15
+ const { isGrouped, objectId, objectType } = useLeftMenuStore(store => store.state.dashboardParams);
16
+ const { auth, languageCode = 'en', env = 'development' } = appConfig || {};
17
+ const { pathname, hash } = window.location;
18
+ const { data: menuList } = useGetListMenu({
19
+ args: {
20
+ auth: {
21
+ token: '5474r2x214r2b4b4v2d4y444u2v5q2p5o4d4c4f424e4' || (auth === null || auth === void 0 ? void 0 : auth.token),
22
+ url: 'https://sandbox-permission.ants.vn',
23
+ portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
24
+ userId: auth === null || auth === void 0 ? void 0 : auth.userId,
25
+ accountId: auth === null || auth === void 0 ? void 0 : auth.accountId,
26
+ },
27
+ params: {
28
+ type: 'menu-item-permission',
29
+ },
30
+ },
31
+ });
32
+ const { data: dashboardData, refetch: refetchDashboard } = useGetDashboard({
33
+ args: {
34
+ auth: {
35
+ token: auth === null || auth === void 0 ? void 0 : auth.token,
36
+ url: `${CDP_API === null || CDP_API === void 0 ? void 0 : CDP_API[env]}/hub`,
37
+ portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
38
+ userId: auth === null || auth === void 0 ? void 0 : auth.userId,
39
+ },
40
+ params: {
41
+ objectType,
42
+ objectId,
43
+ isGrouped,
44
+ languageCode,
45
+ },
46
+ },
47
+ });
48
+ const { data: destinationChannel } = useGetDestinationChannel({
49
+ args: {
50
+ auth: {
51
+ token: auth === null || auth === void 0 ? void 0 : auth.token,
52
+ url: env ? `${CDP_API[env]}/hub` : '',
53
+ userId: auth === null || auth === void 0 ? void 0 : auth.userId,
54
+ portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
55
+ },
56
+ params: {
57
+ objectType: 'DESTINATIONS',
58
+ languageCode,
59
+ },
60
+ },
61
+ });
62
+ const { data: menuListPermission } = useGetListMenuPermission({
63
+ args: {
64
+ auth: {
65
+ token: auth === null || auth === void 0 ? void 0 : auth.token,
66
+ url: PERMISSION_API,
67
+ userId: auth === null || auth === void 0 ? void 0 : auth.userId,
68
+ accountId: auth === null || auth === void 0 ? void 0 : auth.userId,
69
+ },
70
+ params: {
71
+ type: 'list-app',
72
+ from: 'side',
73
+ hasChild: true,
74
+ languageCode,
75
+ },
76
+ },
77
+ });
78
+ const flattenMenuPermission = flattenMenuArray(menuListPermission || [], 'childs');
79
+ const permissionMenu = useMemo(() => recursivePermissionMenu(sortBy((menuList === null || menuList === void 0 ? void 0 : menuList.rows) || [], ['level_position']), flattenMenuPermission), [menuList === null || menuList === void 0 ? void 0 : menuList.rows, flattenMenuPermission]);
80
+ const mappingChildrenMenu = useMemo(() => getMappingAppChildren({
81
+ menuList: permissionMenu,
82
+ auth,
83
+ dashboardData,
84
+ destinationChannelEntries: destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries,
85
+ }), [auth, dashboardData, destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries, permissionMenu]);
86
+ const activeItemPath = useMemo(() => {
87
+ const url = `${pathname}${hash}`;
88
+ const matchedCode = findLastMatchedItemByUrl({
89
+ url,
90
+ menuItems: mappingChildrenMenu,
91
+ auth,
92
+ });
93
+ return matchedCode
94
+ ? findPathOfActiveItem({
95
+ activeMenuItem: matchedCode,
96
+ menuItems: mappingChildrenMenu,
97
+ })
98
+ : [];
99
+ }, [auth, hash, mappingChildrenMenu, pathname]);
100
+ useEffect(() => {
101
+ if (!isCustomized) {
102
+ const receivePostMessage = (event) => {
103
+ const { data } = event;
104
+ const { type } = data || {};
105
+ switch (type) {
106
+ case POST_MESSAGE_TYPES.REFETCH_DASHBOARD_LIST: {
107
+ refetchDashboard();
108
+ break;
109
+ }
110
+ default:
111
+ break;
112
+ }
113
+ };
114
+ window.addEventListener('message', receivePostMessage);
115
+ return () => window.removeEventListener('message', receivePostMessage);
116
+ }
117
+ // eslint-disable-next-line react-hooks/exhaustive-deps
118
+ }, []);
119
+ return { mappingChildrenMenu, permissionMenu, activeItemPath, flattenMenuPermission };
120
+ };
@@ -13,7 +13,7 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  import React, { memo, useCallback, useMemo, useState } from 'react';
14
14
  import { useContextSelector } from 'use-context-selector';
15
15
  import AntsProcessingNotification from '@antscorp/processing-notification';
16
- import { isEmpty, merge } from 'lodash';
16
+ import { merge } from 'lodash';
17
17
  // Styled
18
18
  import { ChildrenWrapper, ContentWrapper, LayoutWrapper, NotificationWrapper } from './styled';
19
19
  // Components
@@ -23,13 +23,12 @@ import { HeaderV2 } from '../../molecules';
23
23
  // Contexts
24
24
  import { AppConfigContext } from '../../..';
25
25
  // Constants
26
- import { APP_ROLE_SCOPE, MENU_PERMISSIONS } from './constants';
27
26
  import { APP_CODES, APP_IAM_DOMAIN, APP_PERMISSION_DOMAIN, IAM_API, PERMISSION_API, PORTALS_IDS, SOCKET_API, } from '../../../constants';
28
27
  // Css
29
28
  import '@antscorp/processing-notification/dist/index.css';
30
29
  import { useLayoutStore } from './stores';
31
30
  // Utils
32
- import { checkingRoleScope } from './utils';
31
+ import { hasSelectAccountPermission } from './utils';
33
32
  const { DATAFLOWS, APP_ANTALYSER } = APP_CODES;
34
33
  export const Layout = memo(props => {
35
34
  const { leftMenuProps, headerProps = {}, workspaceProps, processingNotificationProps, children, onActiveMenuChange, } = props;
@@ -89,51 +88,8 @@ export const Layout = memo(props => {
89
88
  const onActiveMenuCodeChange = useCallback((activeItemPath, flattenPermissionList) => {
90
89
  var _a;
91
90
  onActiveMenuChange === null || onActiveMenuChange === void 0 ? void 0 : onActiveMenuChange((_a = activeItemPath === null || activeItemPath === void 0 ? void 0 : activeItemPath[(activeItemPath === null || activeItemPath === void 0 ? void 0 : activeItemPath.length) - 1]) === null || _a === void 0 ? void 0 : _a.menu_item_code);
92
- if (isEmpty(activeItemPath)) {
93
- setShowAccountSelection(false);
94
- return;
95
- }
96
- let roleScope = false;
97
- for (const activeItem of activeItemPath) {
98
- let permissionCode;
99
- /** Dùng để check xem Permission Code có được lấy từ @constant MENU_PERMISSIONS hay không */
100
- let isExternalPermissionCode = false;
101
- /**
102
- * Kiểm tra nếu MENU_CODE có trong @constant MENU_PERMISSIONS thì lấy Permission từ constant
103
- * Không thì lấy từ api Permission
104
- * Nếu ở cả 2 nơi đều không có permission thì không hiện account selection
105
- */
106
- if (Object.keys(MENU_PERMISSIONS).includes(activeItem.menu_item_code)) {
107
- permissionCode = MENU_PERMISSIONS[activeItem.menu_item_code];
108
- isExternalPermissionCode = true;
109
- }
110
- else {
111
- permissionCode = activeItem.permission_code;
112
- }
113
- const menuPermission = flattenPermissionList === null || flattenPermissionList === void 0 ? void 0 : flattenPermissionList.find(item => permissionCode === item.menu_code);
114
- if (menuPermission) {
115
- const checkRoleScope = menuPermission
116
- ? checkingRoleScope({
117
- menuCode: menuPermission.menu_code || '',
118
- menuPermission,
119
- scope: APP_ROLE_SCOPE.EVERYTHING,
120
- })
121
- : false;
122
- if (checkRoleScope) {
123
- roleScope = true;
124
- break;
125
- }
126
- }
127
- /**
128
- * Nếu trong Api Permission không có những có trong @constant MENU_PERMISSIONS
129
- * thì vẫn trả về True vì có những MENU_CODE mà BA chưa define permission
130
- * */
131
- if (isExternalPermissionCode) {
132
- roleScope = true;
133
- break;
134
- }
135
- }
136
- setShowAccountSelection(roleScope);
91
+ const hasRole = hasSelectAccountPermission(activeItemPath, flattenPermissionList);
92
+ setShowAccountSelection(hasRole);
137
93
  }, [onActiveMenuChange]);
138
94
  return (React.createElement(LayoutWrapper, null,
139
95
  React.createElement(HeaderV2, Object.assign({}, mergeHeaderProps)),
@@ -1,4 +1,4 @@
1
- import { FeatureMenuPermission } from '@antscorp/antsomi-ui/es/models/LeftMenu';
1
+ import { FeatureMenuPermission, TFeatureMenu } from '@antscorp/antsomi-ui/es/models/LeftMenu';
2
2
  /**
3
3
  *
4
4
  * @param {*} menuCode MENU_CODE
@@ -14,3 +14,4 @@ export declare const checkingRoleScope: (args: {
14
14
  scope?: number;
15
15
  isExactly?: boolean;
16
16
  }) => boolean;
17
+ export declare const hasSelectAccountPermission: (activeItemPath: TFeatureMenu[], flattenPermissionList?: FeatureMenuPermission[]) => boolean;
@@ -1,4 +1,5 @@
1
- import { MENU_CODE, APP_ROLE_SCOPE } from '../constants';
1
+ import { MENU_CODE, APP_ROLE_SCOPE, MENU_PERMISSIONS } from '../constants';
2
+ import { isEmpty } from 'lodash';
2
3
  const EDIT_ROLE = new Set(['CREATE', 'UPDATE', 'DELETE']);
3
4
  /**
4
5
  *
@@ -46,3 +47,48 @@ export const checkingRoleScope = (args) => {
46
47
  }
47
48
  return isOK;
48
49
  };
50
+ export const hasSelectAccountPermission = (activeItemPath, flattenPermissionList) => {
51
+ if (isEmpty(activeItemPath))
52
+ return false;
53
+ let roleScope = false;
54
+ for (const activeItem of activeItemPath) {
55
+ let permissionCode;
56
+ /** Dùng để check xem Permission Code có được lấy từ @constant MENU_PERMISSIONS hay không */
57
+ let isExternalPermissionCode = false;
58
+ /**
59
+ * Kiểm tra nếu MENU_CODE có trong @constant MENU_PERMISSIONS thì lấy Permission từ constant
60
+ * Không thì lấy từ api Permission
61
+ * Nếu ở cả 2 nơi đều không có permission thì không hiện account selection
62
+ */
63
+ if (Object.keys(MENU_PERMISSIONS).includes(activeItem.menu_item_code)) {
64
+ permissionCode = MENU_PERMISSIONS[activeItem.menu_item_code];
65
+ isExternalPermissionCode = true;
66
+ }
67
+ else {
68
+ permissionCode = activeItem.permission_code;
69
+ }
70
+ const menuPermission = flattenPermissionList === null || flattenPermissionList === void 0 ? void 0 : flattenPermissionList.find(item => permissionCode === item.menu_code);
71
+ if (menuPermission) {
72
+ const checkRoleScope = menuPermission
73
+ ? checkingRoleScope({
74
+ menuCode: menuPermission.menu_code || '',
75
+ menuPermission,
76
+ scope: APP_ROLE_SCOPE.EVERYTHING,
77
+ })
78
+ : false;
79
+ if (checkRoleScope) {
80
+ roleScope = true;
81
+ break;
82
+ }
83
+ }
84
+ /**
85
+ * Nếu trong Api Permission không có những có trong @constant MENU_PERMISSIONS
86
+ * thì vẫn trả về True vì có những MENU_CODE mà BA chưa define permission
87
+ * */
88
+ if (isExternalPermissionCode) {
89
+ roleScope = true;
90
+ break;
91
+ }
92
+ }
93
+ return roleScope;
94
+ };
@@ -191,9 +191,10 @@ THEME.components = {
191
191
  Switch: {
192
192
  colorTextQuaternary: (_y = THEME.token) === null || _y === void 0 ? void 0 : _y.bw0,
193
193
  colorTextTertiary: (_z = THEME.token) === null || _z === void 0 ? void 0 : _z.bw0,
194
- handleSize: 12,
194
+ handleSize: 8,
195
195
  handleSizeSM: 7,
196
- trackMinWidth: 30,
196
+ trackMinWidth: 27,
197
+ trackHeight: 16,
197
198
  handleBg: (_0 = THEME.token) === null || _0 === void 0 ? void 0 : _0.colorPrimary,
198
199
  },
199
200
  Popover: {
@@ -856,6 +856,11 @@ export const GlobalStyle = () => {
856
856
  }
857
857
  }
858
858
  }
859
+
860
+ .antsomi-switch-inner {
861
+ padding-inline-start: 4px !important;
862
+ padding-inline-end: 18px !important;
863
+ }
859
864
  }
860
865
 
861
866
  /* Tabs */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.332",
3
+ "version": "1.3.5-beta.334",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",