[WEB-4559] fix: workspace menu item active state (#7666)
* fix: highlight active workspace menu item correctly * chore: code refactor
This commit is contained in:
parent
e0912ccefc
commit
ba7303b7af
2 changed files with 13 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ import { useParams, usePathname } from "next/navigation";
|
||||||
// plane imports
|
// plane imports
|
||||||
import { EUserPermissionsLevel, IWorkspaceSidebarNavigationItem } from "@plane/constants";
|
import { EUserPermissionsLevel, IWorkspaceSidebarNavigationItem } from "@plane/constants";
|
||||||
import { useTranslation } from "@plane/i18n";
|
import { useTranslation } from "@plane/i18n";
|
||||||
|
import { joinUrlPath } from "@plane/utils";
|
||||||
// components
|
// components
|
||||||
import { SidebarNavItem } from "@/components/sidebar/sidebar-navigation";
|
import { SidebarNavItem } from "@/components/sidebar/sidebar-navigation";
|
||||||
import { NotificationAppSidebarOption } from "@/components/workspace-notifications/notification-app-sidebar-option";
|
import { NotificationAppSidebarOption } from "@/components/workspace-notifications/notification-app-sidebar-option";
|
||||||
|
|
@ -47,13 +48,13 @@ export const SidebarItemBase: FC<Props> = observer(({ item, additionalRender, ad
|
||||||
const isPinned = sidebarPreference?.[item.key]?.is_pinned;
|
const isPinned = sidebarPreference?.[item.key]?.is_pinned;
|
||||||
if (!isPinned && !staticItems.includes(item.key)) return null;
|
if (!isPinned && !staticItems.includes(item.key)) return null;
|
||||||
|
|
||||||
const itemHref = item.key === "your_work" ? `/${slug}${item.href}${data?.id}/` : `/${slug}${item.href}`;
|
const itemHref =
|
||||||
const isActive = itemHref === pathname;
|
item.key === "your_work" && data?.id ? joinUrlPath(slug, item.href, data?.id) : joinUrlPath(slug, item.href);
|
||||||
const icon = getSidebarNavigationItemIcon(item.key);
|
const icon = getSidebarNavigationItemIcon(item.key);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link href={itemHref} onClick={handleLinkClick}>
|
<Link href={itemHref} onClick={handleLinkClick}>
|
||||||
<SidebarNavItem isActive={isActive}>
|
<SidebarNavItem isActive={item.highlight(pathname, itemHref)}>
|
||||||
<div className="flex items-center gap-1.5 py-[1px]">
|
<div className="flex items-center gap-1.5 py-[1px]">
|
||||||
{icon}
|
{icon}
|
||||||
<p className="text-sm leading-5 font-medium">{t(item.labelTranslationKey)}</p>
|
<p className="text-sm leading-5 font-medium">{t(item.labelTranslationKey)}</p>
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,7 @@ export interface IWorkspaceSidebarNavigationItem {
|
||||||
labelTranslationKey: string;
|
labelTranslationKey: string;
|
||||||
href: string;
|
href: string;
|
||||||
access: EUserWorkspaceRoles[];
|
access: EUserWorkspaceRoles[];
|
||||||
|
highlight: (pathname: string, url: string) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WORKSPACE_SIDEBAR_DYNAMIC_NAVIGATION_ITEMS: Record<string, IWorkspaceSidebarNavigationItem> = {
|
export const WORKSPACE_SIDEBAR_DYNAMIC_NAVIGATION_ITEMS: Record<string, IWorkspaceSidebarNavigationItem> = {
|
||||||
|
|
@ -252,24 +253,28 @@ export const WORKSPACE_SIDEBAR_DYNAMIC_NAVIGATION_ITEMS: Record<string, IWorkspa
|
||||||
labelTranslationKey: "views",
|
labelTranslationKey: "views",
|
||||||
href: `/workspace-views/all-issues/`,
|
href: `/workspace-views/all-issues/`,
|
||||||
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER, EUserWorkspaceRoles.GUEST],
|
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER, EUserWorkspaceRoles.GUEST],
|
||||||
|
highlight: (pathname: string, url: string) => pathname === url,
|
||||||
},
|
},
|
||||||
analytics: {
|
analytics: {
|
||||||
key: "analytics",
|
key: "analytics",
|
||||||
labelTranslationKey: "analytics",
|
labelTranslationKey: "analytics",
|
||||||
href: `/analytics/`,
|
href: `/analytics/`,
|
||||||
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER],
|
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER],
|
||||||
|
highlight: (pathname: string, url: string) => pathname.includes(url),
|
||||||
},
|
},
|
||||||
drafts: {
|
drafts: {
|
||||||
key: "drafts",
|
key: "drafts",
|
||||||
labelTranslationKey: "drafts",
|
labelTranslationKey: "drafts",
|
||||||
href: `/drafts/`,
|
href: `/drafts/`,
|
||||||
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER],
|
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER],
|
||||||
|
highlight: (pathname: string, url: string) => pathname.includes(url),
|
||||||
},
|
},
|
||||||
archives: {
|
archives: {
|
||||||
key: "archives",
|
key: "archives",
|
||||||
labelTranslationKey: "archives",
|
labelTranslationKey: "archives",
|
||||||
href: `/projects/archives/`,
|
href: `/projects/archives/`,
|
||||||
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER],
|
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER],
|
||||||
|
highlight: (pathname: string, url: string) => pathname.includes(url),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -286,24 +291,28 @@ export const WORKSPACE_SIDEBAR_STATIC_NAVIGATION_ITEMS: Record<string, IWorkspac
|
||||||
labelTranslationKey: "home.title",
|
labelTranslationKey: "home.title",
|
||||||
href: `/`,
|
href: `/`,
|
||||||
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER, EUserWorkspaceRoles.GUEST],
|
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER, EUserWorkspaceRoles.GUEST],
|
||||||
|
highlight: (pathname: string, url: string) => pathname === url,
|
||||||
},
|
},
|
||||||
inbox: {
|
inbox: {
|
||||||
key: "inbox",
|
key: "inbox",
|
||||||
labelTranslationKey: "notification.label",
|
labelTranslationKey: "notification.label",
|
||||||
href: `/notifications/`,
|
href: `/notifications/`,
|
||||||
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER, EUserWorkspaceRoles.GUEST],
|
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER, EUserWorkspaceRoles.GUEST],
|
||||||
|
highlight: (pathname: string, url: string) => pathname.includes(url),
|
||||||
},
|
},
|
||||||
"your-work": {
|
"your-work": {
|
||||||
key: "your_work",
|
key: "your_work",
|
||||||
labelTranslationKey: "your_work",
|
labelTranslationKey: "your_work",
|
||||||
href: `/profile/`,
|
href: `/profile/`,
|
||||||
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER],
|
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER],
|
||||||
|
highlight: (pathname: string, url: string) => pathname.includes(url),
|
||||||
},
|
},
|
||||||
projects: {
|
projects: {
|
||||||
key: "projects",
|
key: "projects",
|
||||||
labelTranslationKey: "projects",
|
labelTranslationKey: "projects",
|
||||||
href: `/projects/`,
|
href: `/projects/`,
|
||||||
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER, EUserWorkspaceRoles.GUEST],
|
access: [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER, EUserWorkspaceRoles.GUEST],
|
||||||
|
highlight: (pathname: string, url: string) => pathname.includes(url),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue