Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix pinned sidebar active state
Jiayuan Zhangba7be23f7ca7
diff --git a/packages/views/layout/app-sidebar.test.tsx b/packages/views/layout/app-sidebar.test.tsxindex ab684f879a..ca4d5fb2d8 100644--- a/packages/views/layout/app-sidebar.test.tsx+++ b/packages/views/layout/app-sidebar.test.tsx@@ -3,9 +3,10 @@ import { beforeEach, describe, expect, it, vi } from "vitest";import { ApiError } from "@multica/core/api";import { AppSidebar } from "./app-sidebar";-const { detail, deletePin, pins } = vi.hoisted(() => ({+const { detail, deletePin, navigation, pins } = vi.hoisted(() => ({detail: { current: { isPending: false, isError: false, data: null as unknown, error: null as unknown } },deletePin: vi.fn(),+ navigation: { current: { pathname: "/acme/issues" } },pins: {current: [{@@ -43,7 +44,19 @@ vi.mock("@multica/ui/components/ui/sidebar", () => ({SidebarGroupLabel: ({ children }: { children: React.ReactNode }) => <>{children}</>,SidebarHeader: ({ children }: { children: React.ReactNode }) => <>{children}</>,SidebarMenu: ({ children }: { children: React.ReactNode }) => <>{children}</>,- SidebarMenuButton: ({ children }: { children: React.ReactNode }) => <button type="button">{children}</button>,+ SidebarMenuButton: ({+ children,+ isActive,+ render,+ }: {+ children: React.ReactNode;+ isActive?: boolean;+ render?: React.ReactElement<{ href?: string }>;+ }) => (+ <button type="button" data-active={isActive ? "true" : undefined} data-href={render?.props.href}>+ {children}+ </button>+ ),SidebarMenuItem: ({ children }: { children: React.ReactNode }) => <>{children}</>,SidebarRail: () => null,}));@@ -71,7 +84,7 @@ vi.mock("../auth", () => ({ useLogout: () => vi.fn() }));vi.mock("../issues/components/status-icon", () => ({ StatusIcon: () => <span /> }));vi.mock("../navigation", () => ({AppLink: ({ children, href }: { children: React.ReactNode; href: string }) => <a href={href}>{children}</a>,- useNavigation: () => ({ pathname: "/acme/issues", push: vi.fn() }),+ useNavigation: () => ({ pathname: navigation.current.pathname, push: vi.fn() }),}));vi.mock("../projects/components/project-icon", () => ({ ProjectIcon: () => <span /> }));vi.mock("../workspace/workspace-avatar", () => ({ WorkspaceAvatar: () => <span /> }));@@ -140,6 +153,7 @@ vi.mock("@tanstack/react-query", async (importOriginal) => ({describe("PinRow", () => {beforeEach(() => {deletePin.mockReset();+ navigation.current.pathname = "/acme/issues";detail.current = { isPending: false, isError: false, data: null, error: null };});@@ -160,4 +174,22 @@ describe("PinRow", () => {render(<AppSidebar />);expect(await screen.findByText("MUL-123 Keep this pin")).toBeInTheDocument();});++ it("does not also highlight the parent workspace nav for an active pin", async () => {+ navigation.current.pathname = "/acme/issues/issue-1";+ detail.current = {+ isPending: false,+ isError: false,+ data: { identifier: "MUL-123", title: "Keep this pin", status: "todo" },+ error: null,+ };++ const { container } = render(<AppSidebar />);++ expect((await screen.findByText("MUL-123 Keep this pin")).closest("button")).toHaveAttribute(+ "data-active",+ "true",+ );+ expect(container.querySelector('button[data-href="/acme/issues"]')).not.toHaveAttribute("data-active");+ });});diff --git a/packages/views/layout/app-sidebar.tsx b/packages/views/layout/app-sidebar.tsxindex b83595ce70..4019171635 100644--- a/packages/views/layout/app-sidebar.tsx+++ b/packages/views/layout/app-sidebar.tsx@@ -373,6 +373,10 @@ export function AppSidebar({ topSlot, searchSlot, headerClassName, headerStyle }const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 5 } }));const sidebarScrollRef = useRef<HTMLDivElement>(null);const sidebarFadeStyle = useScrollFade(sidebarScrollRef, 24);+ const getPinHref = useCallback(+ (pin: PinnedItem) => (pin.item_type === "issue" ? p.issueDetail(pin.item_id) : p.projectDetail(pin.item_id)),+ [p],+ );// Local presentational copy of pinnedItems for drop-animation stability.// Follows TQ at rest; frozen during a drag gesture so a mid-drag cache@@ -390,6 +394,7 @@ export function AppSidebar({ topSlot, searchSlot, headerClassName, headerStyle }setLocalPinnedWsId(wsId ?? null);}, [wsId]);const visiblePinned = localPinnedWsId === (wsId ?? null) ? localPinned : EMPTY_PINS;+ const isActivePinnedRoute = visiblePinned.some((pin) => pathname === getPinHref(pin));const handleDragStart = useCallback(() => {isDraggingRef.current = true;@@ -664,7 +669,7 @@ export function AppSidebar({ topSlot, searchSlot, headerClassName, headerStyle }<PinRowkey={pin.id}pin={pin}- href={pin.item_type === "issue" ? p.issueDetail(pin.item_id) : p.projectDetail(pin.item_id)}+ href={getPinHref(pin)}pathname={pathname}onUnpin={() => deletePin.mutate({ itemType: pin.item_type, itemId: pin.item_id })}wsId={wsId ?? ""}@@ -685,7 +690,7 @@ export function AppSidebar({ topSlot, searchSlot, headerClassName, headerStyle }<SidebarMenu className="gap-0.5">{workspaceNav.map((item) => {const href = p[item.key]();- const isActive = isNavActive(pathname, href);+ const isActive = !isActivePinnedRoute && isNavActive(pathname, href);return (<SidebarMenuItem key={item.key}><SidebarMenuButton