diff --git a/apps/web/components/app-sidebar/app-sidebar-header.tsx b/apps/web/components/app-sidebar/app-sidebar-header.tsx index 070d03a8dc..7117a649a7 100644 --- a/apps/web/components/app-sidebar/app-sidebar-header.tsx +++ b/apps/web/components/app-sidebar/app-sidebar-header.tsx @@ -1,7 +1,7 @@ "use client"; import Link from "next/link"; -import { IconChevronsLeft, IconChevronsRight } from "@tabler/icons-react"; +import { IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpand } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { cn } from "@/lib/utils"; @@ -41,7 +41,7 @@ export function AppSidebarHeader({ collapsed, onToggleCollapse }: AppSidebarHead onClick={onToggleCollapse} aria-label="Expand sidebar" > - + Expand sidebar @@ -82,7 +82,7 @@ export function AppSidebarHeader({ collapsed, onToggleCollapse }: AppSidebarHead onClick={onToggleCollapse} aria-label="Collapse sidebar" > - + Collapse sidebar diff --git a/apps/web/components/app-sidebar/app-sidebar-nav-item.tsx b/apps/web/components/app-sidebar/app-sidebar-nav-item.tsx index 491e117f6a..9dd00122b4 100644 --- a/apps/web/components/app-sidebar/app-sidebar-nav-item.tsx +++ b/apps/web/components/app-sidebar/app-sidebar-nav-item.tsx @@ -23,6 +23,8 @@ type AppSidebarNavItemProps = { disabled?: boolean; /** Optional data-testid placed on the button/link element. */ testId?: string; + /** Optional extra classes for surface-specific spacing. */ + className?: string; }; type TriggerProps = { @@ -83,6 +85,7 @@ export function AppSidebarNavItem({ exactMatch = false, disabled = false, testId, + className, }: AppSidebarNavItemProps) { const pathname = usePathname(); const active = isActive ?? isPathActive(pathname, href, exactMatch); @@ -93,6 +96,7 @@ export function AppSidebarNavItem({ disabled ? "cursor-not-allowed text-foreground/40" : cn("cursor-pointer", active ? SIDEBAR_ITEM_ACTIVE : SIDEBAR_ITEM_INACTIVE), + className, ); const inner = ( diff --git a/apps/web/components/app-sidebar/app-sidebar-new-task-item.test.tsx b/apps/web/components/app-sidebar/app-sidebar-new-task-item.test.tsx index d8b0dd58bc..a86a69b61c 100644 --- a/apps/web/components/app-sidebar/app-sidebar-new-task-item.test.tsx +++ b/apps/web/components/app-sidebar/app-sidebar-new-task-item.test.tsx @@ -6,6 +6,7 @@ const mocks = vi.hoisted(() => ({ routerPush: vi.fn(), setActiveTask: vi.fn(), setActiveSession: vi.fn(), + openQuickChat: vi.fn(), dialogTaskSessionId: null as string | null, dialogWillNavigate: false, })); @@ -35,6 +36,9 @@ let pathname = "/"; vi.mock("@/components/state-provider", () => ({ useAppStore: (selector: (s: typeof state) => unknown) => selector(state), })); +vi.mock("@/hooks/use-quick-chat-launcher", () => ({ + useQuickChatLauncher: () => mocks.openQuickChat, +})); vi.mock("@/hooks/domains/features/use-feature", () => ({ useFeature: () => officeEnabled, })); @@ -79,24 +83,26 @@ const SUBTASK_TESTID = "sidebar-new-subtask"; const OFFICE_DIALOG_TESTID = "office-new-task-dialog"; const REGULAR_DIALOG_TESTID = "regular-task-create-dialog"; -describe("AppSidebarNewTaskItem", () => { - beforeEach(() => { - state.workspaces.activeId = "ws-1"; - state.kanban.workflowId = "wf-1"; - state.kanban.steps = [{ id: "s1", title: "Todo" }]; - state.kanban.tasks = [{ id: "t-1", title: "Parent task" }]; - state.tasks.activeTaskId = null; - mocks.routerPush.mockClear(); - mocks.setActiveTask.mockClear(); - mocks.setActiveSession.mockClear(); - mocks.dialogTaskSessionId = null; - mocks.dialogWillNavigate = false; - officeEnabled = false; - pathname = "/"; - }); +function resetTestState() { + state.workspaces.activeId = "ws-1"; + state.kanban.workflowId = "wf-1"; + state.kanban.steps = [{ id: "s1", title: "Todo" }]; + state.kanban.tasks = [{ id: "t-1", title: "Parent task" }]; + state.tasks.activeTaskId = null; + mocks.routerPush.mockClear(); + mocks.setActiveTask.mockClear(); + mocks.setActiveSession.mockClear(); + mocks.openQuickChat.mockClear(); + mocks.dialogTaskSessionId = null; + mocks.dialogWillNavigate = false; + officeEnabled = false; + pathname = "/"; +} - afterEach(() => cleanup()); +beforeEach(resetTestState); +afterEach(() => cleanup()); +describe("AppSidebarNewTaskItem dialog routing", () => { it("uses the regular task-create dialog when office is disabled", () => { officeEnabled = false; renderItem(false); @@ -129,6 +135,25 @@ describe("AppSidebarNewTaskItem", () => { expect(screen.queryByTestId(REGULAR_DIALOG_TESTID)).toBeNull(); expect(screen.queryByTestId(OFFICE_DIALOG_TESTID)).toBeNull(); }); +}); + +describe("AppSidebarNewTaskItem row actions", () => { + it("opens quick chat from the trailing action beside New Task", () => { + renderItem(false); + screen.getByTestId("sidebar-quick-chat-shortcut").click(); + expect(mocks.openQuickChat).toHaveBeenCalledOnce(); + }); + + it("hides the quick chat shortcut when the rail is collapsed", () => { + renderItem(true); + expect(screen.queryByTestId("sidebar-quick-chat-shortcut")).toBeNull(); + }); + + it("hides the quick chat shortcut when there is no active workspace", () => { + state.workspaces.activeId = null; + renderItem(false); + expect(screen.queryByTestId("sidebar-quick-chat-shortcut")).toBeNull(); + }); it("offers a subtask affordance when a task is active in regular mode", () => { state.tasks.activeTaskId = "t-1"; @@ -160,7 +185,9 @@ describe("AppSidebarNewTaskItem", () => { renderItem(true); expect(screen.queryByTestId(SUBTASK_TESTID)).toBeNull(); }); +}); +describe("AppSidebarNewTaskItem creation success", () => { it("focuses the created task after regular sidebar task creation succeeds", () => { renderItem(false); screen.getByTestId(REGULAR_DIALOG_TESTID).click(); diff --git a/apps/web/components/app-sidebar/app-sidebar-new-task-item.tsx b/apps/web/components/app-sidebar/app-sidebar-new-task-item.tsx index c9671e500f..3afab7eea7 100644 --- a/apps/web/components/app-sidebar/app-sidebar-new-task-item.tsx +++ b/apps/web/components/app-sidebar/app-sidebar-new-task-item.tsx @@ -3,10 +3,12 @@ import { useCallback, useState } from "react"; import dynamic from "next/dynamic"; import { useRouter } from "next/navigation"; -import { IconSquarePlus, IconSubtask } from "@tabler/icons-react"; +import { IconMessageCircle, IconSquarePlus, IconSubtask } from "@tabler/icons-react"; +import type { Icon as TablerIcon } from "@tabler/icons-react"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { useAppStore } from "@/components/state-provider"; import { useInOffice } from "@/hooks/use-in-office"; +import { useQuickChatLauncher } from "@/hooks/use-quick-chat-launcher"; import { TaskCreateDialog } from "@/components/task-create-dialog"; import { linkToTask } from "@/lib/links"; import type { Task } from "@/lib/types/http"; @@ -25,6 +27,35 @@ type AppSidebarNewTaskItemProps = { collapsed: boolean; }; +const ONE_ROW_ACTION_INSET_CLASS = "pr-10"; +const TWO_ROW_ACTIONS_INSET_CLASS = "pr-16"; + +type RowActionButtonProps = { + icon: TablerIcon; + label: string; + testId: string; + onClick: () => void; +}; + +function RowActionButton({ icon: Icon, label, testId, onClick }: RowActionButtonProps) { + return ( + + + + + {label} + + ); +} + /** * "New Task" entry in the sidebar primary nav. Inside Office (an `/office` * route) it opens the richer "New issue" dialog (projects/assignees/stages); @@ -52,6 +83,7 @@ export function AppSidebarNewTaskItem({ collapsed }: AppSidebarNewTaskItemProps) return s.kanban.tasks.find((t) => t.id === id)?.title ?? ""; }); const inOffice = useInOffice(); + const handleOpenQuickChat = useQuickChatLauncher(workspaceId); const [open, setOpen] = useState(false); const [subtaskOpen, setSubtaskOpen] = useState(false); @@ -59,7 +91,16 @@ export function AppSidebarNewTaskItem({ collapsed }: AppSidebarNewTaskItemProps) // dialog for the primary New Task, but subtasks always go through the compact // NewSubtaskDialog, matching the retired dropdown). It needs an active task // and the expanded rail to host the trailing button. + const canOpenQuickChat = !collapsed && !!workspaceId; const canCreateSubtask = !collapsed && !!workspaceId && !!activeTaskId; + let actionInsetClass: string | undefined; + // Keep the label clear of the absolute action cluster: + // pr-10 covers one w-6 button + right-1.5 inset; pr-16 covers two buttons + gap-1. + if (canCreateSubtask) { + actionInsetClass = TWO_ROW_ACTIONS_INSET_CLASS; + } else if (canOpenQuickChat) { + actionInsetClass = ONE_ROW_ACTION_INSET_CLASS; + } const handleRegularTaskCreated = useCallback( ( task: Task, @@ -88,22 +129,25 @@ export function AppSidebarNewTaskItem({ collapsed }: AppSidebarNewTaskItemProps) collapsed={collapsed} disabled={!workspaceId} testId="create-task-button" + className={actionInsetClass} /> - {canCreateSubtask && ( - - - - - New subtask of current task - + /> + )} + )} {workspaceId && diff --git a/apps/web/components/app-sidebar/app-sidebar-primary-nav.test.tsx b/apps/web/components/app-sidebar/app-sidebar-primary-nav.test.tsx new file mode 100644 index 0000000000..e0224f81fc --- /dev/null +++ b/apps/web/components/app-sidebar/app-sidebar-primary-nav.test.tsx @@ -0,0 +1,79 @@ +import { cleanup, render, screen } from "@testing-library/react"; +import { TooltipProvider } from "@kandev/ui/tooltip"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +const mocks = vi.hoisted(() => ({ + openQuickChat: vi.fn(), +})); + +const state = { + workspaces: { activeId: "ws-1" as string | null }, + office: { inboxCount: 0 }, +}; +let inOffice = false; +let pathname = "/"; + +vi.mock("@/components/state-provider", () => ({ + useAppStore: (selector: (s: typeof state) => unknown) => selector(state), +})); + +vi.mock("@/hooks/use-in-office", () => ({ + useInOffice: () => inOffice, +})); + +vi.mock("@/hooks/use-quick-chat-launcher", () => ({ + useQuickChatLauncher: () => mocks.openQuickChat, +})); + +vi.mock("next/navigation", () => ({ + usePathname: () => pathname, + useRouter: () => ({ push: vi.fn() }), +})); + +vi.mock("./app-sidebar-new-task-item", () => ({ + AppSidebarNewTaskItem: ({ collapsed }: { collapsed: boolean }) => ( +
+ ), +})); + +import { AppSidebarPrimaryNav } from "./app-sidebar-primary-nav"; + +function renderNav(collapsed: boolean) { + return render( + + + , + ); +} + +describe("AppSidebarPrimaryNav", () => { + beforeEach(() => { + state.workspaces.activeId = "ws-1"; + state.office.inboxCount = 0; + inOffice = false; + pathname = "/"; + mocks.openQuickChat.mockClear(); + }); + + afterEach(() => cleanup()); + + it("keeps Quick Chat reachable when the sidebar rail is collapsed", () => { + renderNav(true); + + screen.getByRole("button", { name: "Quick Chat" }).click(); + expect(mocks.openQuickChat).toHaveBeenCalledOnce(); + }); + + it("omits the standalone Quick Chat row while expanded", () => { + renderNav(false); + + expect(screen.queryByRole("button", { name: "Quick Chat" })).toBeNull(); + }); + + it("omits Quick Chat when the rail is collapsed but there is no workspace", () => { + state.workspaces.activeId = null; + renderNav(true); + + expect(screen.queryByRole("button", { name: "Quick Chat" })).toBeNull(); + }); +}); diff --git a/apps/web/components/app-sidebar/app-sidebar-primary-nav.tsx b/apps/web/components/app-sidebar/app-sidebar-primary-nav.tsx index 60ccb4cdb2..1bed73a043 100644 --- a/apps/web/components/app-sidebar/app-sidebar-primary-nav.tsx +++ b/apps/web/components/app-sidebar/app-sidebar-primary-nav.tsx @@ -35,7 +35,7 @@ export function AppSidebarPrimaryNav({ collapsed }: AppSidebarPrimaryNavProps) { collapsed={collapsed} /> )} - {workspaceId && ( + {workspaceId && collapsed && ( void; }; -function SectionHeader({ label, expanded, headerAction, onToggle }: SectionHeaderProps) { +function SectionHeader({ + label, + expanded, + headerAction, + headerActionVisibility, + onToggle, +}: SectionHeaderProps) { + const showHeaderAction = !!headerAction && (expanded || headerActionVisibility === "always"); + return (
- {expanded && headerAction && ( -
{headerAction}
- )} + {showHeaderAction &&
{headerAction}
}