From 50082f08436884435d90faf6898def0407af52c0 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Fri, 9 May 2025 16:53:51 +0530 Subject: [PATCH] [WEB-4002] fix: sidebar tab highlight (#7011) * fix: work item tab highlight * chore: code refactor * chore: code refactor * chore: code refactor --- .../workspace/sidebar/project-navigation.tsx | 42 +++++++++++++++---- web/core/store/issue/issue.store.ts | 7 ++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/web/core/components/workspace/sidebar/project-navigation.tsx b/web/core/components/workspace/sidebar/project-navigation.tsx index 8a94fbcf6..f4add66e6 100644 --- a/web/core/components/workspace/sidebar/project-navigation.tsx +++ b/web/core/components/workspace/sidebar/project-navigation.tsx @@ -3,7 +3,7 @@ import React, { FC, useCallback, useMemo } from "react"; import { observer } from "mobx-react"; import Link from "next/link"; -import { usePathname } from "next/navigation"; +import { useParams, usePathname } from "next/navigation"; import { FileText, Layers } from "lucide-react"; import { EUserPermissionsLevel, EUserPermissions, EUserProjectRoles } from "@plane/constants"; import { useTranslation } from "@plane/i18n"; @@ -12,7 +12,7 @@ import { Tooltip, DiceIcon, ContrastIcon, LayersIcon, Intake } from "@plane/ui"; // components import { SidebarNavItem } from "@/components/sidebar"; // hooks -import { useAppTheme, useProject, useUserPermissions } from "@/hooks/store"; +import { useAppTheme, useIssueDetail, useProject, useUserPermissions } from "@/hooks/store"; import { usePlatformOS } from "@/hooks/use-platform-os"; // plane-web constants @@ -24,6 +24,7 @@ export type TNavigationItem = { shouldRender: boolean; sortOrder: number; i18n_key: string; + key: string; }; type TProjectItemsProps = { @@ -35,15 +36,23 @@ type TProjectItemsProps = { export const ProjectNavigation: FC = observer((props) => { const { workspaceSlug, projectId, additionalNavigationItems, isSidebarCollapsed } = props; + const { workItem: workItemIdentifierFromRoute } = useParams(); // store hooks const { t } = useTranslation(); const { toggleSidebar } = useAppTheme(); const { getPartialProjectById } = useProject(); const { isMobile } = usePlatformOS(); const { allowPermissions } = useUserPermissions(); + const { + issue: { getIssueIdByIdentifier, getIssueById }, + } = useIssueDetail(); // pathname const pathname = usePathname(); // derived values + const workItemId = workItemIdentifierFromRoute + ? getIssueIdByIdentifier(workItemIdentifierFromRoute?.toString()) + : undefined; + const workItem = workItemId ? getIssueById(workItemId) : undefined; const project = getPartialProjectById(projectId); // handlers const handleProjectClick = () => { @@ -58,6 +67,7 @@ export const ProjectNavigation: FC = observer((props) => { (workspaceSlug: string, projectId: string): TNavigationItem[] => [ { i18n_key: "sidebar.work_items", + key: "work_items", name: "Work items", href: `/${workspaceSlug}/projects/${projectId}/issues`, icon: LayersIcon, @@ -67,6 +77,7 @@ export const ProjectNavigation: FC = observer((props) => { }, { i18n_key: "sidebar.cycles", + key: "cycles", name: "Cycles", href: `/${workspaceSlug}/projects/${projectId}/cycles`, icon: ContrastIcon, @@ -76,6 +87,7 @@ export const ProjectNavigation: FC = observer((props) => { }, { i18n_key: "sidebar.modules", + key: "modules", name: "Modules", href: `/${workspaceSlug}/projects/${projectId}/modules`, icon: DiceIcon, @@ -85,6 +97,7 @@ export const ProjectNavigation: FC = observer((props) => { }, { i18n_key: "sidebar.views", + key: "views", name: "Views", href: `/${workspaceSlug}/projects/${projectId}/views`, icon: Layers, @@ -94,6 +107,7 @@ export const ProjectNavigation: FC = observer((props) => { }, { i18n_key: "sidebar.pages", + key: "pages", name: "Pages", href: `/${workspaceSlug}/projects/${projectId}/pages`, icon: FileText, @@ -103,6 +117,7 @@ export const ProjectNavigation: FC = observer((props) => { }, { i18n_key: "sidebar.intake", + key: "intake", name: "Intake", href: `/${workspaceSlug}/projects/${projectId}/intake`, icon: Intake, @@ -134,6 +149,23 @@ export const ProjectNavigation: FC = observer((props) => { return sortedNavigationItems; }, [workspaceSlug, projectId, baseNavigation, additionalNavigationItems]); + const isActive = useCallback( + (item: TNavigationItem) => { + // work item condition + const workItemCondition = workItemId && workItem && !workItem?.is_epic && workItem?.project_id === projectId; + // epic condition + const epicCondition = workItemId && workItem && workItem?.is_epic && workItem?.project_id === projectId; + // is active + const isWorkItemActive = item.key === "work_items" && workItemCondition; + const isEpicActive = item.key === "epics" && epicCondition; + // pathname condition + const isPathnameActive = pathname.includes(item.href); + // return + return isWorkItemActive || isEpicActive || isPathnameActive; + }, + [pathname, workItem, workItemId, projectId] + ); + return ( <> {navigationItemsMemo.map((item) => { @@ -154,11 +186,7 @@ export const ProjectNavigation: FC = observer((props) => {
{ issues.forEach((issue) => { + // add issue identifier to the issuesIdentifierMap + const projectIdentifier = rootStore.projectRoot.project.getProjectIdentifierById(issue?.project_id); + const workItemSequenceId = issue?.sequence_id; + const issueIdentifier = `${projectIdentifier}-${workItemSequenceId}`; + set(this.issuesIdentifierMap, issueIdentifier, issue.id); + if (!this.issuesMap[issue.id]) set(this.issuesMap, issue.id, issue); else update(this.issuesMap, issue.id, (prevIssue) => ({ ...prevIssue, ...issue })); });