@antscorp/antsomi-ui 1.3.5-beta.564 → 1.3.5-beta.565
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.
|
@@ -31,11 +31,12 @@ import dayjs from 'dayjs';
|
|
|
31
31
|
import html2canvas from 'html2canvas';
|
|
32
32
|
import { useLocation, useParams } from 'react-router-dom';
|
|
33
33
|
// Styled
|
|
34
|
-
import { ChildrenWrapper, ContentWrapper, LayoutWrapper, NotificationWrapper } from './styled';
|
|
34
|
+
import { ChildrenWrapper, ContentWrapper, LayoutLoading, LayoutWrapper, NotificationWrapper, } from './styled';
|
|
35
35
|
// Components
|
|
36
36
|
import { LeftMenu } from '../../organism';
|
|
37
37
|
import { Flex } from '../../atoms';
|
|
38
38
|
import { HeaderV2, AccessDenied } from '../../molecules';
|
|
39
|
+
import { RecommendationWorkspace } from './components';
|
|
39
40
|
// Contexts
|
|
40
41
|
import { AppConfigContext } from '../../..';
|
|
41
42
|
// Constants
|
|
@@ -48,7 +49,6 @@ import { useLayoutStore } from './stores';
|
|
|
48
49
|
import { hasSelectAccountPermission } from './utils';
|
|
49
50
|
import { useCustomRouter, useDeepCompareEffect, useDeepCompareMemo, useMutationObserver, } from '@antscorp/antsomi-ui/es/hooks';
|
|
50
51
|
import { HOME_MENU_ITEMS } from '../../organism/LeftMenu/constants';
|
|
51
|
-
import { RecommendationWorkspace } from './components';
|
|
52
52
|
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
53
53
|
const { DATAFLOWS, APP_ANTALYSER } = APP_CODES;
|
|
54
54
|
export const Layout = memo(props => {
|
|
@@ -67,16 +67,20 @@ export const Layout = memo(props => {
|
|
|
67
67
|
const params = useParams();
|
|
68
68
|
const location = useLocation();
|
|
69
69
|
const { navigate, replace } = useCustomRouter();
|
|
70
|
-
const [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const [state, setState] = useState({
|
|
71
|
+
showAccountSelection: false,
|
|
72
|
+
noSpaceTopContent: false,
|
|
73
|
+
activeMenu: null,
|
|
74
|
+
activePageTitle: '',
|
|
75
|
+
isAccessDenied: false,
|
|
76
|
+
isLoadingLayout: true,
|
|
77
|
+
});
|
|
78
|
+
const { showAccountSelection, noSpaceTopContent, activeMenu, activePageTitle, isAccessDenied, isLoadingLayout, } = state;
|
|
75
79
|
const notificationWrapperRef = useRef(null);
|
|
76
80
|
useMutationObserver(() => {
|
|
77
81
|
if (notificationWrapperRef.current) {
|
|
78
82
|
const child = notificationWrapperRef.current.querySelector('div');
|
|
79
|
-
|
|
83
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { noSpaceTopContent: !!child })));
|
|
80
84
|
}
|
|
81
85
|
}, notificationWrapperRef, {
|
|
82
86
|
attributes: true,
|
|
@@ -144,13 +148,14 @@ export const Layout = memo(props => {
|
|
|
144
148
|
const leftMenuAppConfig = useDeepCompareMemo(() => omit(Object.assign(Object.assign({}, appConfig), { permissionDomain }), ['setAppConfig']), [appConfig]);
|
|
145
149
|
const antsProcessingNotificationConfig = useMemo(() => (Object.assign({ permissionDomain, socketDomain: SOCKET_API, token, accountId: userId, userId, lang: languageCode, networkId: portalId }, processingNotificationProps)), [permissionDomain, token, userId, languageCode, portalId, processingNotificationProps]);
|
|
146
150
|
const onActiveMenuCodeChange = useCallback((activeItemPath, flattenPermissionList, menuListPermission) => {
|
|
147
|
-
var _a;
|
|
148
151
|
const activeMenuItem = activeItemPath === null || activeItemPath === void 0 ? void 0 : activeItemPath[(activeItemPath === null || activeItemPath === void 0 ? void 0 : activeItemPath.length) - 1];
|
|
149
152
|
const { menu_item_code, page_title, menu_item_name, permission_code } = activeMenuItem || {};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
:
|
|
153
|
-
|
|
153
|
+
setState(prev => {
|
|
154
|
+
var _a;
|
|
155
|
+
return (Object.assign(Object.assign({}, prev), { activePageTitle: page_title
|
|
156
|
+
? i18nInstance.t((_a = translations.leftMenu.pageTitle) === null || _a === void 0 ? void 0 : _a[`${page_title}`]).toString()
|
|
157
|
+
: menu_item_name, activeMenu: activeMenuItem }));
|
|
158
|
+
});
|
|
154
159
|
onActiveMenuChange === null || onActiveMenuChange === void 0 ? void 0 : onActiveMenuChange(menu_item_code);
|
|
155
160
|
const hasRole = hasSelectAccountPermission({
|
|
156
161
|
activeItemPath: cloneDeep(activeItemPath),
|
|
@@ -158,11 +163,14 @@ export const Layout = memo(props => {
|
|
|
158
163
|
menuListPermission,
|
|
159
164
|
appItem: activeItemPath[0],
|
|
160
165
|
});
|
|
161
|
-
|
|
166
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { showAccountSelection: hasRole })));
|
|
162
167
|
// Check if the user has permission or not (access denied)
|
|
163
|
-
if (!!permission_code &&
|
|
168
|
+
if (!!permission_code &&
|
|
169
|
+
!!activeMenuItem &&
|
|
170
|
+
Array.isArray(flattenPermissionList) &&
|
|
171
|
+
flattenPermissionList.length) {
|
|
164
172
|
const isAccessDenied = !flattenPermissionList.some(item => item.menu_code === activeMenuItem.permission_code);
|
|
165
|
-
|
|
173
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { isAccessDenied, isLoadingLayout: false })));
|
|
166
174
|
}
|
|
167
175
|
}, [onActiveMenuChange]);
|
|
168
176
|
// Effects
|
|
@@ -262,7 +270,7 @@ export const Layout = memo(props => {
|
|
|
262
270
|
// If user has access denied, disable expandable
|
|
263
271
|
isExpandable: !isAccessDenied && ((_a = mergeLeftMenuProps.customization) === null || _a === void 0 ? void 0 : _a.isExpandable) }), appConfig: leftMenuAppConfig, onActiveMenuCodeChange: onActiveMenuCodeChange }))),
|
|
264
272
|
React.createElement(ContentWrapper, Object.assign({ "$noPadding": noPadding, "$noSpaceTopContent": noSpaceTopContent }, mergeContentWrapperProps), (activeMenu === null || activeMenu === void 0 ? void 0 : activeMenu.menu_item_code) === HOME_MENU_ITEMS.RECOMMENDATION.menu_item_code ? (React.createElement("div", { className: "layout-body__content" },
|
|
265
|
-
React.createElement(RecommendationWorkspace, null))) : (React.createElement("div", Object.assign({ className: `layout-body__content ${(workspaceProps === null || workspaceProps === void 0 ? void 0 : workspaceProps.className) || ''}` }, mergeWorkSpaceProps),
|
|
273
|
+
React.createElement(RecommendationWorkspace, null))) : (React.createElement("div", Object.assign({ className: `layout-body__content ${(workspaceProps === null || workspaceProps === void 0 ? void 0 : workspaceProps.className) || ''}` }, mergeWorkSpaceProps), isLoadingLayout ? (React.createElement(LayoutLoading, { spinning: true })) : (React.createElement(React.Fragment, null,
|
|
266
274
|
React.createElement(NotificationWrapper, { className: "process-notification", ref: notificationWrapperRef }, showNotification && (React.createElement(AntsProcessingNotification, Object.assign({}, antsProcessingNotificationConfig, { callback: handleCallbackNotify })))),
|
|
267
|
-
React.createElement(ChildrenWrapper, Object.assign({}, workspaceContentProps), isAccessDenied ? (React.createElement(AccessDenied, { onClickRequestAccess: onClickRequestAccess, onClickSwitchAccount: onClickSwitchAccount })) : (React.createElement("div", null, children)))))))));
|
|
275
|
+
React.createElement(ChildrenWrapper, Object.assign({}, workspaceContentProps), isAccessDenied ? (React.createElement(AccessDenied, { onClickRequestAccess: onClickRequestAccess, onClickSwitchAccount: onClickSwitchAccount })) : (React.createElement("div", null, children)))))))))));
|
|
268
276
|
}, (prevProps, nextProps) => isEqual(prevProps, nextProps));
|
|
@@ -8,3 +8,7 @@ export declare const ContentWrapper: import("styled-components").StyledComponent
|
|
|
8
8
|
}, never>;
|
|
9
9
|
export declare const NotificationWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
10
10
|
export declare const ChildrenWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
11
|
+
export declare const LayoutLoading: import("styled-components").StyledComponent<{
|
|
12
|
+
(props: import("../../atoms/Spin/Spin").TSpinProps): import("react").JSX.Element;
|
|
13
|
+
defaultProps: {};
|
|
14
|
+
}, any, {}, never>;
|
|
@@ -2,7 +2,7 @@ var _a, _b;
|
|
|
2
2
|
// Libraries
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
// Components
|
|
5
|
-
import { Flex } from '../../atoms';
|
|
5
|
+
import { Flex, Spin } from '../../atoms';
|
|
6
6
|
// Constants
|
|
7
7
|
import { HEADER_HEIGHT } from '../../molecules/HeaderV2/constants';
|
|
8
8
|
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
@@ -85,3 +85,6 @@ export const ChildrenWrapper = styled.div `
|
|
|
85
85
|
}
|
|
86
86
|
/* height: calc(100% - 50px); */
|
|
87
87
|
`;
|
|
88
|
+
export const LayoutLoading = styled(Spin) `
|
|
89
|
+
margin: auto !important;
|
|
90
|
+
`;
|