@antscorp/antsomi-ui 1.3.5-beta.566 → 1.3.5-beta.567
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.
|
@@ -36,7 +36,6 @@ import { ChildrenWrapper, ContentWrapper, LayoutLoading, LayoutWrapper, Notifica
|
|
|
36
36
|
import { LeftMenu } from '../../organism';
|
|
37
37
|
import { Flex } from '../../atoms';
|
|
38
38
|
import { HeaderV2, AccessDenied } from '../../molecules';
|
|
39
|
-
import { RecommendationWorkspace } from './components';
|
|
40
39
|
// Contexts
|
|
41
40
|
import { AppConfigContext } from '../../..';
|
|
42
41
|
// Constants
|
|
@@ -49,6 +48,7 @@ import { useLayoutStore } from './stores';
|
|
|
49
48
|
import { hasSelectAccountPermission } from './utils';
|
|
50
49
|
import { useCustomRouter, useDeepCompareEffect, useDeepCompareMemo, useMutationObserver, } from '@antscorp/antsomi-ui/es/hooks';
|
|
51
50
|
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,20 +67,18 @@ 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
|
-
|
|
75
|
-
|
|
76
|
-
isLoadingLayout: true,
|
|
77
|
-
});
|
|
78
|
-
const { showAccountSelection, noSpaceTopContent, activeMenu, activePageTitle, isAccessDenied, isLoadingLayout, } = state;
|
|
70
|
+
const [showAccountSelection, setShowAccountSelection] = useState(false);
|
|
71
|
+
const [noSpaceTopContent, setNoSpaceTopContent] = useState(false);
|
|
72
|
+
const [activeMenu, setActiveMenu] = useState(null);
|
|
73
|
+
const [activePageTitle, setActivePageTitle] = useState('');
|
|
74
|
+
const [isAccessDenied, setIsAccessDenied] = useState(false);
|
|
75
|
+
const [isLoadingLayout, setLoadingLayout] = useState(true);
|
|
79
76
|
const notificationWrapperRef = useRef(null);
|
|
77
|
+
const timeoutLoadingLayout = useRef(null);
|
|
80
78
|
useMutationObserver(() => {
|
|
81
79
|
if (notificationWrapperRef.current) {
|
|
82
80
|
const child = notificationWrapperRef.current.querySelector('div');
|
|
83
|
-
|
|
81
|
+
setNoSpaceTopContent(!!child);
|
|
84
82
|
}
|
|
85
83
|
}, notificationWrapperRef, {
|
|
86
84
|
attributes: true,
|
|
@@ -148,14 +146,13 @@ export const Layout = memo(props => {
|
|
|
148
146
|
const leftMenuAppConfig = useDeepCompareMemo(() => omit(Object.assign(Object.assign({}, appConfig), { permissionDomain }), ['setAppConfig']), [appConfig]);
|
|
149
147
|
const antsProcessingNotificationConfig = useMemo(() => (Object.assign({ permissionDomain, socketDomain: SOCKET_API, token, accountId: userId, userId, lang: languageCode, networkId: portalId }, processingNotificationProps)), [permissionDomain, token, userId, languageCode, portalId, processingNotificationProps]);
|
|
150
148
|
const onActiveMenuCodeChange = useCallback((activeItemPath, flattenPermissionList, menuListPermission) => {
|
|
149
|
+
var _a;
|
|
151
150
|
const activeMenuItem = activeItemPath === null || activeItemPath === void 0 ? void 0 : activeItemPath[(activeItemPath === null || activeItemPath === void 0 ? void 0 : activeItemPath.length) - 1];
|
|
152
151
|
const { menu_item_code, page_title, menu_item_name, permission_code } = activeMenuItem || {};
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
: menu_item_name, activeMenu: activeMenuItem }));
|
|
158
|
-
});
|
|
152
|
+
setActivePageTitle(page_title
|
|
153
|
+
? i18nInstance.t((_a = translations.leftMenu.pageTitle) === null || _a === void 0 ? void 0 : _a[`${page_title}`]).toString()
|
|
154
|
+
: menu_item_name);
|
|
155
|
+
setActiveMenu(activeMenuItem);
|
|
159
156
|
onActiveMenuChange === null || onActiveMenuChange === void 0 ? void 0 : onActiveMenuChange(menu_item_code);
|
|
160
157
|
const hasRole = hasSelectAccountPermission({
|
|
161
158
|
activeItemPath: cloneDeep(activeItemPath),
|
|
@@ -163,16 +160,25 @@ export const Layout = memo(props => {
|
|
|
163
160
|
menuListPermission,
|
|
164
161
|
appItem: activeItemPath[0],
|
|
165
162
|
});
|
|
166
|
-
|
|
163
|
+
setShowAccountSelection(hasRole);
|
|
167
164
|
// Check if the user has permission or not (access denied)
|
|
168
165
|
if (!!permission_code &&
|
|
169
166
|
!!activeMenuItem &&
|
|
170
167
|
Array.isArray(flattenPermissionList) &&
|
|
171
|
-
flattenPermissionList.length) {
|
|
168
|
+
!!flattenPermissionList.length) {
|
|
172
169
|
const isAccessDenied = !flattenPermissionList.some(item => item.menu_code === activeMenuItem.permission_code);
|
|
173
|
-
|
|
170
|
+
setIsAccessDenied(isAccessDenied);
|
|
171
|
+
}
|
|
172
|
+
// Handle set loading layout
|
|
173
|
+
if (timeoutLoadingLayout) {
|
|
174
|
+
clearTimeout(timeoutLoadingLayout.current);
|
|
174
175
|
}
|
|
175
|
-
|
|
176
|
+
timeoutLoadingLayout.current = setTimeout(() => {
|
|
177
|
+
if (isLoadingLayout) {
|
|
178
|
+
setLoadingLayout(false);
|
|
179
|
+
}
|
|
180
|
+
}, 500);
|
|
181
|
+
}, [isLoadingLayout, onActiveMenuChange]);
|
|
176
182
|
// Effects
|
|
177
183
|
/** Handle replace current userId in params if current userId is not match */
|
|
178
184
|
useDeepCompareEffect(() => {
|