Files
twenty/packages/twenty-front/src/modules/settings/components/SettingsNavigationDrawerItem.tsx
T
nitin da00dee8a1 Fix settings navigation active state for sub-pages (#12318)
Changes the default behavior for settings navigation items to stay
active when navigating to sub-pages.

**Problem:**
- Navigation items like "Data Model" and "Webhooks" were not staying
highlighted when navigating to detail pages
- This was because `matchSubPages` defaulted to requiring exact path
matches

**Solution:**
- Updated logic to make sub-page matching the default behavior (`end:
item.matchSubPages === false`)
- Only "Accounts" explicitly sets `matchSubPages: false` for its custom
sub-item navigation
- Removed redundant `matchSubPages: true` declarations throughout the
codebase

**URL Changes:** -- checked with @Bonapara 
- `/settings/workspace` → `/settings/general`
- `/settings/workspace-members` → `/settings/members`
- `/settings/api-keys` → `/settings/apis`
- `/settings/developers/webhooks` → `/settings/webhooks`

before: 


https://github.com/user-attachments/assets/56b94a49-9c31-4bb5-9875-ec24f4bc4d1e

after:


https://github.com/user-attachments/assets/38742599-c045-44d1-8020-56f3eacca779

---------

Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
2025-05-30 08:19:20 +02:00

60 lines
1.8 KiB
TypeScript

import { useMatch, useResolvedPath } from 'react-router-dom';
import { AdvancedSettingsWrapper } from '@/settings/components/AdvancedSettingsWrapper';
import { SettingsNavigationItem } from '@/settings/hooks/useSettingsNavigationItems';
import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem';
import { NavigationDrawerSubItemState } from '@/ui/navigation/navigation-drawer/types/NavigationDrawerSubItemState';
import { isDefined } from 'twenty-shared/utils';
import { getSettingsPath } from '~/utils/navigation/getSettingsPath';
type SettingsNavigationDrawerItemProps = {
item: SettingsNavigationItem;
subItemState?: NavigationDrawerSubItemState;
};
export const SettingsNavigationDrawerItem = ({
item,
subItemState,
}: SettingsNavigationDrawerItemProps) => {
const href = item.path ? getSettingsPath(item.path) : '';
const pathName = useResolvedPath(href).pathname;
const isActive = !!useMatch({
path: pathName,
end: item.matchSubPages === false,
});
if (isDefined(item.isHidden) && item.isHidden) {
return null;
}
if (isDefined(item.isAdvanced) && item.isAdvanced) {
return (
<AdvancedSettingsWrapper>
<NavigationDrawerItem
indentationLevel={item.indentationLevel}
subItemState={subItemState}
label={item.label}
to={href}
Icon={item.Icon}
active={isActive}
soon={item.soon}
onClick={item.onClick}
/>
</AdvancedSettingsWrapper>
);
}
return (
<NavigationDrawerItem
indentationLevel={item.indentationLevel}
subItemState={subItemState}
label={item.label}
to={href}
Icon={item.Icon}
active={isActive}
soon={item.soon}
onClick={item.onClick}
/>
);
};