MCPcopy
hub / github.com/Dokploy/dokploy / findActiveNavItem

Function findActiveNavItem

apps/dokploy/components/layouts/side.tsx:515–538  ·  view source on GitHub ↗

* Finds the active nav item based on the current pathname * @returns the active nav item with `SingleNavItem` type or undefined if none is active

(
	navItems: NavItem[],
	pathname: string,
)

Source from the content-addressed store, hash-verified

513 * @returns the active nav item with `SingleNavItem` type or undefined if none is active
514 */
515function findActiveNavItem(
516 navItems: NavItem[],
517 pathname: string,
518): SingleNavItem | undefined {
519 const found = navItems.find((item) =>
520 item.isSingle !== false
521 ? // The current item is single, so check if the item url is active
522 isActiveRoute({ itemUrl: item.url, pathname })
523 : // The current item is not single, so check if any of the sub items are active
524 item.items.some((item) =>
525 isActiveRoute({ itemUrl: item.url, pathname }),
526 ),
527 );
528
529 if (found?.isSingle !== false) {
530 // The found item is single, so return it
531 return found;
532 }
533
534 // The found item is not single, so find the active sub item
535 return found?.items.find((item) =>
536 isActiveRoute({ itemUrl: item.url, pathname }),
537 );
538}
539
540interface Props {
541 children: React.ReactNode;

Callers 1

PageFunction · 0.85

Calls 1

isActiveRouteFunction · 0.85

Tested by

no test coverage detected