feat(command-palette): show environments in search results (#10722)

This commit is contained in:
Justin Nel authored and GitHub committed 2026-09-10 23:50:28 +00:00
1 parent 2afa02a280
commit c52b8d96e4
4 files changed
+211 -3

No files matched your search

@@ -3,6 +3,7 @@ import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools
import type { Project, Thread } from "../types";
import {
buildBrowseGroups,
buildCommandPaletteProjectMetadata,
buildProjectActionItems,
buildThreadActionItems,
buildLinkedThreadActionItems,
@@ -55,6 +56,124 @@ describe("linked pull request thread navigation", () => {
});
});
describe("buildCommandPaletteProjectMetadata", () => {
const localEnvironmentId = EnvironmentId.make("environment-local");
const remoteEnvironmentId = EnvironmentId.make("environment-build-box");
const locations = new Map([
[localEnvironmentId, { kind: "local" as const, label: "Local", machine: "laptop" as const }],
[
remoteEnvironmentId,
{ kind: "remote" as const, label: "Build box", machine: "server" as const },
],
]);
it("makes every member environment and path searchable", () => {
const metadata = buildCommandPaletteProjectMetadata({
projects: [
{
environmentId: localEnvironmentId,
title: "T3 Code",
workspaceRoot: "/Users/theo/Projects/t3code",
},
{
environmentId: remoteEnvironmentId,
title: "t3code",
workspaceRoot: "/srv/t3code",
},
],
locationByEnvironmentId: locations,
});
expect(metadata.searchTerms).toEqual([
"T3 Code",
"/Users/theo/Projects/t3code",
"Local",
"t3code",
"/srv/t3code",
"Build box",
]);
expect(metadata.environmentLabels).toEqual(["Local", "Build box"]);
const [filteredGroup] = filterCommandPaletteGroups({
activeGroups: [],
query: "build box",
isInSubmenu: false,
projectSearchItems: [
{
kind: "action",
value: "project:t3code",
title: "T3 Code",
searchTerms: metadata.searchTerms,
icon: null,
run: async () => undefined,
},
],
threadSearchItems: [],
});
expect(filteredGroup?.items).toHaveLength(1);
});
it("deduplicates grouped checkouts by environment", () => {
const metadata = buildCommandPaletteProjectMetadata({
projects: [
{
environmentId: remoteEnvironmentId,
title: "T3 Code",
workspaceRoot: "/srv/t3code",
},
{
environmentId: remoteEnvironmentId,
title: "T3 Code worktree",
workspaceRoot: "/srv/t3code-feature",
},
],
locationByEnvironmentId: locations,
});
expect(metadata.environmentLabels).toEqual(["Build box"]);
});
it("deduplicates distinct environments with the same label", () => {
const secondRemoteEnvironmentId = EnvironmentId.make("environment-build-box-2");
const metadata = buildCommandPaletteProjectMetadata({
projects: [
{
environmentId: remoteEnvironmentId,
title: "T3 Code",
workspaceRoot: "/srv/t3code",
},
{
environmentId: secondRemoteEnvironmentId,
title: "T3 Code mirror",
workspaceRoot: "/srv/mirror/t3code",
},
],
locationByEnvironmentId: new Map([
[remoteEnvironmentId, { label: "Build box" }],
[secondRemoteEnvironmentId, { label: "Build box" }],
]),
});
expect(metadata.environmentLabels).toEqual(["Build box"]);
});
it("uses a human-readable fallback when presentation data is unavailable", () => {
const metadata = buildCommandPaletteProjectMetadata({
projects: [
{
environmentId: remoteEnvironmentId,
title: "T3 Code",
workspaceRoot: "/srv/t3code",
},
],
locationByEnvironmentId: new Map(),
});
expect(metadata.searchTerms).toContain("Remote");
expect(metadata.environmentLabels).toEqual(["Remote"]);
});
});
describe("reduceCommandPaletteUiState", () => {
const closedState = { open: false, mode: "command", openIntent: null } as const;
@@ -1,6 +1,7 @@
import { threadPullRequestSearchTerms } from "@t3tools/shared/threadPullRequests";
import type { CommandPaletteLinkedThreads } from "../commandPaletteBus";
import {
type EnvironmentId,
type FilesystemBrowseEntry,
type KeybindingCommand,
THREAD_JUMP_KEYBINDING_COMMANDS,
@@ -185,6 +186,22 @@ export type CommandPaletteMode = "root" | "root-browse" | "submenu" | "submenu-b
// every other surface uses the real title, so overriding it desyncs the icon.
export type CommandPaletteProject = Project & { readonly displayName: string };
export function buildCommandPaletteProjectMetadata(input: {
readonly projects: ReadonlyArray<Pick<Project, "environmentId" | "title" | "workspaceRoot">>;
readonly locationByEnvironmentId: ReadonlyMap<EnvironmentId, { readonly label: string }>;
}) {
const searchTerms: string[] = [];
const environmentLabels = new Set<string>();
for (const project of input.projects) {
const label = input.locationByEnvironmentId.get(project.environmentId)?.label ?? "Remote";
searchTerms.push(project.title, project.workspaceRoot, label);
environmentLabels.add(label);
}
return { searchTerms, environmentLabels: [...environmentLabels] };
}
export function buildProjectActionItems(input: {
projects: ReadonlyArray<CommandPaletteProject>;
valuePrefix: string;
+68 -3
View File
@@ -126,6 +126,7 @@ import {
ADDON_ICON_CLASS,
browseInputEndPaddingClass,
buildBrowseGroups,
buildCommandPaletteProjectMetadata,
buildProjectActionItems,
buildRootGroups,
buildThreadActionItems,
@@ -186,6 +187,38 @@ function projectFavicon(project: Project) {
return <ProjectFavicon project={project} className="size-4" />;
}
function ProjectSearchDescription(props: {
readonly environmentLabels: ReadonlyArray<string>;
readonly grouped: boolean;
readonly location: {
readonly kind: "local" | "remote";
readonly label: string;
readonly machine: EnvironmentMachineKind;
};
readonly workspaceRoot: string;
}) {
if (!props.grouped) {
return (
<span className="flex min-w-0 items-center gap-1">
<span className="inline-flex min-w-0 items-center gap-1">
{props.location.kind === "remote" ? (
<EnvironmentMachineIcon
aria-hidden
kind={props.location.machine}
className={COMMAND_PALETTE_META_ICON_CLASS}
/>
) : null}
<span className="truncate">{props.location.label}</span>
</span>
<CommandPaletteMetaDot />
<span className="truncate">{props.workspaceRoot}</span>
</span>
);
}
return <span className="truncate">{props.environmentLabels.join(" · ")}</span>;
}
function getEnvironmentBrowsePlatform(os: string | null | undefined): string {
if (os === "windows") {
return "Win32";
@@ -1079,15 +1112,43 @@ function OpenCommandPaletteDialog(props: {
projects: pickerProjects,
valuePrefix: "project",
searchTerms: (project) => {
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
const members = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`)
?.memberProjects ?? [project];
return buildCommandPaletteProjectMetadata({
projects: members,
locationByEnvironmentId: projectEnvironmentLocationById,
}).searchTerms;
},
renderDescription: (project) => {
const members = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`)
?.memberProjects ?? [project];
const metadata = buildCommandPaletteProjectMetadata({
projects: members,
locationByEnvironmentId: projectEnvironmentLocationById,
});
const location = projectEnvironmentLocationById.get(project.environmentId) ?? {
kind: "remote" as const,
label: "Remote",
machine: "server" as const,
};
return (
group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ?? []
<ProjectSearchDescription
environmentLabels={metadata.environmentLabels}
grouped={members.length > 1}
location={location}
workspaceRoot={project.workspaceRoot}
/>
);
},
icon: projectFavicon,
runProject: openProjectFromSearch,
}),
[openProjectFromSearch, pickerProjects, projectGroupByTargetKey],
[
openProjectFromSearch,
pickerProjects,
projectEnvironmentLocationById,
projectGroupByTargetKey,
],
);
const projectThreadItems = useMemo(
@@ -1176,6 +1237,9 @@ function OpenCommandPaletteDialog(props: {
<ThreadCommandSubtitle
project={projectByKey.get(`${thread.environmentId}:${thread.projectId}`) ?? null}
projectTitle={projectTitle ?? null}
environmentLabel={
projectEnvironmentLocationById.get(thread.environmentId)?.label ?? "Remote"
}
branch={thread.branch}
worktreePath={thread.worktreePath}
isCurrent={thread.id === activeThreadId}
@@ -1213,6 +1277,7 @@ function OpenCommandPaletteDialog(props: {
clientSettings.sidebarThreadSortOrder,
navigate,
projectByKey,
projectEnvironmentLocationById,
projectTitleById,
providerEntryByEnvironmentAndInstanceId,
threadContentMatchByKey,
@@ -36,6 +36,7 @@ function WorkspaceIcon(props: { variant: ThreadCommandSubtitleVariant; isWorktre
export function ThreadCommandSubtitle(props: {
project: ProjectFaviconProject | null;
projectTitle: string | null;
environmentLabel?: string | null;
branch: string | null;
worktreePath: string | null;
isCurrent: boolean;
@@ -69,6 +70,12 @@ export function ThreadCommandSubtitle(props: {
<ProjectFavicon project={props.project} className="size-3 shrink-0" />
) : null}
<span className="min-w-0 truncate">{projectLabel}</span>
{props.environmentLabel ? (
<>
<CommandPaletteMetaDot />
<span className="shrink-0">{props.environmentLabel}</span>
</>
) : null}
</span>
) : null}