From 9f55948785962ca1a0f07aa7828410ac7bfb341f Mon Sep 17 00:00:00 2001 From: Abdul Rahman Date: Thu, 9 Apr 2026 06:51:53 +0530 Subject: [PATCH] Refactor active navigation item logic in NavigationDrawerItemForObjectMetadataItem - Enhanced the calculation of active navigation item state by introducing checks for the current path, improving the accuracy of the `isActive` determination. - Simplified the logic for determining if the current path matches the object metadata, contributing to better maintainability and clarity in the component's navigation handling. --- ...igationDrawerItemForObjectMetadataItem.tsx | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/object/components/NavigationDrawerItemForObjectMetadataItem.tsx b/packages/twenty-front/src/modules/navigation-menu-item/display/object/components/NavigationDrawerItemForObjectMetadataItem.tsx index fc183c01b17..a91c811435b 100644 --- a/packages/twenty-front/src/modules/navigation-menu-item/display/object/components/NavigationDrawerItemForObjectMetadataItem.tsx +++ b/packages/twenty-front/src/modules/navigation-menu-item/display/object/components/NavigationDrawerItemForObjectMetadataItem.tsx @@ -98,36 +98,44 @@ export const NavigationDrawerItemForObjectMetadataItem = ({ const activeNavigationItem = useAtomStateValue(activeNavigationItemState); const setActiveNavigationItem = useSetAtomState(activeNavigationItemState); - const isAtomForCurrentObject = + const isOnRecordShowPage = matchesRecordShowPathForObject( + currentPath, + objectMetadataItem.nameSingular, + ); + + const isOnIndexPage = + currentPath === + getAppPath(AppPath.RecordIndexPage, { + objectNamePlural: objectMetadataItem.namePlural, + }); + + const isCurrentPathMatchingObject = isOnIndexPage || isOnRecordShowPage; + + const shouldUseExplicitActiveItem = isDefined(activeNavigationItem) && - activeNavigationItem.objectNameSingular === objectMetadataItem.nameSingular; + activeNavigationItem.objectNameSingular === + objectMetadataItem.nameSingular && + isCurrentPathMatchingObject; const isRecordMatchingCurrentPage = isRecord && hasCustomLink && computedLink === currentPath; - const isActiveByUrl = hasCustomLink - ? isLocationMatchingNavigationMenuItem( - currentPath, - currentPathWithSearch, - navigationMenuItem!.type, - computedLink, - ) || - (isObject && - matchesRecordShowPathForObject( - currentPath, - objectMetadataItem.nameSingular, - )) - : currentPath === - getAppPath(AppPath.RecordIndexPage, { - objectNamePlural: objectMetadataItem.namePlural, - }) || - matchesRecordShowPathForObject( - currentPath, - objectMetadataItem.nameSingular, - ); + const matchesNavigationMenuItemLink = + hasCustomLink && + isLocationMatchingNavigationMenuItem( + currentPath, + currentPathWithSearch, + navigationMenuItem!.type, + computedLink, + ); + + const isActiveByUrl = + matchesNavigationMenuItemLink || + (isObject && isOnRecordShowPage) || + (!hasCustomLink && isCurrentPathMatchingObject); const isActive = - isAtomForCurrentObject && isDefined(navItemId) + shouldUseExplicitActiveItem && isDefined(navItemId) ? activeNavigationItem.navItemId === navItemId || isRecordMatchingCurrentPage : isActiveByUrl;