refactor: remove static routes and stop multiple token api call in sse
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Layers,
|
||||
Milestone,
|
||||
Package,
|
||||
@@ -26,11 +25,6 @@ export type MenuItem = {
|
||||
};
|
||||
|
||||
export const menuItems: MenuItem[] = [
|
||||
{
|
||||
title: 'Dashboard',
|
||||
path: ROUTES.DASHBOARD,
|
||||
icon: LayoutDashboard,
|
||||
},
|
||||
{
|
||||
title: 'Upload',
|
||||
path: ROUTES.UPLOAD,
|
||||
@@ -120,3 +114,36 @@ export function filterMenuItems(
|
||||
})
|
||||
.filter((item): item is MenuItem => item !== null);
|
||||
}
|
||||
|
||||
function findFirstMenuPath(items: MenuItem[]): string | undefined {
|
||||
for (const item of items) {
|
||||
if (item.path) return item.path;
|
||||
|
||||
const childPath = item.children
|
||||
? findFirstMenuPath(item.children)
|
||||
: undefined;
|
||||
if (childPath) return childPath;
|
||||
}
|
||||
}
|
||||
|
||||
export function getFirstAccessibleMenuPath(
|
||||
hasPermission: (permission?: string) => boolean,
|
||||
fallback = ROUTES.ACCESS,
|
||||
) {
|
||||
return findFirstMenuPath(filterMenuItems(menuItems, hasPermission)) ?? fallback;
|
||||
}
|
||||
|
||||
export function getFirstAccessiblePathForPermissions(
|
||||
grantedPermissions: string[],
|
||||
fallback = ROUTES.ACCESS,
|
||||
) {
|
||||
const normalizedPermissions = new Set(
|
||||
grantedPermissions.map((permission) => permission.toLowerCase()),
|
||||
);
|
||||
|
||||
return getFirstAccessibleMenuPath(
|
||||
(permission) =>
|
||||
!permission || normalizedPermissions.has(permission.toLowerCase()),
|
||||
fallback,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user