Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(inbox): add a keyboard shortcut for archiving the open notification (#6877)

Tim16f9f25224a3
diff --git a/packages/core/shortcuts/definitions.test.ts b/packages/core/shortcuts/definitions.test.ts
index 4614f206a1..8eab645b3e 100644
--- a/packages/core/shortcuts/definitions.test.ts
+++ b/packages/core/shortcuts/definitions.test.ts
@@ -93,6 +93,12 @@ describe("keyboard shortcut definitions", () => {
expect(action.allowInEditable).toBe(true);
});
+ it("keeps the inbox archive key out of editable controls", () => {
+ const action = SHORTCUT_ACTION_BY_ID.archiveInboxItem;
+ expect(action.defaultShortcut).toEqual(createShortcutChord("E"));
+ expect(action.allowInEditable).toBe(false);
+ });
+
it("strictly distinguishes Command and Control on macOS", () => {
const commandF = createShortcutChord("F", { primary: true });
const controlF = createShortcutChord("F", { control: true });
diff --git a/packages/core/shortcuts/definitions.ts b/packages/core/shortcuts/definitions.ts
index 5c165a18d5..2c18629997 100644
--- a/packages/core/shortcuts/definitions.ts
+++ b/packages/core/shortcuts/definitions.ts
@@ -12,6 +12,7 @@ export type ShortcutActionId =
| "toggleChat"
| "findInIssue"
| "openThreadNav"
+ | "archiveInboxItem"
| "send"
| "goBack"
| "goForward"
@@ -102,6 +103,12 @@ export const SHORTCUT_ACTIONS: readonly ShortcutActionDefinition[] = [
defaultShortcut: createShortcutChord("O", { primary: true, shift: true }),
allowInEditable: true,
},
+ {
+ id: "archiveInboxItem",
+ category: "general",
+ defaultShortcut: createShortcutChord("E"),
+ allowInEditable: false,
+ },
{ id: "send", category: "general", defaultShortcut: primary("Enter"), allowInEditable: true },
// Browser-style history navigation (Mod+[ / Mod+]). Neither bracket is
// app-owned (PRIMARY_RESERVED_KEYS) nor browser-owned
@@ -272,6 +279,21 @@ export function isEditableShortcutTarget(target: EventTarget | null): boolean {
);
}
+const PORTAL_LAYER_SELECTOR =
+ '[role="menu"], [role="dialog"], [role="alertdialog"], [role="listbox"]';
+
+/**
+ * Whether an open popup (menu, dialog, listbox) owns the keyboard. Popups are
+ * portaled to the body, so page-level listeners still see their keypresses;
+ * the `data-base-ui-inert` marker catches modal layers even when focus never
+ * left the page.
+ */
+export function isPortalLayerShortcutTarget(target: EventTarget | null): boolean {
+ if (typeof document === "undefined") return false;
+ if (document.querySelector("[data-base-ui-inert]") !== null) return true;
+ return target instanceof Element && target.closest(PORTAL_LAYER_SELECTOR) !== null;
+}
+
const PRIMARY_RESERVED_KEYS = new Set([
// Window operations the app itself owns on every runtime: W closes the
// tab, R/F5 is the reload guard, Q quits.
diff --git a/packages/core/shortcuts/index.ts b/packages/core/shortcuts/index.ts
index 883b2ebd74..07e9f0f1f6 100644
--- a/packages/core/shortcuts/index.ts
+++ b/packages/core/shortcuts/index.ts
@@ -8,6 +8,7 @@ export {
isPlainShortcut,
formatShortcut,
isEditableShortcutTarget,
+ isPortalLayerShortcutTarget,
isReservedShortcut,
isShortcutAllowedForAction,
type ShortcutActionDefinition,
diff --git a/packages/views/inbox/components/inbox-page.test.tsx b/packages/views/inbox/components/inbox-page.test.tsx
index 67ef962768..a5590ca988 100644
--- a/packages/views/inbox/components/inbox-page.test.tsx
+++ b/packages/views/inbox/components/inbox-page.test.tsx
@@ -1,8 +1,13 @@
import { act, fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
+import { toast } from "sonner";
import type { InboxItem } from "@multica/core/types";
import { InboxPage } from "./inbox-page";
+vi.mock("sonner", () => ({
+ toast: { success: vi.fn(), error: vi.fn() },
+}));
+
vi.mock("react-resizable-panels", () => ({
useDefaultLayout: () => ({ defaultLayout: undefined, onLayoutChanged: vi.fn() }),
}));
@@ -34,8 +39,12 @@ vi.mock("@multica/core/paths", () => ({
}),
}));
+const modalState: { modal: string | null; open: ReturnType<typeof vi.fn> } = {
+ modal: null,
+ open: vi.fn(),
+};
vi.mock("@multica/core/modals", () => ({
- useModalStore: { getState: () => ({ open: vi.fn() }) },
+ useModalStore: { getState: () => modalState },
}));
vi.mock("@multica/core/issues/stores/draft-store", () => ({
@@ -54,14 +63,16 @@ vi.mock("@multica/core/inbox/queries", () => ({
// fresh `vi.fn()` per render would make the effect's deps churn.
const markReadMutate = vi.fn();
const markUnreadMutate = vi.fn();
+const archiveMutate = vi.fn();
+const unarchiveMutate = vi.fn();
vi.mock("@multica/core/inbox/mutations", () => {
const mutation = () => ({ mutate: vi.fn() });
return {
useMarkInboxRead: () => ({ mutate: markReadMutate }),
useMarkInboxUnread: () => ({ mutate: markUnreadMutate }),
- useArchiveInbox: mutation,
- useUnarchiveInbox: mutation,
+ useArchiveInbox: () => ({ mutate: archiveMutate }),
+ useUnarchiveInbox: () => ({ mutate: unarchiveMutate }),
useMarkAllInboxRead: mutation,
useArchiveAllInbox: mutation,
useArchiveAllReadInbox: mutation,
@@ -186,6 +197,11 @@ function reset() {
replace.mockClear();
markReadMutate.mockClear();
markUnreadMutate.mockClear();
+ archiveMutate.mockClear();
+ unarchiveMutate.mockClear();
+ modalState.modal = null;
+ vi.mocked(toast.success).mockClear();
+ vi.mocked(toast.error).mockClear();
rowActions = null;
issueDetailProps.length = 0;
layout.width = PHONE;
@@ -407,6 +423,207 @@ describe("InboxPage", () => {
expect(screen.queryByTestId("list")).not.toBeNull();
});
+ function renderWithActiveItem() {
+ reset();
+ layout.width = DESKTOP;
+ listData.active = [item({ id: "inbox-a", issue_id: "issue-a" })];
+ return render(<InboxPage />);
+ }
+
+ function renderWithOpenItem() {
+ const view = renderWithActiveItem();
+ fireEvent.click(screen.getByTestId("row"));
+ return view;
+ }
+
+ describe("archive shortcut", () => {
+ function pressArchiveKey(target: Element | Document = document) {
+ fireEvent.keyDown(target, { key: "e" });
+ }
+
+ function typeArchiveKeyInto(element: Element) {
+ document.body.appendChild(element);
+ pressArchiveKey(element);
+ element.remove();
+ }
+
+ it("archives the open notification", () => {
+ renderWithOpenItem();
+ pressArchiveKey();
+
+ expect(archiveMutate).toHaveBeenCalledWith("inbox-a", expect.anything());
+ });
+
+ it("restores the open notification while reading the archive", () => {
+ reset();
+ layout.width = DESKTOP;
+ searchParams = new URLSearchParams("view=archived");
+ listData.archived = [
+ item({ id: "archived-1", issue_id: "issue-9", archived: true }),
+ ];
+
+ render(<InboxPage />);
+ fireEvent.click(screen.getByTestId("row"));
+ pressArchiveKey();
+
+ expect(unarchiveMutate).toHaveBeenCalledWith("archived-1", expect.anything());
+ expect(archiveMutate).not.toHaveBeenCalled();
+ });
+
+ it("leaves the selection on the next notification", () => {
+ reset();
+ layout.width = DESKTOP;
+ listData.active = [
+ item({ id: "inbox-a", issue_id: "issue-a" }),
+ item({ id: "inbox-b", issue_id: "issue-b" }),
+ ];
+
+ render(<InboxPage />);
+ fireEvent.click(screen.getAllByTestId("row")[0]!);
+ replace.mockClear();
+ pressArchiveKey();
+
+ expect(replace).toHaveBeenCalledWith("/acme/inbox?issue=issue-b");
+ });
+
+ it("does not fire while typing in an editable control", () => {
+ renderWithOpenItem();
+
+ typeArchiveKeyInto(document.createElement("input"));
+ typeArchiveKeyInto(document.createElement("textarea"));
+ const richText = document.createElement("div");
+ richText.setAttribute("contenteditable", "true");
+ typeArchiveKeyInto(richText);
+
+ expect(archiveMutate).not.toHaveBeenCalled();
+ });
+
+ it("stands down while a dialog is open", () => {
+ renderWithOpenItem();
+ modalState.modal = "create-issue";
+ pressArchiveKey();
+
+ expect(archiveMutate).not.toHaveBeenCalled();
+ });
+
+ // Keypresses in portaled popups still reach the page listener, where `e`
+ // is typeahead, not archive.
+ it.each([
+ ["menu", "menuitem"],
+ ["dialog", "button"],
+ ["listbox", "option"],
+ ])("stands down while a portaled %s owns the keyboard", (layerRole, itemRole) => {
+ renderWithOpenItem();
+
+ const layer = document.createElement("div");
+ layer.setAttribute("role", layerRole);
+ const focused = document.createElement("div");
+ focused.setAttribute("role", itemRole);
+ layer.appendChild(focused);
+ document.body.appendChild(layer);
+ pressArchiveKey(focused);
+ layer.remove();
+
+ expect(archiveMutate).not.toHaveBeenCalled();
+ });
+
+ it("stands down while a modal layer holds the page inert", () => {
+ // Base UI marks everything outside a modal popup `data-base-ui-inert`,
+ // even when focus never left the page.
+ const { container } = renderWithOpenItem();
+ container.firstElementChild?.setAttribute("data-base-ui-inert", "");
+ pressArchiveKey();
+
+ expect(archiveMutate).not.toHaveBeenCalled();
+ });
+
+ it("ignores an auto-repeated key", () => {
+ renderWithOpenItem();
+ fireEvent.keyDown(document, { key: "e", repeat: true });
+
+ expect(archiveMutate).not.toHaveBeenCalled();
+ });
+
+ it("ignores a press a nearer handler already consumed", () => {
+ renderWithOpenItem();
+
+ const consumer = document.createElement("button");
+ consumer.addEventListener("keydown", (event) => event.preventDefault());
+ document.body.appendChild(consumer);
+ pressArchiveKey(consumer);
+ consumer.remove();
+
+ expect(archiveMutate).not.toHaveBeenCalled();
+ });
+
+ it("does nothing when no notification is open", () => {
+ renderWithActiveItem();
+ pressArchiveKey();
+
+ expect(archiveMutate).not.toHaveBeenCalled();
+ });
+ });
+
+ // Toasts live in the shared handlers, so every archive surface reports alike.
+ describe("archive feedback", () => {
+ type MutateOptions = {
+ onSuccess?: () => void;
+ onError?: (err: unknown) => void;
+ };
+
+ function settle(
+ spy: typeof archiveMutate,
+ outcome: "success" | "error",
+ err: unknown = new Error("boom"),
+ ) {
+ const options = spy.mock.calls.at(-1)?.[1] as MutateOptions | undefined;
+ act(() => {
+ if (outcome === "success") options?.onSuccess?.();
+ else options?.onError?.(err);
+ });
+ }
+
+ it("confirms an archive from the row action", () => {
+ renderWithActiveItem();
+ act(() => rowActions?.onAction("inbox-a"));
+ settle(archiveMutate, "success");
+
+ expect(toast.success).toHaveBeenCalledTimes(1);
+ });
+
+ it("confirms an archive driven by the shortcut", () => {
+ renderWithOpenItem();
+ fireEvent.keyDown(document, { key: "e" });
+ settle(archiveMutate, "success");
+
+ expect(toast.success).toHaveBeenCalledTimes(1);
+ });
+
+ it("confirms a restore", () => {
+ reset();
+ layout.width = DESKTOP;
+ searchParams = new URLSearchParams("view=archived");
+ listData.archived = [
+ item({ id: "archived-1", issue_id: "issue-9", archived: true }),
+ ];
+
+ render(<InboxPage />);
+ act(() => rowActions?.onAction("archived-1"));
+ settle(unarchiveMutate, "success");
+
+ expect(toast.success).toHaveBeenCalledTimes(1);
+ });
+
+ it("reports a failed archive as a failure only", () => {
+ renderWithActiveItem();
+ act(() => rowActions?.onAction("inbox-a"));
+ settle(archiveMutate, "error");
+
+ expect(toast.error).toHaveBeenCalledTimes(1);
+ expect(toast.success).not.toHaveBeenCalled();
+ });
+ });
+
it("does not swallow a deep link to an issue that is not in the archive", () => {
// ?view=archived&issue=X with an empty archive: the drain effect and the
// unresolved-selection fallback both want to navigate. The fallback must
diff --git a/packages/views/inbox/components/inbox-page.tsx b/packages/views/inbox/components/inbox-page.tsx
index f4f6d3c910..0df26905b0 100644
--- a/packages/views/inbox/components/inbox-page.tsx
+++ b/packages/views/inbox/components/inbox-page.tsx
@@ -6,6 +6,13 @@ import { useQuery } from "@tanstack/react-query";
import { useWorkspaceId } from "@multica/core/hooks";
import { useWorkspacePaths } from "@multica/core/paths";
import { useModalStore } from "@multica/core/modals";
+import {
+ getShortcut,
+ isEditableShortcutTarget,
+ isPortalLayerShortcutTarget,
+ shortcutMatchesEvent,
+} from "@multica/core/shortcuts";
+import { isImeComposing } from "@multica/core/utils";
import { useIssueDraftStore } from "@multica/core/issues/stores/draft-store";
import {
inboxListOptions,
@@ -320,9 +327,11 @@ export function InboxPage() {
setSelectedKey(next ? (next.issue_id ?? next.id) : "");
};
+ // Toasts live in these shared handlers so every archive surface confirms alike.
const handleArchive = (id: string) => {
advanceSelectionPast(id, items);
archiveMutation.mutate(id, {
+ onSuccess: () => toast.success(t(($) => $.toasts.archived)),
onError: (err) =>
toast.error(
err instanceof Error && err.message
@@ -335,6 +344,7 @@ export function InboxPage() {
const handleUnarchive = (id: string) => {
advanceSelectionPast(id, archivedItems);
unarchiveMutation.mutate(id, {
+ onSuccess: () => toast.success(t(($) => $.toasts.unarchived)),
onError: (err) =>
toast.error(
err instanceof Error && err.message
@@ -344,6 +354,30 @@ export function InboxPage() {
});
};
+ // Keep the listener stable while using the latest selected-item action.
+ const actionOnSelectedRef = useRef<(() => void) | null>(null);
+ useEffect(() => {
+ actionOnSelectedRef.current = selected
+ ? () => (isArchivedView ? handleUnarchive(selected.id) : handleArchive(selected.id))
+ : null;
+ });
+
+ useEffect(() => {
+ const onKeyDown = (event: KeyboardEvent) => {
+ if (event.defaultPrevented || event.repeat || isImeComposing(event)) return;
+ if (isEditableShortcutTarget(event.target)) return;
+ if (isPortalLayerShortcutTarget(event.target)) return;
+ if (useModalStore.getState().modal) return;
+ if (!shortcutMatchesEvent(getShortcut("archiveInboxItem"), event)) return;
+ const run = actionOnSelectedRef.current;
+ if (!run) return;
+ event.preventDefault();
+ run();
+ };
+ document.addEventListener("keydown", onKeyDown);
+ return () => document.removeEventListener("keydown", onKeyDown);
+ }, []);
+
// Batch operations
const handleMarkAllRead = () => {
markAllReadMutation.mutate(undefined, {
diff --git a/packages/views/locales/en/inbox.json b/packages/views/locales/en/inbox.json
index f5b5696320..c46c7c5cbb 100644
--- a/packages/views/locales/en/inbox.json
+++ b/packages/views/locales/en/inbox.json
@@ -73,6 +73,10 @@
"created_with_agent": "Created with agent: {{identifier}}",
"failed_with_detail": "Failed: {{detail}}"
},
+ "toasts": {
+ "archived": "Notification archived",
+ "unarchived": "Notification restored"
+ },
"errors": {
"mark_read_failed": "Failed to mark as read",
"mark_unread_failed": "Failed to mark as unread",
diff --git a/packages/views/locales/en/settings.json b/packages/views/locales/en/settings.json
index cce0d5f689..882f4b1ed5 100644
--- a/packages/views/locales/en/settings.json
+++ b/packages/views/locales/en/settings.json
@@ -115,6 +115,7 @@
"toggleChat": { "label": "Toggle chat window", "description": "Open or close the floating chat window. Opening it focuses the message input." },
"findInIssue": { "label": "Find in issue", "description": "Search within the open issue detail." },
"openThreadNav": { "label": "Open thread navigator", "description": "List, search, and jump between the comment threads of the open issue." },
+ "archiveInboxItem": { "label": "Archive notification", "description": "Archive the open inbox notification, or restore it while reading the archive." },
"send": { "label": "Send", "description": "Send chat messages, comments, replies, feedback, and prompts, and create issues in the create dialog." },
"goBack": { "label": "Go back", "description": "Navigate back through history, like a browser." },
"goForward": { "label": "Go forward", "description": "Navigate forward through history, like a browser." },
diff --git a/packages/views/locales/ja/inbox.json b/packages/views/locales/ja/inbox.json
index a8dde2abe8..6b06e84538 100644
--- a/packages/views/locales/ja/inbox.json
+++ b/packages/views/locales/ja/inbox.json
@@ -73,6 +73,10 @@
"created_with_agent": "エージェントで作成: {{identifier}}",
"failed_with_detail": "失敗: {{detail}}"
},
+ "toasts": {
+ "archived": "通知をアーカイブしました",
+ "unarchived": "通知を元に戻しました"
+ },
"errors": {
"mark_read_failed": "既読にできませんでした",
"mark_unread_failed": "未読にできませんでした",
diff --git a/packages/views/locales/ja/settings.json b/packages/views/locales/ja/settings.json
index fe4d7d4fe7..c823d7655e 100644
--- a/packages/views/locales/ja/settings.json
+++ b/packages/views/locales/ja/settings.json
@@ -115,6 +115,7 @@
"toggleChat": { "label": "チャットウィンドウを切り替え", "description": "フローティングチャットを開閉します。開いたときは入力欄にフォーカスします。" },
"findInIssue": { "label": "タスク内を検索", "description": "開いているタスクの詳細を検索します。" },
"openThreadNav": { "label": "スレッドナビゲーターを開く", "description": "開いているタスクのコメントスレッドを一覧・検索して移動します。" },
+ "archiveInboxItem": { "label": "通知をアーカイブ", "description": "開いているインボックス通知をアーカイブします。アーカイブ表示中はアーカイブを解除します。" },
"send": { "label": "送信", "description": "チャット、コメント、返信、フィードバック、プロンプトを送信し、作成ダイアログでタスクを作成します。" },
"goBack": { "label": "戻る", "description": "ブラウザーのように履歴を戻ります。" },
"goForward": { "label": "進む", "description": "ブラウザーのように履歴を進みます。" },
diff --git a/packages/views/locales/ko/inbox.json b/packages/views/locales/ko/inbox.json
index fe07500401..8d203c62ad 100644
--- a/packages/views/locales/ko/inbox.json
+++ b/packages/views/locales/ko/inbox.json
@@ -73,6 +73,10 @@
"created_with_agent": "에이전트가 생성: {{identifier}}",
"failed_with_detail": "실패: {{detail}}"
},
+ "toasts": {
+ "archived": "알림을 보관했습니다",
+ "unarchived": "알림을 복원했습니다"
+ },
"errors": {
"mark_read_failed": "읽음 표시를 하지 못했습니다",
"mark_unread_failed": "읽지 않음 표시를 하지 못했습니다",
diff --git a/packages/views/locales/ko/settings.json b/packages/views/locales/ko/settings.json
index ec25c0d244..c0d2e558be 100644
--- a/packages/views/locales/ko/settings.json
+++ b/packages/views/locales/ko/settings.json
@@ -115,6 +115,7 @@
"toggleChat": { "label": "채팅 창 전환", "description": "플로팅 채팅 창을 열거나 닫습니다. 열면 메시지 입력란에 포커스합니다." },
"findInIssue": { "label": "태스크에서 찾기", "description": "열린 태스크 상세 내용에서 검색합니다." },
"openThreadNav": { "label": "스레드 내비게이터 열기", "description": "열린 태스크의 댓글 스레드를 나열하고 검색해 이동합니다." },
+ "archiveInboxItem": { "label": "알림 보관", "description": "열린 인박스 알림을 보관합니다. 보관함을 보는 중에는 보관을 해제합니다." },
"send": { "label": "보내기", "description": "채팅, 댓글, 답글, 피드백 및 프롬프트를 보내고, 생성 대화상자에서 태스크를 만듭니다." },
"goBack": { "label": "뒤로 가기", "description": "브라우저처럼 기록을 따라 뒤로 이동합니다." },
"goForward": { "label": "앞으로 가기", "description": "브라우저처럼 기록을 따라 앞으로 이동합니다." },
diff --git a/packages/views/locales/zh-Hans/inbox.json b/packages/views/locales/zh-Hans/inbox.json
index 86a48de61a..63b684b84f 100644
--- a/packages/views/locales/zh-Hans/inbox.json
+++ b/packages/views/locales/zh-Hans/inbox.json
@@ -73,6 +73,10 @@
"created_with_agent": "通过智能体创建:{{identifier}}",
"failed_with_detail": "失败:{{detail}}"
},
+ "toasts": {
+ "archived": "已归档通知",
+ "unarchived": "已恢复通知"
+ },
"errors": {
"mark_read_failed": "标为已读失败",
"mark_unread_failed": "标为未读失败",
diff --git a/packages/views/locales/zh-Hans/settings.json b/packages/views/locales/zh-Hans/settings.json
index 854cb7ed3e..f2a9ce39dd 100644
--- a/packages/views/locales/zh-Hans/settings.json
+++ b/packages/views/locales/zh-Hans/settings.json
@@ -115,6 +115,7 @@
"toggleChat": { "label": "显示或隐藏聊天窗", "description": "打开或关闭悬浮聊天窗,打开时自动聚焦输入框。" },
"findInIssue": { "label": "在任务中查找", "description": "搜索当前打开的任务详情。" },
"openThreadNav": { "label": "打开讨论导航", "description": "列出、搜索并跳转当前任务的评论讨论。" },
+ "archiveInboxItem": { "label": "归档通知", "description": "归档当前打开的收件箱通知;在归档列表中则取消归档。" },
"send": { "label": "发送", "description": "发送聊天消息、评论、回复、反馈和提示词,并在创建弹窗中创建任务。" },
"goBack": { "label": "后退", "description": "像浏览器一样在历史记录中后退。" },
"goForward": { "label": "前进", "description": "像浏览器一样在历史记录中前进。" },