Skip to content

Commit df67a5f

Browse files
fix(search): open PR thread lookup in the command palette
1 parent 5a88404 commit df67a5f

5 files changed

Lines changed: 44 additions & 49 deletions

File tree

‎apps/web/src/commandPaletteBus.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const COMMAND_PALETTE_OPEN_EVENT = "t3code:open-command-palette";
44

55
export interface CommandPaletteOpenDetail {
6+
readonly query?: string;
67
readonly open?: "add-project" | "new-thread-in";
78
}
89

‎apps/web/src/components/CommandPalette.logic.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ describe("reduceCommandPaletteUiState", () => {
6464
});
6565
});
6666

67+
it("opens a supplied search from another overlay and clears it on close", () => {
68+
const query = "https://github.com/pingdotgg/t3code/pull/10636";
69+
const opened = reduceCommandPaletteUiState(
70+
{ open: true, mode: "files", openIntent: null },
71+
{ _tag: "OpenSearch", query },
72+
);
73+
expect(opened).toEqual({ open: true, mode: "command", openIntent: { kind: "search", query } });
74+
expect(
75+
reduceCommandPaletteUiState(opened, { _tag: "SetOpen", open: false }).openIntent,
76+
).toBeNull();
77+
});
78+
6779
it("preserves the mode on close and resets it on open", () => {
6880
const filesOpen = reduceCommandPaletteUiState(closedState, {
6981
_tag: "ToggleMode",

‎apps/web/src/components/CommandPalette.logic.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export function browseInputEndPaddingClass(input: {
3939
*/
4040
export type SearchOverlayMode = "command" | "files" | "content";
4141

42-
export interface CommandPaletteOpenIntent {
43-
readonly kind: "add-project" | "new-thread-in";
44-
}
42+
export type CommandPaletteOpenIntent =
43+
| { readonly kind: "add-project" | "new-thread-in" }
44+
| { readonly kind: "search"; readonly query: string };
4545

4646
export interface CommandPaletteUiState {
4747
readonly open: boolean;
@@ -52,6 +52,7 @@ export interface CommandPaletteUiState {
5252
export type CommandPaletteUiAction =
5353
| { readonly _tag: "SetOpen"; readonly open: boolean }
5454
| { readonly _tag: "ToggleMode"; readonly mode: SearchOverlayMode }
55+
| { readonly _tag: "OpenSearch"; readonly query: string }
5556
| { readonly _tag: "OpenAddProject" }
5657
| { readonly _tag: "OpenNewThreadIn" }
5758
| { readonly _tag: "ClearOpenIntent" };
@@ -69,6 +70,8 @@ export function reduceCommandPaletteUiState(
6970
return state.open && state.mode === action.mode
7071
? { ...state, open: false, openIntent: null }
7172
: { open: true, mode: action.mode, openIntent: null };
73+
case "OpenSearch":
74+
return { open: true, mode: "command", openIntent: { kind: "search", query: action.query } };
7275
case "OpenAddProject":
7376
return { open: true, mode: "command", openIntent: { kind: "add-project" } };
7477
case "OpenNewThreadIn":

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ export function CommandPalette({ children }: { children: ReactNode }) {
482482
openNewThreadIn();
483483
} else if (detail.open === "add-project") {
484484
openAddProject();
485+
} else if (detail.query !== undefined) {
486+
dispatch({ _tag: "OpenSearch", query: detail.query });
485487
} else {
486488
setOpen(true);
487489
}
@@ -1496,6 +1498,13 @@ function OpenCommandPaletteDialog(props: {
14961498
startAddProjectSourceSelection,
14971499
]);
14981500

1501+
useLayoutEffect(() => {
1502+
if (openIntent?.kind !== "search") return;
1503+
setViewStack([]);
1504+
setQuery(openIntent.query);
1505+
clearOpenIntent();
1506+
}, [clearOpenIntent, openIntent]);
1507+
14991508
useLayoutEffect(() => {
15001509
if (openIntent?.kind !== "add-project") {
15011510
return;

‎apps/web/src/components/pullRequest/PullRequestThreadLinks.tsx‎

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2-
import { Link } from "@tanstack/react-router";
2+
import { openCommandPalette } from "~/commandPaletteBus";
33
import type { EnvironmentId, PullRequestRef, ScopedThreadRef, ThreadId } from "@t3tools/contracts";
44
import { CheckIcon, LinkIcon, MessageSquareIcon, UnlinkIcon } from "lucide-react";
55
import { useState } from "react";
@@ -10,11 +10,10 @@ import { parseChangeRequestUrl } from "~/lib/openPullRequestLink";
1010
import { useProjects, useServerConfigs, useThreadShell, useThreadShells } from "~/state/entities";
1111
import { pullRequestEnvironment } from "~/state/pullRequests";
1212
import { useEnvironmentQuery } from "~/state/query";
13-
import { buildThreadRouteParams } from "~/threadRoutes";
1413
import { Button } from "../ui/button";
1514
import { Command, CommandInput, CommandItem, CommandList } from "../ui/command";
1615
import { Dialog, DialogPopup, DialogTitle } from "../ui/dialog";
17-
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
16+
import { MenuItem } from "../ui/menu";
1817
import { toastManager } from "../ui/toast";
1918

2019
interface PullRequestThreadLinksProps {
@@ -59,8 +58,7 @@ function EnabledPullRequestThreadLinks({
5958
})
6059
: null,
6160
);
62-
// Refreshes can briefly clear the query value. Keep the last response so polling
63-
// does not unmount an open menu or move its highlighted thread.
61+
// Keep the count stable while its query refreshes.
6462
const [lastRelations, setLastRelations] = useState(relations.data);
6563
if (relations.data !== null && relations.data !== lastRelations) {
6664
setLastRelations(relations.data);
@@ -96,47 +94,19 @@ function EnabledPullRequestThreadLinks({
9694
return (
9795
<>
9896
{display === "count" && (linkedThreads.length > 0 || relations.error !== null) ? (
99-
<Menu>
100-
<MenuTrigger
101-
render={
102-
<Button
103-
size="xs"
104-
variant="ghost"
105-
aria-label={linkedThreadsLabel}
106-
title={linkedThreadsLabel}
107-
/>
108-
}
109-
>
110-
<MessageSquareIcon aria-hidden className="size-3.5" />
111-
<span className="@max-[40rem]/pr-header:hidden">{linkedThreadsLabel}</span>
112-
<span aria-hidden className="hidden @max-[40rem]/pr-header:inline">
113-
{linkedThreads.length || "?"}
114-
</span>
115-
</MenuTrigger>
116-
<MenuPopup align="end" className="max-h-72 max-w-80 overflow-y-auto">
117-
{relations.error !== null ? (
118-
<MenuItem onClick={relations.refresh}>Could not load linked threads. Retry</MenuItem>
119-
) : null}
120-
{linkedThreads.map((linkedThread) => (
121-
<MenuItem
122-
key={linkedThread.id}
123-
render={
124-
<Link
125-
to="/$environmentId/$threadId"
126-
params={buildThreadRouteParams(scopeThreadRef(environmentId, linkedThread.id))}
127-
/>
128-
}
129-
>
130-
<span className="min-w-0 flex-1 truncate">
131-
{linkedThread.title || "Untitled thread"}
132-
</span>
133-
{linkedThread.archivedAt !== null ? (
134-
<span className="text-xs text-muted-foreground">Archived</span>
135-
) : null}
136-
</MenuItem>
137-
))}
138-
</MenuPopup>
139-
</Menu>
97+
<Button
98+
size="xs"
99+
variant="ghost"
100+
aria-label={linkedThreadsLabel}
101+
title={linkedThreadsLabel}
102+
onClick={() => openCommandPalette({ query: url })}
103+
>
104+
<MessageSquareIcon aria-hidden className="size-3.5" />
105+
<span className="@max-[40rem]/pr-header:hidden">{linkedThreadsLabel}</span>
106+
<span aria-hidden className="hidden @max-[40rem]/pr-header:inline">
107+
{linkedThreads.length || "?"}
108+
</span>
109+
</Button>
140110
) : null}
141111
{display === "menu-item" ? (
142112
<MenuItem

0 commit comments

Comments
 (0)