Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8439 fix(sidebar): keep the open issue and project in place when an edit filters them out (#9758)
Jiayuan Zhang0d627e54e1bd
diff --git a/packages/core/issues/stores/sidebar-kept-store.test.ts b/packages/core/issues/stores/sidebar-kept-store.test.tsnew file mode 100644index 0000000000..3c366902d0--- /dev/null+++ b/packages/core/issues/stores/sidebar-kept-store.test.ts@@ -0,0 +1,39 @@+// @vitest-environment node+import { beforeEach, describe, expect, it } from "vitest";+import { useSidebarKeptStore } from "./sidebar-kept-store";++beforeEach(() => {+ useSidebarKeptStore.setState({ held: {} });+});++describe("useSidebarKeptStore", () => {+ it("records the open item's place per list", () => {+ const { hold } = useSidebarKeptStore.getState();+ hold("project:p1", "issue-1", 2);+ hold("builtin:all_issues", "issue-1", 0);+ hold("project:p1", "issue-1", 3);++ expect(useSidebarKeptStore.getState().held).toEqual({+ "project:p1": { id: "issue-1", index: 3 },+ "builtin:all_issues": { id: "issue-1", index: 0 },+ });+ });++ it("keeps the state untouched when nothing changes", () => {+ useSidebarKeptStore.getState().hold("project:p1", "issue-1", 2);+ const before = useSidebarKeptStore.getState().held;+ useSidebarKeptStore.getState().hold("project:p1", "issue-1", 2);+ useSidebarKeptStore.getState().release(["issue-1"]);++ expect(useSidebarKeptStore.getState().held).toBe(before);+ });++ it("forgets places held for items no longer open", () => {+ const { hold, release } = useSidebarKeptStore.getState();+ hold("project:p1", "issue-1", 2);+ hold("projects", "project-1", 0);+ release(["project-1"]);++ expect(useSidebarKeptStore.getState().held).toEqual({ projects: { id: "project-1", index: 0 } });+ });+});diff --git a/packages/core/issues/stores/sidebar-kept-store.ts b/packages/core/issues/stores/sidebar-kept-store.tsnew file mode 100644index 0000000000..12b601046d--- /dev/null+++ b/packages/core/issues/stores/sidebar-kept-store.ts@@ -0,0 +1,37 @@+import { create } from "zustand";++/** The open item a sidebar list showed, and its place there. */+export interface SidebarKeptItem {+ id: string;+ index: number;+}++interface SidebarKeptState {+ /** By list: a sidebar source, or `projects` for the Projects section. */+ held: Record<string, SidebarKeptItem>;+ /** Records that `list` shows the open item `id` at `index`. */+ hold: (list: string, id: string, index: number) => void;+ /** Forgets every place held for an item that is no longer open. */+ release: (openIds: readonly string[]) => void;+}++/**+ * Where the sidebar lists last showed the open issue or project, so a list+ * can keep that row in place after an edit filters it out. Shared, so the+ * panel and its hover peek keep the same rows.+ */+export const useSidebarKeptStore = create<SidebarKeptState>()((set) => ({+ held: {},+ hold: (list, id, index) =>+ set((s) => {+ const current = s.held[list];+ if (current?.id === id && current.index === index) return s;+ return { held: { ...s.held, [list]: { id, index } } };+ }),+ release: (openIds) =>+ set((s) => {+ const kept = Object.entries(s.held).filter(([, item]) => openIds.includes(item.id));+ if (kept.length === Object.keys(s.held).length) return s;+ return { held: Object.fromEntries(kept) };+ }),+}));diff --git a/packages/views/layout/panels/sidebar-tree.tsx b/packages/views/layout/panels/sidebar-tree.tsxindex 43c52a78e6..b489266c42 100644--- a/packages/views/layout/panels/sidebar-tree.tsx+++ b/packages/views/layout/panels/sidebar-tree.tsx@@ -1,6 +1,6 @@"use client";-import { forwardRef, memo, useCallback, useState } from "react";+import { forwardRef, memo, useCallback, useLayoutEffect, useState } from "react";import { keepPreviousData, useQuery } from "@tanstack/react-query";import { ChevronDown, ChevronRight, ChevronUp } from "@multica/ui/icons";import { cn } from "@multica/ui/lib/utils";@@ -8,8 +8,9 @@ import { ShimmerText } from "@multica/ui/components/common/shimmer-text";import { agentTaskSnapshotOptions } from "@multica/core/agents";import { useIssueStatuses } from "@multica/core/issue-statuses/hooks";import { issueStatusCategory } from "@multica/core/issues";-import { sidebarIssuesOptions } from "@multica/core/issues/queries";+import { issueDetailOptions, sidebarIssuesOptions } from "@multica/core/issues/queries";import { SIDEBAR_FIRST_PAGE, SIDEBAR_PAGE_STEP, type SidebarIssuesRequest } from "@multica/core/issues/sidebar-list";+import { useSidebarKeptStore } from "@multica/core/issues/stores/sidebar-kept-store";import { useWorkspacePaths } from "@multica/core/paths";import type { AgentTask, Issue, ListIssuesParams } from "@multica/core/types";import { AppLink } from "../../navigation";@@ -161,6 +162,30 @@ export function issueRowMenuOpenClass(active: boolean) {}const EMPTY_PARAMS: ListIssuesParams = {};+const EMPTY_ISSUES: Issue[] = [];++/**+ * `items` with the open item put back at its last place in `list` once it+ * drops out, until another item opens: an edit on its page (marking it done,+ * reassigning it, moving it) must not take away its row or move the+ * highlight elsewhere. `latest` is the open item's current data; without it+ * (deleted, or not loaded) nothing is kept.+ */+export function useKeptActiveItem<T extends { id: string }>(+ list: string,+ items: readonly T[],+ activeId: string | null,+ latest: T | undefined,+): readonly T[] {+ const index = activeId ? items.findIndex((item) => item.id === activeId) : -1;+ const held = useSidebarKeptStore((s) => s.held[list]);+ useLayoutEffect(() => {+ if (activeId && index !== -1) useSidebarKeptStore.getState().hold(list, activeId, index);+ }, [list, activeId, index]);+ if (index !== -1 || !activeId || !held || held.id !== activeId || !latest || latest.id !== activeId) return items;+ const at = Math.min(held.index, items.length);+ return [...items.slice(0, at), latest, ...items.slice(at)];+}/*** The issues under an expanded row: the first page, then "Load more" in@@ -192,8 +217,15 @@ export function SidebarIssueList({enabled: !!params,placeholderData: keepPreviousData,});- const issues = params ? (query.data?.issues ?? []) : [];+ const listed = params ? (query.data?.issues ?? EMPTY_ISSUES) : EMPTY_ISSUES;const total = params ? (query.data?.total ?? 0) : 0;+ // The list no longer carries a kept issue; the detail cache follows its+ // edits, and dropping it on delete ends the keep.+ const { data: activeIssue } = useQuery({+ ...issueDetailOptions(wsId, activeIssueId ?? ""),+ enabled: false,+ });+ const issues = useKeptActiveItem(source, listed, activeIssueId, activeIssue);const onKeyDown = (event: React.KeyboardEvent) => {if (event.key !== "ArrowLeft") return;@@ -232,23 +264,23 @@ export function SidebarIssueList({/></li>))}- {total > issues.length ? (+ {total > listed.length ? (<li><buttontype="button"className={tailClass}disabled={query.isFetching}onKeyDown={onKeyDown}- onClick={() => setLimit(issues.length + SIDEBAR_PAGE_STEP)}+ onClick={() => setLimit(listed.length + SIDEBAR_PAGE_STEP)}><ChevronDown className="size-3.5" />{t(($) => $.panels.work.load_more)}{" "}- <span className="tabular-nums">{total - issues.length}</span>+ <span className="tabular-nums">{total - listed.length}</span></button></li>) : (limit > SIDEBAR_FIRST_PAGE &&- issues.length > SIDEBAR_FIRST_PAGE && (+ listed.length > SIDEBAR_FIRST_PAGE && (<li><button type="button" className={tailClass} onKeyDown={onKeyDown} onClick={() => setLimit(SIDEBAR_FIRST_PAGE)}><ChevronUp className="size-3.5" />diff --git a/packages/views/layout/panels/work-panel.test.tsx b/packages/views/layout/panels/work-panel.test.tsxindex 6fa49b6a41..0a947fdb73 100644--- a/packages/views/layout/panels/work-panel.test.tsx+++ b/packages/views/layout/panels/work-panel.test.tsx@@ -1,20 +1,23 @@import { useState, type ReactNode } from "react";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";-import { fireEvent, screen } from "@testing-library/react";+import { act, fireEvent, screen, waitFor, within } from "@testing-library/react";import { beforeEach, describe, expect, it, vi } from "vitest";import { agentTaskSnapshotOptions } from "@multica/core/agents";import { EMPTY_ISSUE_VIEW_PREFERENCE } from "@multica/core/api/schemas";import { useActiveIssueViewStore } from "@multica/core/issue-views/active-view-store";import { issueViewPreferenceOptions } from "@multica/core/issue-views/preferences";import { issueViewEverywhereOptions } from "@multica/core/issue-views/queries";+import { issueDetailOptions, issueKeys } from "@multica/core/issues/queries";import { SIDEBAR_PROJECTS_SCOPE } from "@multica/core/issues/sidebar-project-prefs";+import { useSidebarKeptStore } from "@multica/core/issues/stores/sidebar-kept-store";import { useSidebarTreeStore } from "@multica/core/issues/stores/sidebar-tree-store";+import { spaceForPath } from "@multica/core/paths";import { pinListOptions } from "@multica/core/pins/queries";import { projectListOptions } from "@multica/core/projects/queries";-import type { Issue, IssueTableRowsResponse, PinnedItem } from "@multica/core/types";+import type { Issue, IssueTableRowsResponse, PinnedItem, Project } from "@multica/core/types";import { renderWithI18n } from "../../test/i18n";import { NavigationProvider, type NavigationAdapter } from "../../navigation";-import { WorkPanel } from "./work-panel";+import { KeptRowsRelease, WorkPanel } from "./work-panel";const apiMock = vi.hoisted(() => ({ listIssueTableRows: vi.fn(), getIssue: vi.fn() }));const actions = vi.hoisted(() => ({@@ -116,9 +119,21 @@ const PIN: PinnedItem = {created_at: "",};-function renderPanel(initialPath: string, pins: PinnedItem[] = []) {+const PROJECT = {+ id: "5d4c3b2a-1f0e-4d9c-8b7a-6f5e4d3c2b1a",+ title: "Launch",+ status: "in_progress",+ lead_type: null,+ lead_id: null,+ issue_count: 0,+ done_count: 0,+ created_at: "",+ updated_at: "",+} as unknown as Project;++function renderPanel(initialPath: string, pins: PinnedItem[] = [], projects: Project[] = []) {const qc = new QueryClient({ defaultOptions: { queries: { staleTime: Infinity, retry: false } } });- qc.setQueryData(projectListOptions("ws-1").queryKey, { projects: [], total: 0 });+ qc.setQueryData(projectListOptions("ws-1").queryKey, { projects, total: projects.length });qc.setQueryData(pinListOptions("ws-1", "u1").queryKey, pins);qc.setQueryData(issueViewEverywhereOptions("ws-1").queryKey, []);qc.setQueryData(issueViewPreferenceOptions("ws-1", SIDEBAR_PROJECTS_SCOPE).queryKey, EMPTY_ISSUE_VIEW_PREFERENCE);@@ -126,6 +141,10 @@ function renderPanel(initialPath: string, pins: PinnedItem[] = []) {function Harness() {const [pathname, setPathname] = useState(initialPath);+ // A collapsed sidebar mounts a second panel as its hover peek.+ const [peek, setPeek] = useState(false);+ // A compact sheet unmounts the panel whenever it closes.+ const [sheetOpen, setSheetOpen] = useState(true);const adapter: NavigationAdapter = {push: setPathname,replace: setPathname,@@ -137,7 +156,25 @@ function renderPanel(initialPath: string, pins: PinnedItem[] = []) {};return (<NavigationProvider value={adapter}>- <WorkPanel />+ <KeptRowsRelease />+ {sheetOpen && spaceForPath(pathname) === "work" && <WorkPanel />}+ <button type="button" onClick={() => setPathname("/acme/inbox")}>+ Visit inbox+ </button>+ <button type="button" onClick={() => setPathname(`/acme/issues/${ISSUE.id}`)}>+ Return to issue+ </button>+ <button type="button" onClick={() => setSheetOpen((open) => !open)}>+ Toggle sheet+ </button>+ <button type="button" onClick={() => setPeek(true)}>+ Open peek+ </button>+ {peek && (+ <div data-testid="peek">+ <WorkPanel />+ </div>+ )}</NavigationProvider>);}@@ -147,6 +184,7 @@ function renderPanel(initialPath: string, pins: PinnedItem[] = []) {<Harness /></QueryClientProvider>,);+ return qc;}const issueRow = () => screen.getByRole("link", { name: ISSUE.title });@@ -160,6 +198,7 @@ beforeEach(() => {projectsCollapsed: false,});useActiveIssueViewStore.setState({ active: {} });+ useSidebarKeptStore.setState({ held: {} });apiMock.listIssueTableRows.mockResolvedValue({rows: [ISSUE, OTHER].map((issue) => ({ issue })),total: 2,@@ -198,4 +237,91 @@ describe("WorkPanel issue highlight", () => {await screen.findByRole("link", { name: ISSUE.title });expect(allIssues()).toHaveAttribute("aria-current", "page");});++ it("keeps an issue its list drops lit in place until another issue opens", async () => {+ const qc = renderPanel("/acme/my-issues");+ fireEvent.click(await screen.findByRole("link", { name: ISSUE.title }));+ qc.setQueryData(issueDetailOptions("ws-1", ISSUE.id).queryKey, { ...ISSUE, title: "Fixed the sidebar", status: "done" });+ apiMock.listIssueTableRows.mockResolvedValue({ rows: [{ issue: OTHER }], total: 1, next_cursor: null });+ await act(() => qc.invalidateQueries({ queryKey: issueKeys.sidebarAll("ws-1") }));++ expect(await screen.findByRole("link", { name: "Fixed the sidebar" })).toHaveAttribute("aria-current", "page");+ expect(allIssues()).not.toHaveAttribute("aria-current");++ fireEvent.click(screen.getByRole("link", { name: OTHER.title }));+ expect(screen.queryByRole("link", { name: "Fixed the sidebar" })).toBeNull();+ });++ it("drops a kept issue once it is deleted", async () => {+ const qc = renderPanel("/acme/my-issues");+ fireEvent.click(await screen.findByRole("link", { name: ISSUE.title }));+ qc.setQueryData(issueDetailOptions("ws-1", ISSUE.id).queryKey, ISSUE);+ apiMock.listIssueTableRows.mockResolvedValue({ rows: [{ issue: OTHER }], total: 1, next_cursor: null });+ await act(async () => {+ qc.removeQueries({ queryKey: issueKeys.detail("ws-1", ISSUE.id) });+ await qc.invalidateQueries({ queryKey: issueKeys.sidebarAll("ws-1") });+ });++ await waitFor(() => expect(screen.queryByRole("link", { name: ISSUE.title })).toBeNull());+ });++ it("keeps the dropped issue lit in a peek opened afterwards", async () => {+ const qc = renderPanel("/acme/my-issues");+ fireEvent.click(await screen.findByRole("link", { name: ISSUE.title }));+ qc.setQueryData(issueDetailOptions("ws-1", ISSUE.id).queryKey, { ...ISSUE, title: "Fixed the sidebar", status: "done" });+ apiMock.listIssueTableRows.mockResolvedValue({ rows: [{ issue: OTHER }], total: 1, next_cursor: null });+ await act(() => qc.invalidateQueries({ queryKey: issueKeys.sidebarAll("ws-1") }));+ await screen.findByRole("link", { name: "Fixed the sidebar" });+ fireEvent.click(screen.getByRole("button", { name: "Open peek" }));++ const peek = within(screen.getByTestId("peek"));+ expect(peek.getByRole("link", { name: "Fixed the sidebar" })).toHaveAttribute("aria-current", "page");+ expect(peek.getByRole("link", { name: "All issues" })).not.toHaveAttribute("aria-current");+ });++ it("keeps the dropped issue while the panel remounts on the same page", async () => {+ const qc = renderPanel("/acme/my-issues");+ fireEvent.click(await screen.findByRole("link", { name: ISSUE.title }));+ qc.setQueryData(issueDetailOptions("ws-1", ISSUE.id).queryKey, { ...ISSUE, title: "Fixed the sidebar", status: "done" });+ apiMock.listIssueTableRows.mockResolvedValue({ rows: [{ issue: OTHER }], total: 1, next_cursor: null });+ await act(() => qc.invalidateQueries({ queryKey: issueKeys.sidebarAll("ws-1") }));+ await screen.findByRole("link", { name: "Fixed the sidebar" });++ fireEvent.click(screen.getByRole("button", { name: "Toggle sheet" }));+ fireEvent.click(screen.getByRole("button", { name: "Toggle sheet" }));++ expect(await screen.findByRole("link", { name: "Fixed the sidebar" })).toHaveAttribute("aria-current", "page");+ });++ it("ends the keep after leaving Work and coming back to the issue", async () => {+ const qc = renderPanel("/acme/my-issues");+ fireEvent.click(await screen.findByRole("link", { name: ISSUE.title }));+ qc.setQueryData(issueDetailOptions("ws-1", ISSUE.id).queryKey, { ...ISSUE, title: "Fixed the sidebar", status: "done" });+ apiMock.listIssueTableRows.mockResolvedValue({ rows: [{ issue: OTHER }], total: 1, next_cursor: null });+ await act(() => qc.invalidateQueries({ queryKey: issueKeys.sidebarAll("ws-1") }));+ await screen.findByRole("link", { name: "Fixed the sidebar" });++ fireEvent.click(screen.getByRole("button", { name: "Visit inbox" }));+ fireEvent.click(screen.getByRole("button", { name: "Return to issue" }));++ expect(await screen.findByRole("link", { name: OTHER.title })).toBeInTheDocument();+ expect(screen.queryByRole("link", { name: "Fixed the sidebar" })).toBeNull();+ expect(allIssues()).toHaveAttribute("aria-current", "page");+ });++ it("keeps the open project in the tree after it leaves the projects filter", async () => {+ const qc = renderPanel(`/acme/projects/${PROJECT.id}`, [], [PROJECT]);+ expect(screen.getByRole("link", { name: PROJECT.title })).toHaveAttribute("aria-current", "page");++ act(() => {+ qc.setQueryData(projectListOptions("ws-1").queryKey, {+ projects: [{ ...PROJECT, title: "Launched", status: "completed" }],+ total: 1,+ });+ });+ expect(await screen.findByRole("link", { name: "Launched" })).toHaveAttribute("aria-current", "page");++ fireEvent.click(allIssues());+ expect(screen.queryByRole("link", { name: "Launched" })).toBeNull();+ });});diff --git a/packages/views/layout/panels/work-panel.tsx b/packages/views/layout/panels/work-panel.tsxindex 50fd65d1e3..2f09e16a34 100644--- a/packages/views/layout/panels/work-panel.tsx+++ b/packages/views/layout/panels/work-panel.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useMemo, useState } from "react";+import { useEffect, useLayoutEffect, useMemo, useState } from "react";import { useQuery } from "@tanstack/react-query";import { useAuthStore } from "@multica/core/auth";import { useCurrentWorkspace, useWorkspacePaths } from "@multica/core/paths";@@ -8,26 +8,58 @@ import { isIssueUuid } from "@multica/core/issues/canonical-id";import { issueDetailOptions } from "@multica/core/issues/queries";import { projectSidebarSource, sidebarProjects } from "@multica/core/issues/sidebar-list";import { useSidebarProjectPrefs } from "@multica/core/issues/sidebar-project-prefs";+import { useSidebarKeptStore } from "@multica/core/issues/stores/sidebar-kept-store";import { useSidebarTreeStore } from "@multica/core/issues/stores/sidebar-tree-store";import { projectListOptions } from "@multica/core/projects/queries";import type { Project } from "@multica/core/types";import { useNavigation } from "../../navigation";import { IssueContextMenuProvider } from "../../issues/actions";import { useT } from "../../i18n";-import { PanelBody, PanelHeader } from "../panel-nav";+import { PanelBody, PanelHeader, isPathWithin } from "../panel-nav";import { PinnedSection, usePanelPins } from "./pinned-section";+import { useKeptActiveItem } from "./sidebar-tree";import { ProjectsSection, useIssueIdInTree } from "./work-tree";import { ViewsSection } from "./views-section";const EMPTY_PROJECTS: Project[] = [];+/** The Projects section's key in the kept-rows store, apart from every sidebar source. */+const PROJECTS_LIST = "projects";-/** The `{id}` of an `/issues/{id}` route — a UUID or an identifier like `MUL-123`. */-function issueRouteSegment(pathname: string, issuesPath: string): string | null {- if (!pathname.startsWith(issuesPath + "/")) return null;- const segment = pathname.slice(issuesPath.length + 1).split("/")[0];+/**+ * The `{id}` of a `{base}/{id}` route — for `/issues/{id}`, a UUID or an+ * identifier like `MUL-123`.+ */+function routeSegment(pathname: string, base: string): string | null {+ if (!pathname.startsWith(base + "/")) return null;+ const segment = pathname.slice(base.length + 1).split("/")[0];return segment ? decodeURIComponent(segment) : null;}+/**+ * Ends the rows the sidebar lists keep (`useKeptActiveItem`) once their issue+ * or project is no longer the page. Mounted with the shell rather than the+ * Work panel, which unmounts on leaving Work and with every compact sheet+ * close.+ */+export function KeptRowsRelease() {+ const p = useWorkspacePaths();+ const { pathname } = useNavigation();+ const wsId = useCurrentWorkspace()?.id ?? "";+ const issueSegment = routeSegment(pathname, p.issues());+ const { data: issue } = useQuery({+ ...issueDetailOptions(wsId, issueSegment ?? ""),+ enabled: false,+ });+ // `undefined` while an identifier route waits for the page to load its issue.+ const issueId = issueSegment ? (issue?.id ?? (isIssueUuid(issueSegment) ? issueSegment : undefined)) : null;+ const projectId = routeSegment(pathname, p.projects());+ useLayoutEffect(() => {+ if (issueId === undefined) return;+ useSidebarKeptStore.getState().release([issueId, projectId].filter((id) => id !== null));+ }, [issueId, projectId]);+ return null;+}+export function WorkPanel() {const { t } = useT("layout");const p = useWorkspacePaths();@@ -40,7 +72,7 @@ export function WorkPanel() {enabled: !!wsId,});// Cache read only: the detail page owns resolving the route's issue.- const issueSegment = issueRouteSegment(pathname, p.issues());+ const issueSegment = routeSegment(pathname, p.issues());const { data: currentIssue } = useQuery({...issueDetailOptions(wsId ?? "", issueSegment ?? ""),enabled: false,@@ -66,7 +98,7 @@ export function WorkPanel() {const link = (event.target as HTMLElement).closest("a[href]");if (!link) return;const path = new URL(link.getAttribute("href") ?? "", window.location.href).pathname;- const segment = issueRouteSegment(path, p.issues());+ const segment = routeSegment(path, p.issues());setClickedIssue(segment ? { segment, fromPins: !!link.closest("[data-pinned-section]") } : null);};// A lit pin already marks the issue; opening its project would only push@@ -80,11 +112,16 @@ export function WorkPanel() {}, [revealProjectId, setExpanded]);const { projectSettings, projectOrder } = useSidebarProjectPrefs(wsId ?? "");+ const filteredProjects = useMemo(+ () => sidebarProjects(projects, projectSettings, projectOrder, userId),+ [projects, projectSettings, projectOrder, userId],+ );+ const openProject = projects.find((project) => isPathWithin(pathname, p.projectDetail(project.id)));+ const keptProjects = useKeptActiveItem(PROJECTS_LIST, filteredProjects, openProject?.id ?? null, openProject);const shownProjects = useMemo(() => {- const shown = sidebarProjects(projects, projectSettings, projectOrder, userId);const revealed = projects.find((project) => project.id === revealProjectId);- return revealed && !shown.includes(revealed) ? [...shown, revealed] : shown;- }, [projects, projectSettings, projectOrder, userId, revealProjectId]);+ return revealed && !keptProjects.includes(revealed) ? [...keptProjects, revealed] : [...keptProjects];+ }, [projects, keptProjects, revealProjectId]);const issueLitInTree = treeIssueId !== null;const plainRowsLit = !pins.isActivePinnedRoute;diff --git a/packages/views/layout/panels/work-tree.tsx b/packages/views/layout/panels/work-tree.tsxindex bda67a4189..b62db631d9 100644--- a/packages/views/layout/panels/work-tree.tsx+++ b/packages/views/layout/panels/work-tree.tsx@@ -18,10 +18,11 @@ import {} from "@multica/core/issues/sidebar-list";import { useSidebarProjectPrefs, useUpdateSidebarProjectPrefs } from "@multica/core/issues/sidebar-project-prefs";import { openCreateIssueWithPreference } from "@multica/core/issues/stores/create-mode-store";+import { useSidebarKeptStore } from "@multica/core/issues/stores/sidebar-kept-store";import { useSidebarTreeStore, type SidebarIssueSettings } from "@multica/core/issues/stores/sidebar-tree-store";import { useModalStore } from "@multica/core/modals";import { useWorkspacePaths } from "@multica/core/paths";-import type { ListIssuesParams, ListIssuesResponse, Project } from "@multica/core/types";+import type { Issue, ListIssuesParams, ListIssuesResponse, Project } from "@multica/core/types";import { useT } from "../../i18n";import { PanelCount, PanelLink, PanelList, PanelSection, isPathWithin } from "../panel-nav";import { ProjectsSectionSettings } from "./sidebar-settings";@@ -43,23 +44,39 @@ function usePrefetch(wsId: string, source: string, params: ListIssuesParams | nu}/**- * The id of the issue an expanded row lists under `ref` — its UUID, or an- * identifier like `MUL-123` matched case-insensitively as the server does —- * or `null` when no expanded row lists it.+ * The id of the issue an expanded row lists or keeps under `ref` — its UUID,+ * or an identifier like `MUL-123` matched case-insensitively as the server+ * does — or `null` when no expanded row lists it.*/export function useIssueIdInTree(wsId: string, ref: string | null): string | null {- const cache = useQueryClient().getQueryCache();- const subscribe = useCallback((onChange: () => void) => cache.subscribe(onChange), [cache]);+ const qc = useQueryClient();+ const cache = qc.getQueryCache();+ const subscribe = useCallback(+ (onChange: () => void) => {+ const unsubscribeCache = cache.subscribe(onChange);+ const unsubscribeKept = useSidebarKeptStore.subscribe(onChange);+ return () => {+ unsubscribeCache();+ unsubscribeKept();+ };+ },+ [cache],+ );return useSyncExternalStore(subscribe, () => {if (!ref) return null;const identifier = ref.toUpperCase();- for (const query of cache.findAll({ queryKey: issueKeys.sidebarAll(wsId) })) {- if (query.getObserversCount() === 0) continue;- const issue = (query.state.data as ListIssuesResponse | undefined)?.issues?.find(- (issue) => issue.id === ref || issue.identifier.toUpperCase() === identifier,- );+ const matches = (issue: Issue) => issue.id === ref || issue.identifier.toUpperCase() === identifier;+ const shown = (queryKey: readonly unknown[]) =>+ cache.findAll({ queryKey }).filter((query) => query.getObserversCount() > 0);+ for (const query of shown(issueKeys.sidebarAll(wsId))) {+ const issue = (query.state.data as ListIssuesResponse | undefined)?.issues?.find(matches);if (issue) return issue.id;}+ // A shown list keeps the open issue its query dropped (`useKeptActiveItem`).+ for (const [list, held] of Object.entries(useSidebarKeptStore.getState().held)) {+ const issue = qc.getQueryData<Issue>(issueKeys.detail(wsId, held.id));+ if (issue && matches(issue) && shown([...issueKeys.sidebarAll(wsId), list]).length > 0) return issue.id;+ }return null;});}diff --git a/packages/views/layout/space-panel.test.tsx b/packages/views/layout/space-panel.test.tsxindex e47a13b6ab..5b1590b0f2 100644--- a/packages/views/layout/space-panel.test.tsx+++ b/packages/views/layout/space-panel.test.tsx@@ -10,7 +10,10 @@ const navigation = vi.hoisted(() => ({ pathname: "/acme/issues" }));vi.mock("../navigation", () => ({useNavigation: () => ({ pathname: navigation.pathname }),}));-vi.mock("./panels/work-panel", () => ({ WorkPanel: () => <div data-testid="work-panel" /> }));+vi.mock("./panels/work-panel", () => ({+ WorkPanel: () => <div data-testid="work-panel" />,+ KeptRowsRelease: () => null,+}));vi.mock("./panels/team-panel", () => ({ TeamPanel: () => <div data-testid="team-panel" /> }));vi.mock("./panels/autopilots-panel", () => ({AutopilotsPanel: () => <div data-testid="autopilots-panel" />,diff --git a/packages/views/layout/space-panel.tsx b/packages/views/layout/space-panel.tsxindex 80ab93cef9..23befaf79b 100644--- a/packages/views/layout/space-panel.tsx+++ b/packages/views/layout/space-panel.tsx@@ -10,7 +10,7 @@ import { AutopilotsPanel } from "./panels/autopilots-panel";import { ChatPeek, InboxPeek } from "./panels/list-space-peeks";import { NAV_COLUMN_MOTION_CLASS, NAV_PEEK_CLASS } from "./rail-styles";import { TeamPanel } from "./panels/team-panel";-import { WorkPanel } from "./panels/work-panel";+import { KeptRowsRelease, WorkPanel } from "./panels/work-panel";const PANELS: Partial<Record<AppSpaceId, () => React.ReactNode>> = {work: WorkPanel,@@ -43,7 +43,8 @@ export function SpacePanel() {const shell = useAppShell();const { open, isCompact } = useSidebar();const panelRef = useRef<HTMLElement>(null);- if (!shell || isCompact) return null;+ if (!shell) return null;+ if (isCompact) return <KeptRowsRelease />;const { space, hasPanel, peekSpace, navCollapsed } = shell;// The current space's own list column floats itself (`ListColumn`).@@ -52,6 +53,7 @@ export function SpacePanel() {return (<>+ <KeptRowsRelease />{hasPanel && (<aside// A new space mounts at its final width; only toggling animates.