mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-27 11:02:16 +01:00
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { adminGroups } from 'component/admin/adminRoutes';
|
|
import { useRoutes } from 'component/layout/MainLayout/NavigationSidebar/useRoutes';
|
|
import type { INavigationMenuItem } from 'interfaces/route';
|
|
import { useMemo } from 'react';
|
|
|
|
interface IPageRouteInfo {
|
|
path: string;
|
|
route: string;
|
|
title: string;
|
|
searchText: string;
|
|
}
|
|
|
|
export const useCommandBarRoutes = () => {
|
|
const { routes } = useRoutes();
|
|
const getSearchText = (route: INavigationMenuItem, title: string) => {
|
|
if (route.group && adminGroups[route.group]) {
|
|
return `${title} ${route.path} ${route.group} ${adminGroups[route.group]}`;
|
|
}
|
|
|
|
return `${title} ${route.path}`;
|
|
};
|
|
|
|
const getRouteTitle = (route: INavigationMenuItem) => {
|
|
if (route.path === '/admin') {
|
|
return 'Admin settings';
|
|
}
|
|
|
|
return route.title;
|
|
};
|
|
return useMemo(() => {
|
|
const allRoutes: Record<string, IPageRouteInfo> = {};
|
|
for (const route of [
|
|
...routes.mainNavRoutes,
|
|
...routes.adminRoutes,
|
|
...routes.primaryRoutes,
|
|
]) {
|
|
const title = getRouteTitle(route);
|
|
allRoutes[route.path] = {
|
|
path: route.path,
|
|
route: route.route,
|
|
title: title,
|
|
searchText: getSearchText(route, title),
|
|
};
|
|
}
|
|
|
|
return {
|
|
allRoutes,
|
|
};
|
|
}, [routes]);
|
|
};
|