Skip to content

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

Go

feat(search): jump to views from the Cmd+K palette (MUL-9342) (#10678)

Jiayuan Zhang314f2cc5fa70
diff --git a/packages/views/locales/en/search.json b/packages/views/locales/en/search.json
index fda9ebe553..daa86514cd 100644
--- a/packages/views/locales/en/search.json
+++ b/packages/views/locales/en/search.json
@@ -6,6 +6,7 @@
"breadcrumb_aria": "Current menu",
"groups": {
"pages": "Pages",
+ "views": "Views",
"commands": "Commands",
"members": "Members",
"agents": "Agents",
diff --git a/packages/views/locales/es/search.json b/packages/views/locales/es/search.json
index 21a31369f2..9394225be3 100644
--- a/packages/views/locales/es/search.json
+++ b/packages/views/locales/es/search.json
@@ -4,6 +4,7 @@
"placeholder": "Busca o escribe lo que necesitas hacer...",
"groups": {
"pages": "Páginas",
+ "views": "Vistas",
"commands": "Comandos",
"members": "Miembros",
"projects": "Proyectos",
diff --git a/packages/views/locales/fr/search.json b/packages/views/locales/fr/search.json
index 3e045fcb2e..72cb128b76 100644
--- a/packages/views/locales/fr/search.json
+++ b/packages/views/locales/fr/search.json
@@ -6,6 +6,7 @@
"breadcrumb_aria": "Menu actuel",
"groups": {
"pages": "Pages",
+ "views": "Vues",
"commands": "Commandes",
"members": "Membres",
"agents": "Agents",
diff --git a/packages/views/locales/ja/search.json b/packages/views/locales/ja/search.json
index 722dcd0fa2..c2dbf9f2b1 100644
--- a/packages/views/locales/ja/search.json
+++ b/packages/views/locales/ja/search.json
@@ -6,6 +6,7 @@
"breadcrumb_aria": "現在のメニュー",
"groups": {
"pages": "ページ",
+ "views": "ビュー",
"commands": "コマンド",
"members": "メンバー",
"agents": "エージェント",
diff --git a/packages/views/locales/ko/search.json b/packages/views/locales/ko/search.json
index c571c2a71a..029ec70905 100644
--- a/packages/views/locales/ko/search.json
+++ b/packages/views/locales/ko/search.json
@@ -6,6 +6,7 @@
"breadcrumb_aria": "현재 메뉴",
"groups": {
"pages": "페이지",
+ "views": "뷰",
"commands": "명령어",
"members": "멤버",
"agents": "에이전트",
diff --git a/packages/views/locales/ru/search.json b/packages/views/locales/ru/search.json
index 29f3be0e90..3113097a8c 100644
--- a/packages/views/locales/ru/search.json
+++ b/packages/views/locales/ru/search.json
@@ -6,6 +6,7 @@
"breadcrumb_aria": "Текущее меню",
"groups": {
"pages": "Страницы",
+ "views": "Представления",
"commands": "Команды",
"members": "Участники",
"agents": "Агенты",
diff --git a/packages/views/locales/zh-Hans/search.json b/packages/views/locales/zh-Hans/search.json
index 3e2eed3875..f9a9e8bdba 100644
--- a/packages/views/locales/zh-Hans/search.json
+++ b/packages/views/locales/zh-Hans/search.json
@@ -6,6 +6,7 @@
"breadcrumb_aria": "当前菜单",
"groups": {
"pages": "页面",
+ "views": "视图",
"commands": "命令",
"members": "成员",
"agents": "智能体",
diff --git a/packages/views/locales/zh-Hant/search.json b/packages/views/locales/zh-Hant/search.json
index 795f216b28..8961bc0717 100644
--- a/packages/views/locales/zh-Hant/search.json
+++ b/packages/views/locales/zh-Hant/search.json
@@ -6,6 +6,7 @@
"breadcrumb_aria": "目前選單",
"groups": {
"pages": "頁面",
+ "views": "檢視",
"commands": "命令",
"members": "成員",
"agents": "AI 代理",
diff --git a/packages/views/search/palette-context.tsx b/packages/views/search/palette-context.tsx
index e4a86be9c2..d3029bb130 100644
--- a/packages/views/search/palette-context.tsx
+++ b/packages/views/search/palette-context.tsx
@@ -6,8 +6,11 @@ import type { PaletteHostDialog, PaletteStackEntry } from "./types";
export interface PaletteApi {
close: () => void;
push: (entry: PaletteStackEntry) => void;
- /** Navigate honoring the gesture's modifiers (⌘↵ / ⌘-click open a new tab), then close. */
- navigate: (href: string) => void;
+ /**
+ * Navigate honoring the gesture's modifiers (⌘↵ / ⌘-click open a new tab), then close.
+ * `onNavigateInPlace` has AppLink's contract: it runs only when this tab navigates.
+ */
+ navigate: (href: string, onNavigateInPlace?: () => void) => void;
/** Close the palette and open a confirm or form dialog it hosts. */
openHostDialog: (dialog: PaletteHostDialog) => void;
}
diff --git a/packages/views/search/root-view.tsx b/packages/views/search/root-view.tsx
index 42fed46cb8..c4a3e80f17 100644
--- a/packages/views/search/root-view.tsx
+++ b/packages/views/search/root-view.tsx
@@ -1,16 +1,21 @@
"use client";
import type { ReactNode } from "react";
-import { Clock, Loader2, MessageSquare, Sparkles, SquarePen, UserPlus, Zap, type IconComponent } from "@multica/ui/icons";
+import { Clock, Layers, Loader2, MessageSquare, Sparkles, SquarePen, UserPlus, Zap, type IconComponent } from "@multica/ui/icons";
import { Command as CommandPrimitive } from "cmdk";
import { useQuery } from "@tanstack/react-query";
+import { useWorkspaceId } from "@multica/core/hooks";
import { inboxUnreadSummaryOptions, unreadWorkspaceIds } from "@multica/core/inbox/queries";
+import { useActiveIssueViewStore } from "@multica/core/issue-views/active-view-store";
+import { issueViewTarget } from "@multica/core/issue-views/view-target";
import { paths, useWorkspacePaths } from "@multica/core/paths";
+import { projectListOptions } from "@multica/core/projects/queries";
import type { InboxWorkspaceUnread } from "@multica/core/types";
import { openCreateIssueWithPreference } from "@multica/core/issues/stores";
import { useModalStore } from "@multica/core/modals";
import { cn } from "@multica/ui/lib/utils";
import { ActorAvatar } from "../common/actor-avatar";
+import { BUILTIN_VIEW_ICON, useBuiltinViewNavigation } from "../issue-views/builtin-views";
import { routeIconForPath } from "../layout/route-icon-components";
import { ProjectIcon } from "../projects/components/project-icon";
import { WorkspaceAvatar } from "../workspace/workspace-avatar";
@@ -21,6 +26,7 @@ import { usePalette } from "./palette-context";
import { CommandGroupView, CommandRow, PaletteGroup, ROW_CLASS, ROW_ICON_CLASS, RowHint } from "./rows";
import { ActorRow, AgentPresenceText, IssueResultRow, ObjectRow, ProjectResultRow } from "./result-rows";
import type { IssueTarget } from "./types";
+import type { PaletteView } from "./use-object-search";
import type { BestMatch, HandToAgentSeed, RootModel } from "./use-root-model";
const EMPTY_UNREAD_SUMMARY: InboxWorkspaceUnread[] = [];
@@ -29,6 +35,7 @@ const EMPTY_UNREAD_SUMMARY: InboxWorkspaceUnread[] = [];
const TYPE_ORDER = [
"context",
"pages",
+ "views",
"commands",
"agents",
"squads",
@@ -109,6 +116,24 @@ export function RootView({ model, rawQuery }: { model: RootModel; rawQuery: stri
),
});
}
+ if (objects.views.length > 0) {
+ groups.push({
+ key: "views",
+ type: "views",
+ score: objects.views[0]!.score,
+ node: (
+ <PaletteGroup key="views" heading={t(($) => $.groups.views)}>
+ {objects.views.map(({ item }) => (
+ <ViewResultRow
+ key={item.kind === "builtin" ? `builtin:${item.key}` : item.view.id}
+ view={item}
+ query={query}
+ />
+ ))}
+ </PaletteGroup>
+ ),
+ });
+ }
if (model.commands.length > 0) {
groups.push({
key: "commands",
@@ -401,6 +426,52 @@ export function RootView({ model, rawQuery }: { model: RootModel; rawQuery: stri
);
}
+/**
+ * Opens a view the way its sidebar row does: the view's link, and the
+ * active-view write that makes an already-open page switch to it.
+ */
+function ViewResultRow({ view, query }: { view: PaletteView; query: string }) {
+ const { t } = useT("issues");
+ const palette = usePalette();
+ const wsId = useWorkspaceId();
+ const p = useWorkspacePaths();
+ const builtinNav = useBuiltinViewNavigation();
+ const setActive = useActiveIssueViewStore((s) => s.setActive);
+ const projectId = view.kind === "view" && view.view.scope_type === "project" ? (view.view.scope_id ?? null) : null;
+ const { data: projects } = useQuery({ ...projectListOptions(wsId), enabled: !!projectId });
+
+ if (view.kind === "builtin") {
+ const { key } = view;
+ return (
+ <ObjectRow
+ value={`view:builtin:${key}`}
+ icon={<span className="flex text-muted-foreground">{BUILTIN_VIEW_ICON[key]}</span>}
+ title={view.name}
+ query={query}
+ onSelect={() => palette.navigate(builtinNav.hrefFor(key), () => builtinNav.prepare(key))}
+ />
+ );
+ }
+
+ const saved = view.view;
+ const target = issueViewTarget(wsId, saved, p);
+ const location = projectId
+ ? (projects?.find((project) => project.id === projectId)?.title ?? t(($) => $.views.directory.location_project))
+ : saved.scope_type === "my"
+ ? t(($) => $.views.builtin.my_issues)
+ : t(($) => $.views.builtin.all_issues);
+ return (
+ <ObjectRow
+ value={`view:${saved.id}`}
+ icon={<Layers className={ROW_ICON_CLASS} />}
+ title={view.name}
+ query={query}
+ detail={location}
+ onSelect={() => palette.navigate(target.href, () => setActive(target.containerKey, saved.id))}
+ />
+ );
+}
+
/**
* Always the last row while there is input, so ↵ on a result never turns into
* a write. It only opens quick create, prefilled; the user confirms there.
diff --git a/packages/views/search/search-command.test.tsx b/packages/views/search/search-command.test.tsx
index efb445508c..390c1fb3fb 100644
--- a/packages/views/search/search-command.test.tsx
+++ b/packages/views/search/search-command.test.tsx
@@ -10,6 +10,9 @@ import {
type CommandBarContext,
} from "@multica/core/command-bar";
import { inboxUnreadSummaryOptions } from "@multica/core/inbox/queries";
+import { useActiveIssueViewStore } from "@multica/core/issue-views/active-view-store";
+import { issueViewEverywhereOptions } from "@multica/core/issue-views/queries";
+import { projectListOptions } from "@multica/core/projects/queries";
import { I18nProvider } from "@multica/core/i18n/react";
import { issueDetailOptions, issueTimelineOptions } from "@multica/core/issues/queries";
import { WORKSPACE_PAGES } from "@multica/core/paths";
@@ -799,6 +802,89 @@ describe("SearchCommand", () => {
});
});
+ describe("views", () => {
+ const makeView = (id: string, name: string, over: Record<string, unknown> = {}) => ({
+ id,
+ workspace_id: "ws-test",
+ owner_id: ME,
+ name,
+ scope_type: "workspace",
+ scope_id: null,
+ visibility: "private",
+ query: {},
+ display: {},
+ ...over,
+ });
+
+ beforeEach(() => {
+ act(() => useActiveIssueViewStore.setState({ active: {} }));
+ seed(issueViewEverywhereOptions("ws-test"), [
+ makeView("view-bugs", "Open bugs"),
+ makeView("view-launch", "Launch blockers", { scope_type: "project", scope_id: "proj-1" }),
+ ]);
+ seed(projectListOptions("ws-test"), { projects: [{ id: "proj-1", title: "Website" }] });
+ });
+
+ const viewRows = () => within(screen.getByRole("group", { name: "Views" })).getAllByRole("option");
+
+ it("opens a saved view on its surface and makes it the active view", async () => {
+ const user = userEvent.setup();
+ renderSearch();
+ await user.type(input(), "open bugs");
+ fireEvent.click(await rowText("Open bugs"));
+
+ expect(mockPush).toHaveBeenCalledWith("/ws-test/issues?view=view-bugs");
+ expect(useActiveIssueViewStore.getState().active).toEqual({ "ws-test:workspace": "view-bugs" });
+ expect(useSearchStore.getState().open).toBe(false);
+ });
+
+ it("names the project a project view opens in", async () => {
+ const user = userEvent.setup();
+ renderSearch();
+ await user.type(input(), "launch");
+
+ await waitFor(() => expect(viewRows()[0]).toHaveTextContent("Launch blockersWebsite"));
+ fireEvent.click(viewRows()[0]!);
+ expect(mockPush).toHaveBeenCalledWith("/ws-test/projects/proj-1?view=view-launch");
+ });
+
+ it("opens a built-in view", async () => {
+ const user = userEvent.setup();
+ renderSearch();
+ await user.type(input(), "working");
+ fireEvent.click(await rowText("Working"));
+
+ expect(mockPush).toHaveBeenCalledWith("/ws-test/issues?view=working");
+ expect(useActiveIssueViewStore.getState().active).toEqual({ "ws-test:workspace": "working" });
+ });
+
+ it('lists every view under the Views page for "views"', async () => {
+ const user = userEvent.setup();
+ renderSearch();
+ await user.type(input(), "views");
+
+ await waitFor(() => expect(viewRows()).toHaveLength(6));
+ expect(renderedValues().indexOf("page:views")).toBeLessThan(renderedValues().indexOf("view:view-bugs"));
+ });
+
+ it("leaves this tab's active view alone when the view opens in a new tab", async () => {
+ const user = userEvent.setup();
+ const open = vi.spyOn(window, "open").mockReturnValue(null);
+ renderSearch();
+ await user.type(input(), "open bugs");
+ fireEvent.click(await rowText("Open bugs"), { metaKey: true });
+
+ expect(open).toHaveBeenCalledWith(
+ "https://app.multica//ws-test/issues?view=view-bugs",
+ "_blank",
+ "noopener,noreferrer",
+ );
+ expect(mockPush).not.toHaveBeenCalled();
+ expect(useActiveIssueViewStore.getState().active).toEqual({});
+ open.mockRestore();
+ });
+ });
+
describe("current agent", () => {
it("opens the agent's settings when 'settings' is typed", async () => {
const user = userEvent.setup();
diff --git a/packages/views/search/search-command.tsx b/packages/views/search/search-command.tsx
index 6fb2817386..6b17969fe7 100644
--- a/packages/views/search/search-command.tsx
+++ b/packages/views/search/search-command.tsx
@@ -105,9 +105,11 @@ function PaletteBody({
() => ({
close,
push,
- navigate: (href) => {
+ navigate: (href, onNavigateInPlace) => {
close();
- intentNavigate(href, consumeIntent());
+ const intent = consumeIntent();
+ if (intent === "push") onNavigateInPlace?.();
+ intentNavigate(href, intent);
},
openHostDialog,
}),
diff --git a/packages/views/search/use-object-search.ts b/packages/views/search/use-object-search.ts
index 6a0f974606..9573704cc9 100644
--- a/packages/views/search/use-object-search.ts
+++ b/packages/views/search/use-object-search.ts
@@ -5,7 +5,10 @@ import { useQuery } from "@tanstack/react-query";
import { autopilotListOptions } from "@multica/core/autopilots/queries";
import { chatSessionsOptions } from "@multica/core/chat/queries";
import { useWorkspaceId } from "@multica/core/hooks";
+import { issueViewEverywhereOptions } from "@multica/core/issue-views/queries";
+import { BUILTIN_VIEW_KEYS, type BuiltinViewKey } from "@multica/core/issue-views/sidebar-views";
import { skillListOptions, workspaceListOptions } from "@multica/core/workspace/queries";
+import type { IssueView } from "@multica/core/api/schemas";
import type {
Autopilot,
ChatSession,
@@ -13,6 +16,7 @@ import type {
SkillSummary,
Workspace,
} from "@multica/core/types";
+import { useBuiltinViewLabel } from "../issue-views/builtin-views";
import { scoreRow, scoreText } from "./matching";
import { useActorDirectory, type AgentEntry, type SquadEntry } from "./use-actor-directory";
@@ -21,10 +25,16 @@ export interface Scored<T> {
score: number;
}
+/** A built-in view, or a saved view the user can open. */
+export type PaletteView =
+ | { kind: "builtin"; key: BuiltinViewKey; name: string }
+ | { kind: "view"; view: IssueView; name: string };
+
export interface ObjectHits {
agents: Scored<AgentEntry>[];
squads: Scored<SquadEntry>[];
members: Scored<MemberWithUser>[];
+ views: Scored<PaletteView>[];
autopilots: Scored<Autopilot>[];
chats: Scored<ChatSession>[];
skills: Scored<SkillSummary>[];
@@ -34,12 +44,15 @@ export interface ObjectHits {
const EMPTY_AUTOPILOTS: Autopilot[] = [];
const EMPTY_CHATS: ChatSession[] = [];
const EMPTY_SKILLS: SkillSummary[] = [];
+const EMPTY_VIEWS: IssueView[] = [];
const EMPTY_WORKSPACES: Workspace[] = [];
// Hidden aliases for the Workspaces group, prefix-matched like page keywords:
// typing "workspace" lists every workspace the user can switch to.
const WORKSPACE_KEYWORDS = ["switch", "workspace"];
const ALL_MEMBERS_WORDS = ["members", "people", "users", "team"];
+// Typing "views" lists every view under the Views page row.
+const ALL_VIEWS_WORDS = ["views", "视图"];
function rank<T>(items: readonly T[], score: (item: T) => number, limit: number): Scored<T>[] {
return items
@@ -58,15 +71,24 @@ function memberScore(member: MemberWithUser, query: string): number {
return 0;
}
+function viewScore(view: PaletteView, query: string): number {
+ const byName = scoreText(view.name, query);
+ if (byName > 0) return byName;
+ if (query.length >= 2 && ALL_VIEWS_WORDS.some((word) => word.startsWith(query))) return 20;
+ return 0;
+}
+
/**
* Client-side search over the workspace lists the app already caches. Lists
- * the palette does not otherwise need (autopilots, chats, skills) load only
- * once the user types.
+ * the palette does not otherwise need (views, autopilots, chats, skills) load
+ * only once the user types.
*/
export function useObjectSearch(query: string, open: boolean): ObjectHits & { directory: ReturnType<typeof useActorDirectory> } {
const wsId = useWorkspaceId();
const directory = useActorDirectory(open);
const typing = open && query.length > 0;
+ const builtinLabel = useBuiltinViewLabel();
+ const { data: savedViews = EMPTY_VIEWS } = useQuery({ ...issueViewEverywhereOptions(wsId), enabled: typing && !!wsId });
const { data: autopilots = EMPTY_AUTOPILOTS } = useQuery({ ...autopilotListOptions(wsId), enabled: typing });
const { data: chats = EMPTY_CHATS } = useQuery({ ...chatSessionsOptions(wsId), enabled: typing });
const { data: skills = EMPTY_SKILLS } = useQuery({ ...skillListOptions(wsId), enabled: typing });
@@ -74,14 +96,23 @@ export function useObjectSearch(query: string, open: boolean): ObjectHits & { di
// holds, so the Workspaces group adds no request of its own.
const { data: workspaces = EMPTY_WORKSPACES } = useQuery(workspaceListOptions());
+ const views = useMemo<PaletteView[]>(
+ () => [
+ ...BUILTIN_VIEW_KEYS.map((key) => ({ kind: "builtin" as const, key, name: builtinLabel(key) })),
+ ...savedViews.map((view) => ({ kind: "view" as const, view, name: view.name })),
+ ],
+ [builtinLabel, savedViews],
+ );
+
const hits = useMemo<ObjectHits>(() => {
if (!query) {
- return { agents: [], squads: [], members: [], autopilots: [], chats: [], skills: [], workspaces: [] };
+ return { agents: [], squads: [], members: [], views: [], autopilots: [], chats: [], skills: [], workspaces: [] };
}
return {
agents: rank(directory.agents, (e) => scoreText(e.agent.name, query), 8),
squads: rank(directory.squads, (e) => scoreText(e.squad.name, query), 5),
members: rank(directory.members, (m) => memberScore(m, query), 10),
+ views: rank(views, (v) => viewScore(v, query), 8),
autopilots: rank(
autopilots.filter((a) => a.status !== "archived"),
(a) => scoreText(a.title, query),
@@ -102,7 +133,7 @@ export function useObjectSearch(query: string, open: boolean): ObjectHits & { di
50,
),
};
- }, [autopilots, chats, directory, query, skills, workspaces, wsId]);
+ }, [autopilots, chats, directory, query, skills, views, workspaces, wsId]);
return { ...hits, directory };
}
diff --git a/packages/views/search/use-root-model.ts b/packages/views/search/use-root-model.ts
index 31ad4fbab1..5f39ca3f53 100644
--- a/packages/views/search/use-root-model.ts
+++ b/packages/views/search/use-root-model.ts
@@ -229,6 +229,7 @@ export function useRootModel(
agents: people ? objects.agents : [],
squads: people ? objects.squads : [],
members: people ? objects.members : [],
+ views: scope === "all" ? objects.views : [],
autopilots: scope === "all" ? objects.autopilots : [],
chats: scope === "all" ? objects.chats : [],
skills: scope === "all" ? objects.skills : [],
@@ -259,6 +260,7 @@ export function useRootModel(
visibleObjects.agents.length +
visibleObjects.squads.length +
visibleObjects.members.length +
+ visibleObjects.views.length +
visibleObjects.autopilots.length +
visibleObjects.chats.length +
visibleObjects.skills.length +