Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(work): keep the open issue lit while the next page loads (MUL-9350) (#10687)
Jiayuan Zhangeebe4aba1a41
diff --git a/packages/views/layout/panels/work-panel.test.tsx b/packages/views/layout/panels/work-panel.test.tsxindex 7543edd5c6..c3888907bb 100644--- a/packages/views/layout/panels/work-panel.test.tsx+++ b/packages/views/layout/panels/work-panel.test.tsx@@ -154,6 +154,8 @@ function renderPanel(projects: Project[] = [],unreadIssueIds: string[] = [],inbox: InboxItem[] = [],+ /** As on web, a push lands only once the next page has loaded ("Finish loading"). */+ deferPush = false,) {const qc = new QueryClient({ defaultOptions: { queries: { staleTime: Infinity, retry: false } } });qc.setQueryData(inboxListOptions("ws-1").queryKey, inbox);@@ -180,8 +182,9 @@ function renderPanel(const [peek, setPeek] = useState(false);// A compact sheet unmounts the panel whenever it closes.const [sheetOpen, setSheetOpen] = useState(true);+ const [loading, setLoading] = useState<string | null>(null);const adapter: NavigationAdapter = {- push: setPathname,+ push: deferPush ? setLoading : setPathname,replace: setPathname,back: vi.fn(),pathname,@@ -199,6 +202,9 @@ function renderPanel(<button type="button" onClick={() => setPathname(`/acme/issues/${ISSUE.id}`)}>Return to issue</button>+ <button type="button" onClick={() => loading && setPathname(new URL(loading, "http://x").pathname)}>+ Finish loading+ </button><button type="button" onClick={() => setSheetOpen((open) => !open)}>Toggle sheet</button>@@ -358,6 +364,63 @@ describe("WorkPanel Inbox highlight", () => {});});+describe("WorkPanel Inbox highlight while the next page loads", () => {+ const inInbox = () => document.querySelector('[data-sidebar-list="inbox"]') as HTMLElement;+ const inMyIssues = () => document.querySelector('[data-sidebar-list="builtin:my_work"]') as HTMLElement;+ const inboxRow = (issue: Issue) => within(inInbox()).getByRole("link", { name: new RegExp(`^${issue.title}`) });+ const finishLoading = () => fireEvent.click(screen.getByRole("button", { name: "Finish loading" }));++ // Under the collapsed Projects section, an issue without a project that no+ // other row marks lights All issues.+ async function openFromInbox(expanded: string[]) {+ useSidebarTreeStore.setState({ expanded, projectsCollapsed: true });+ const qc = renderPanel("/acme/my-issues", [], [], [], [inboxItem(ISSUE), inboxItem(OTHER)], true);+ act(() => {+ qc.setQueryData(issueDetailOptions("ws-1", ISSUE.id).queryKey, ISSUE);+ });+ fireEvent.click(inboxRow(ISSUE));+ finishLoading();+ expect(inboxRow(ISSUE)).toHaveAttribute("aria-current", "page");+ return qc;+ }++ it("keeps the open issue lit in the Inbox until the next notification's page arrives", async () => {+ await openFromInbox([]);+ fireEvent.click(inboxRow(OTHER));++ expect(inboxRow(ISSUE)).toHaveAttribute("aria-current", "page");+ expect(allIssues()).not.toHaveAttribute("aria-current");++ finishLoading();+ expect(inboxRow(OTHER)).toHaveAttribute("aria-current", "page");+ expect(inboxRow(ISSUE)).not.toHaveAttribute("aria-current");+ });++ it("keeps the open issue lit in the Inbox until an issue clicked in a view arrives", async () => {+ await openFromInbox(["builtin:my_work"]);+ fireEvent.click(await within(await waitFor(inMyIssues)).findByRole("link", { name: OTHER.title }));++ expect(inboxRow(ISSUE)).toHaveAttribute("aria-current", "page");+ expect(within(inMyIssues()).getByRole("link", { name: ISSUE.title })).not.toHaveAttribute("aria-current");+ expect(allIssues()).not.toHaveAttribute("aria-current");++ finishLoading();+ expect(within(inMyIssues()).getByRole("link", { name: OTHER.title })).toHaveAttribute("aria-current", "page");+ expect(inboxRow(ISSUE)).not.toHaveAttribute("aria-current");+ });++ it("lights nothing else while the issue header moves on from an archived notification", async () => {+ const qc = await openFromInbox([]);+ act(() => {+ qc.setQueryData(inboxListOptions("ws-1").queryKey, [{ ...inboxItem(ISSUE), archived: true }, inboxItem(OTHER)]);+ useInboxSelectionStore.getState().rememberSidebarIssue("ws-1", OTHER.id);+ });++ await waitFor(() => expect(within(inInbox()).queryByRole("link", { name: INBOX_ROW_NAME })).toBeNull());+ expect(allIssues()).not.toHaveAttribute("aria-current");+ });+});+describe("WorkPanel issue highlight", () => {it("lights a clicked tree issue at once, never All issues first", async () => {renderPanel("/acme/my-issues");diff --git a/packages/views/layout/panels/work-panel.tsx b/packages/views/layout/panels/work-panel.tsxindex 119807882b..39029d58fb 100644--- a/packages/views/layout/panels/work-panel.tsx+++ b/packages/views/layout/panels/work-panel.tsx@@ -30,6 +30,18 @@ const PROJECTS_LIST = "projects";/** Pinned rows' place in the clicked-issue record, apart from every sidebar source. */const PINS_LIST = "pins";+interface ClickedIssue {+ segment: string;+ list: string | null;+}++/** The highlight records the open issue had before a click or the issue header moved on. */+interface SettledIssue {+ issueId: string | null;+ clickedIssue: ClickedIssue | null;+ inboxIssueId: string | null;+}+/*** The `{id}` of a `{base}/{id}` route — for `/issues/{id}`, a UUID or an* identifier like `MUL-123`.@@ -92,17 +104,37 @@ export function WorkPanel() {// An issue can sit in Pinned and in several lists at once, but lights in// one place: the list it was clicked in. Arriving any other way (search, a// link, a shortcut) lights the pin, else the first list that shows it.- const [clickedIssue, setClickedIssue] = useState<{ segment: string; list: string | null } | null>(null);- const clickedList =- clickedIssue &&- currentIssueId &&- (clickedIssue.segment === currentIssueId || clickedIssue.segment === currentIssue?.identifier)- ? clickedIssue.list- : undefined;+ const [liveClickedIssue, setClickedIssue] = useState<ClickedIssue | null>(null);+ const isOpenIssue = (segment: string) =>+ !!currentIssueId && (segment === currentIssueId || segment === currentIssue?.identifier);// An issue opened from the Inbox, by a row or by the issue header moving on// to the next notification, lights there while the section still shows it;// once archived, it falls back to the other lists.- const inboxIssueId = useInboxSelectionStore((s) => (wsId ? s.sidebarIssueByWorkspace[wsId] : null));+ const liveInboxIssueId = useInboxSelectionStore((s) => (wsId ? (s.sidebarIssueByWorkspace[wsId] ?? null) : null));+ // A click, or the issue header moving on, names the next issue before the+ // route reaches it, which on web waits for the next page to load. Until+ // then the open issue keeps the record it had, or its highlight would fall+ // through to another list, or All issues, for the length of the load.+ const [settled, setSettled] = useState<SettledIssue>({+ issueId: currentIssueId,+ clickedIssue: liveClickedIssue,+ inboxIssueId: liveInboxIssueId,+ });+ const movingOn =+ settled.issueId === currentIssueId &&+ ((liveClickedIssue !== settled.clickedIssue && !!liveClickedIssue && !isOpenIssue(liveClickedIssue.segment)) ||+ (liveInboxIssueId !== settled.inboxIssueId && !!liveInboxIssueId && liveInboxIssueId !== currentIssueId));+ if (+ !movingOn &&+ (settled.issueId !== currentIssueId ||+ settled.clickedIssue !== liveClickedIssue ||+ settled.inboxIssueId !== liveInboxIssueId)+ ) {+ setSettled({ issueId: currentIssueId, clickedIssue: liveClickedIssue, inboxIssueId: liveInboxIssueId });+ }+ const clickedIssue = movingOn ? settled.clickedIssue : liveClickedIssue;+ const inboxIssueId = movingOn ? settled.inboxIssueId : liveInboxIssueId;+ const clickedList = clickedIssue && isOpenIssue(clickedIssue.segment) ? clickedIssue.list : undefined;// The notification open beside the section: an issue opened from it, or an// issue-less one on the Inbox page.const inboxOpenKey =@@ -113,8 +145,11 @@ export function WorkPanel() {: null;const inboxRows = useInboxSectionRows(wsId, inboxOpenKey);const rememberSidebarIssue = useInboxSelectionStore((s) => s.rememberSidebarIssue);+ // Moving on from an archived row keeps the issue lit nowhere rather than elsewhere.const inboxClaimsIssue =- !!currentIssueId && inboxIssueId === currentIssueId && inboxRows.shownIssueIds.has(currentIssueId);+ !!currentIssueId &&+ inboxIssueId === currentIssueId &&+ (movingOn || inboxRows.shownIssueIds.has(currentIssueId));const treeClaimsIssue = inboxClaimsIssue || (clickedList !== undefined && clickedList !== PINS_LIST);const pins = usePanelPins(wsId, userId, pathname, treeClaimsIssue ? null : currentIssueId);const requestLocate = useSidebarTreeStore((s) => s.requestLocate);