Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8590 fix(sidebar): keep the Unread row while the issue opened from it is read (#9919)
Jiayuan Zhang7c984c0f1668
diff --git a/packages/views/layout/panels/views-section.tsx b/packages/views/layout/panels/views-section.tsxindex 011cad8699..ad44a652cc 100644--- a/packages/views/layout/panels/views-section.tsx+++ b/packages/views/layout/panels/views-section.tsx@@ -1,6 +1,6 @@"use client";-import { useCallback, useEffect, useId, useRef, useState } from "react";+import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";import { useQuery, useQueryClient } from "@tanstack/react-query";import { useStore } from "zustand";import { DndContext, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent } from "@dnd-kit/core";@@ -33,6 +33,7 @@ import { todayDateOnly } from "@multica/core/issues/date";import { useIssueUnreadIds } from "@multica/core/issues/unread";import { useIssueStatuses } from "@multica/core/issue-statuses/hooks";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 {myIssuesRelationFromScope,@@ -398,10 +399,28 @@ function BuiltinViewRow({);}+/** The Unread row's key in the kept-rows store, apart from its issue list's. */+const UNREAD_ROW_KEPT = "unread-row";++/**+ * Whether the open issue was unread when it opened. Opening it marks it+ * read, so the unread list alone cannot tell; the kept-rows store remembers+ * it across panel remounts until the issue is no longer the page.+ */+function useOpenedUnread(activeIssueId: string | null, unreadIds: readonly string[] | undefined): boolean {+ const index = activeIssueId && unreadIds ? unreadIds.indexOf(activeIssueId) : -1;+ const held = useSidebarKeptStore((s) => s.held[UNREAD_ROW_KEPT]);+ useLayoutEffect(() => {+ if (activeIssueId && index !== -1) useSidebarKeptStore.getState().hold(UNREAD_ROW_KEPT, activeIssueId, index);+ }, [activeIssueId, index]);+ return !!activeIssueId && (index !== -1 || held?.id === activeIssueId);+}+/*** The built-in Unread view. It shows only while the viewer has unread- * issues, and stays while its page is open so reading the last one does not- * pull the row out from under the reader.+ * issues, and stays while its page is open, or while an issue that was+ * unread when it opened is open, so reading the last one does not pull the+ * row (and that issue's place under it) out from under the reader.*/function UnreadViewRow({wsId,@@ -430,8 +449,9 @@ function UnreadViewRow({const count = unread.ids?.length ?? 0;const request = unread.ids ? viewSidebarRequest(UNREAD_VIEW, todayDateOnly(), unread.ids) : undefined;const prefetch = usePrefetch(wsId, source, request);+ const readingUnread = useOpenedUnread(activeIssueId, unread.ids);- if (count === 0 && !open) return null;+ if (count === 0 && !open && !readingUnread) return null;const label = t(($) => $.panels.work.unread);return (<li>diff --git a/packages/views/layout/panels/views-section.unread.test.tsx b/packages/views/layout/panels/views-section.unread.test.tsxindex d105d29f6f..19dcb0a458 100644--- a/packages/views/layout/panels/views-section.unread.test.tsx+++ b/packages/views/layout/panels/views-section.unread.test.tsx@@ -4,8 +4,10 @@ import { fireEvent, screen, waitFor } from "@testing-library/react";import { beforeEach, describe, expect, it, vi } from "vitest";import { setApiInstance } from "@multica/core/api";import type { ApiClient } from "@multica/core/api/client";+import { useSidebarKeptStore } from "@multica/core/issues/stores/sidebar-kept-store";import { useSidebarTreeStore } from "@multica/core/issues/stores/sidebar-tree-store";import { viewSidebarSource } from "@multica/core/issues/sidebar-list";+import { issueUnreadOptions } from "@multica/core/issues/unread";import { issueViewContainerKey, useActiveIssueViewStore } from "@multica/core/issue-views/active-view-store";import { UNREAD_VIEW_ID } from "@multica/core/issue-views/unread-view";import { renderWithI18n } from "../../test/i18n";@@ -73,21 +75,23 @@ const UNREAD_VIEW = {let listIssueUnread: ReturnType<typeof vi.fn>;let listIssueTableRows: ReturnType<typeof vi.fn>;-function renderSection() {+function renderSection({ activeIssueId = null }: { activeIssueId?: string | null } = {}) {const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });- return renderWithI18n(+ const tree = (issueId: string | null) => (<QueryClientProvider client={qc}><NavigationProvider value={adapter}><ViewsSectionwsId="ws-1"- pathname="/acme/issues"+ pathname={issueId ? `/acme/issues/${issueId}` : "/acme/issues"}plainRowsLitissueLitInTree={false}- activeIssueId={null}+ activeIssueId={issueId}/></NavigationProvider>- </QueryClientProvider>,+ </QueryClientProvider>);+ const view = renderWithI18n(tree(activeIssueId));+ return { ...view, qc, openIssue: (issueId: string | null) => view.rerender(tree(issueId)) };}beforeEach(() => {@@ -107,6 +111,7 @@ beforeEach(() => {getIssueViewPreference: vi.fn(() => new Promise(() => {})),} as unknown as ApiClient);useActiveIssueViewStore.setState({ active: {} });+ useSidebarKeptStore.setState({ held: {} });actions.sidebar.items = [{ id: "view:v1", kind: "view", view: UNREAD_VIEW }];useSidebarTreeStore.setState({ viewsCollapsed: false, expanded: [viewSidebarSource("v1")] });});@@ -183,4 +188,24 @@ describe("ViewsSection built-in Unread view", () => {expect(link).toHaveAttribute("aria-current", "page");expect(screen.getByRole("link", { name: /^All issues/ })).not.toHaveAttribute("aria-current");});++ it("stays while the last unread issue is open and read, until another page opens", async () => {+ listIssueUnread.mockResolvedValue([mark("a")]);+ const { qc, openIssue } = renderSection({ activeIssueId: "a" });+ await screen.findByRole("link", { name: /^Unread/ });++ qc.setQueryData(issueUnreadOptions("ws-1").queryKey, []);+ await waitFor(() => expect(screen.getByRole("link", { name: /^Unread/ }).closest("li")).toHaveTextContent(/^Unread$/));++ openIssue(null);+ await waitFor(() => expect(screen.queryByRole("link", { name: /^Unread/ })).toBeNull());+ });++ it("does not show for an open issue that was already read", async () => {+ listIssueUnread.mockResolvedValue([]);+ renderSection({ activeIssueId: "a" });+ await waitFor(() => expect(listIssueUnread).toHaveBeenCalled());+ await screen.findByRole("link", { name: "All issues" });+ expect(screen.queryByRole("link", { name: /^Unread/ })).toBeNull();+ });});diff --git a/packages/views/layout/panels/work-panel.test.tsx b/packages/views/layout/panels/work-panel.test.tsxindex 0a947fdb73..d51d5e6c99 100644--- a/packages/views/layout/panels/work-panel.test.tsx+++ b/packages/views/layout/panels/work-panel.test.tsx@@ -8,6 +8,7 @@ import { useActiveIssueViewStore } from "@multica/core/issue-views/active-view-simport { issueViewPreferenceOptions } from "@multica/core/issue-views/preferences";import { issueViewEverywhereOptions } from "@multica/core/issue-views/queries";import { issueDetailOptions, issueKeys } from "@multica/core/issues/queries";+import { issueUnreadOptions } from "@multica/core/issues/unread";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";@@ -131,13 +132,29 @@ const PROJECT = {updated_at: "",} as unknown as Project;-function renderPanel(initialPath: string, pins: PinnedItem[] = [], projects: Project[] = []) {+function renderPanel(+ initialPath: string,+ pins: PinnedItem[] = [],+ projects: Project[] = [],+ unreadIssueIds: string[] = [],+) {const qc = new QueryClient({ defaultOptions: { queries: { staleTime: Infinity, retry: false } } });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);qc.setQueryData(agentTaskSnapshotOptions("ws-1").queryKey, []);+ qc.setQueryData(+ issueUnreadOptions("ws-1").queryKey,+ unreadIssueIds.map((issue_id) => ({+ issue_id,+ outcome: "completed" as const,+ agent_id: null,+ task_id: null,+ comment_id: null,+ created_at: "2026-01-01T00:00:00Z",+ })),+ );function Harness() {const [pathname, setPathname] = useState(initialPath);@@ -325,3 +342,49 @@ describe("WorkPanel issue highlight", () => {expect(screen.queryByRole("link", { name: "Launched" })).toBeNull();});});++describe("WorkPanel Unread row after its last issue is read", () => {+ const unreadRow = (scope: Pick<typeof screen, "queryByRole"> = screen) =>+ scope.queryByRole("link", { name: /^Unread/ });++ async function openAndReadLastUnread() {+ useSidebarTreeStore.setState({ expanded: ["view:unread"] });+ apiMock.listIssueTableRows.mockResolvedValue({ rows: [{ issue: ISSUE }], total: 1, next_cursor: null });+ const qc = renderPanel("/acme/my-issues", [], [], [ISSUE.id]);+ // The unread dot's label is part of the link's name until it is read.+ fireEvent.click(await screen.findByRole("link", { name: new RegExp(`^${ISSUE.title}`) }));+ apiMock.listIssueTableRows.mockResolvedValue({ rows: [], total: 0, next_cursor: null });+ await act(async () => {+ qc.setQueryData(issueDetailOptions("ws-1", ISSUE.id).queryKey, ISSUE);+ qc.setQueryData(issueUnreadOptions("ws-1").queryKey, []);+ });+ await waitFor(() => expect(unreadRow()?.closest("li")).toHaveTextContent(/^Unread/));+ expect(unreadRow()?.closest("li")).not.toHaveTextContent("Unread1");+ expect(issueRow()).toHaveAttribute("aria-current", "page");+ return qc;+ }++ it("keeps the row and the open issue in the hover peek", async () => {+ await openAndReadLastUnread();+ fireEvent.click(screen.getByRole("button", { name: "Open peek" }));+ const peek = within(screen.getByTestId("peek"));+ expect(unreadRow(peek)).not.toBeNull();+ expect(peek.getByRole("link", { name: ISSUE.title })).toHaveAttribute("aria-current", "page");+ });++ it("keeps the row and the open issue when the compact sheet reopens", async () => {+ await openAndReadLastUnread();+ fireEvent.click(screen.getByRole("button", { name: "Toggle sheet" }));+ fireEvent.click(screen.getByRole("button", { name: "Toggle sheet" }));+ expect(unreadRow()).not.toBeNull();+ expect(issueRow()).toHaveAttribute("aria-current", "page");+ });++ it("drops the row once the issue is no longer the page", async () => {+ await openAndReadLastUnread();+ fireEvent.click(screen.getByRole("button", { name: "Visit inbox" }));+ fireEvent.click(screen.getByRole("button", { name: "Return to issue" }));+ await screen.findByRole("link", { name: "All issues" });+ expect(unreadRow()).toBeNull();+ });+});