Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 154db9c

Browse files
authored
Merge pull request #62 from nursoltan-s/issue-178
fix issue 178
2 parents 6eecd23 + 3ca002a commit 154db9c

File tree

9 files changed

+75
-11
lines changed

9 files changed

+75
-11
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ This app exports functions to be imported by other microapps.
6868
- `getAuthUserProfile` - returns a promise which resolves to the user profile object
6969
- `disableSidebarForRoute` - disable (remove) sidebar for some route
7070
- `enableSidebarForRoute` - enable sidebar for the route, which was previously disabled
71+
- `disableNavigationForRoute` - disable (remove) navigation for some route
72+
- `enableNavigationForRoute` - enable (remove) navigation for some route
7173

7274
#### How to export
7375

src/App.jsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ const App = () => {
1818
const apps = useMemo(() => _.flatMap(menu, "apps"), [menu]);
1919
// list of routes where we have to disabled sidebar
2020
const disabledRoutes = useSelector((state) => state.menu.disabledRoutes);
21+
// list of routes where we have to disabled navigations
22+
const disabledNavigations = useSelector(
23+
(state) => state.menu.disabledNavigations
24+
);
2125
// user profile information
2226
const auth = useSelector((state) => state.auth);
2327
// `true` is sidebar has to be disabled for the current route
2428
const isSideBarDisabled = useMatchSomeRoute(disabledRoutes);
29+
// `true` is navigation has to be disabled for the current route
30+
const isNavigationDisabled = useMatchSomeRoute(disabledNavigations);
2531
// Left sidebar collapse state
2632
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
27-
// hide switch tools and notification when user is onboarding
28-
const [hideSwitchTools, setHideSwitchTools] = useState(false);
2933
// Toggle left sidebar callback
3034
const toggleSidebar = useCallback(() => {
3135
setSidebarCollapsed(!sidebarCollapsed);
@@ -41,11 +45,6 @@ const App = () => {
4145

4246
// set/remove class for the whole page, to know if sidebar is present or no
4347
useEffect(() => {
44-
if (location.pathname.includes("/self-service")) {
45-
setHideSwitchTools(true);
46-
} else {
47-
setHideSwitchTools(false);
48-
}
4948
if (isSideBarDisabled) {
5049
document.body.classList.add("no-sidebar");
5150
} else {
@@ -55,7 +54,7 @@ const App = () => {
5554

5655
return (
5756
<>
58-
<NavBar hideSwitchTools={hideSwitchTools} />
57+
<NavBar hideSwitchTools={isNavigationDisabled} />
5958
{!isSideBarDisabled && (
6059
<div className="main-menu-wrapper">
6160
<Router>

src/actions/menu.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,28 @@ export default {
3939
type: ACTIONS.MENU.ENABLE_SIDEBAR_FOR_ROUTE,
4040
payload: route,
4141
}),
42+
43+
/**
44+
* Disable navigation for route.
45+
*
46+
* @param {String} route route path
47+
*
48+
* @returns {{ type: String, payload: any }} action object
49+
*/
50+
disableNavigationForRoute: (route) => ({
51+
type: ACTIONS.MENU.DISABLE_NAVIGATION_FOR_ROUTE,
52+
payload: route,
53+
}),
54+
55+
/**
56+
* Enable navigation for route.
57+
*
58+
* @param {String} route route path
59+
*
60+
* @returns {{ type: String, payload: any }} action object
61+
*/
62+
enableNavigationForRoute: (route) => ({
63+
type: ACTIONS.MENU.ENABLE_NAVIGATION_FOR_ROUTE,
64+
payload: route,
65+
}),
4266
};

src/components/NavBar/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Shows global top navigation bar with all apps menu, logo and user menu.
55
*/
6-
import React, {
6+
import React, {
77
useState,
88
useCallback,
99
Fragment,

src/constants/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ export const ACTIONS = {
1616
SET_APP_MENU: "SET_APP_MENU",
1717
DISABLE_SIDEBAR_FOR_ROUTE: "DISABLE_SIDEBAR_FOR_ROUTE",
1818
ENABLE_SIDEBAR_FOR_ROUTE: "ENABLE_SIDEBAR_FOR_ROUTE",
19+
DISABLE_NAVIGATION_FOR_ROUTE: "DISABLE_NAVIGATION_FOR_ROUTE",
20+
ENABLE_NAVIGATION_FOR_ROUTE: "ENABLE_NAVIGATION_FOR_ROUTE",
1921
},
2022
};

src/reducers/menu.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ACTIONS, APP_CATEGORIES } from "../constants";
1010
const initialState = {
1111
categories: APP_CATEGORIES, // Default Apps Menu structure.
1212
disabledRoutes: [],
13+
disabledNavigations: [],
1314
};
1415

1516
/**
@@ -132,6 +133,35 @@ const menuReducer = (state = initialState, action) => {
132133
};
133134
}
134135

136+
case ACTIONS.MENU.DISABLE_NAVIGATION_FOR_ROUTE: {
137+
// if route is already disabled, don't do anything
138+
if (state.disabledNavigations.indexOf(action.payload) > -1) {
139+
return state;
140+
}
141+
142+
return {
143+
...state,
144+
// add route to the disabled list
145+
disabledNavigations: [...state.disabledNavigations, action.payload],
146+
};
147+
}
148+
149+
case ACTIONS.MENU.ENABLE_NAVIGATION_FOR_ROUTE: {
150+
// if route is not disabled, don't do anything
151+
if (state.disabledNavigations.indexOf(action.payload) === -1) {
152+
return state;
153+
}
154+
155+
return {
156+
...state,
157+
// remove the route from the disabled list
158+
disabledNavigations: _.without(
159+
state.disabledNavigations,
160+
action.payload
161+
),
162+
};
163+
}
164+
135165
default:
136166
return state;
137167
}

src/services/auth.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,3 @@ export function authenticate(store) {
125125
}
126126
});
127127
}
128-

src/topcoder-micro-frontends-navbar-app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
getAuthUserProfile,
1919
setUserProfilePhoto,
2020
setNotificationPlatform,
21+
disableNavigationForRoute,
22+
enableNavigationForRoute,
2123
} from "./utils/exports";
2224

2325
import { login, businessLogin, logout } from "./utils";
@@ -47,5 +49,7 @@ export {
4749
disableSidebarForRoute,
4850
enableSidebarForRoute,
4951
setNotificationPlatform,
52+
disableNavigationForRoute,
53+
enableNavigationForRoute,
5054
PLATFORM,
5155
};

src/utils/exports.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ export const {
1616
disableSidebarForRoute,
1717
enableSidebarForRoute,
1818
setNotificationPlatform,
19-
setUserProfilePhoto
19+
setUserProfilePhoto,
20+
disableNavigationForRoute,
21+
enableNavigationForRoute,
2022
} = bindActionCreators(
2123
{
2224
setAppMenu: menuActions.setAppMenu,
2325
disableSidebarForRoute: menuActions.disableSidebarForRoute,
2426
enableSidebarForRoute: menuActions.enableSidebarForRoute,
2527
setNotificationPlatform: notificationActions.setNotificationPlatform,
2628
setUserProfilePhoto: authActions.setProfilePhoto,
29+
disableNavigationForRoute: menuActions.disableNavigationForRoute,
30+
enableNavigationForRoute: menuActions.enableNavigationForRoute,
2731
},
2832
store.dispatch
2933
);

0 commit comments

Comments
 (0)