Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions apps/web/src/components/CommandPalette.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface CommandPaletteSubmenuItem extends CommandPaletteItem {
export interface CommandPaletteGroup {
readonly value: string;
readonly label: string;
readonly enumerateShortcuts?: boolean;
readonly items: ReadonlyArray<CommandPaletteActionItem | CommandPaletteSubmenuItem>;
}

Expand All @@ -125,8 +126,8 @@ export interface CommandPaletteView {
}

export function enumerateCommandPaletteItems(
items: ReadonlyArray<CommandPaletteActionItem>,
): CommandPaletteActionItem[] {
items: CommandPaletteGroup["items"],
): Array<CommandPaletteActionItem | CommandPaletteSubmenuItem> {
return items.map((item, index) => {
const shortcutCommand = THREAD_JUMP_KEYBINDING_COMMANDS[index];
if (shortcutCommand) return { ...item, shortcutCommand };
Expand All @@ -136,6 +137,11 @@ export function enumerateCommandPaletteItems(
});
}

function withEnumeratedShortcuts(group: CommandPaletteGroup): CommandPaletteGroup {
if (!group.enumerateShortcuts) return group;
return { ...group, items: enumerateCommandPaletteItems(group.items) };
}

export type CommandPaletteMode = "root" | "root-browse" | "submenu" | "submenu-browse";

export function normalizeSearchText(value: string): string {
Expand Down Expand Up @@ -303,7 +309,7 @@ export function filterCommandPaletteGroups(input: {
if (isActionsFilter) {
return input.activeGroups.filter((group) => group.value === "actions");
}
return [...input.activeGroups];
return input.activeGroups.map(withEnumeratedShortcuts);
}

let baseGroups = [...input.activeGroups];
Expand Down Expand Up @@ -351,7 +357,7 @@ export function filterCommandPaletteGroups(input: {
return [];
}

return [{ value: group.value, label: group.label, items }];
return [withEnumeratedShortcuts({ ...group, items })];
});
}

Expand Down
105 changes: 55 additions & 50 deletions apps/web/src/components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ import {
buildProjectActionItems,
buildRootGroups,
buildThreadActionItems,
enumerateCommandPaletteItems,
type CommandPaletteActionItem,
type CommandPaletteOpenIntent,
type CommandPaletteSubmenuItem,
Expand Down Expand Up @@ -1023,55 +1022,53 @@ function OpenCommandPaletteDialog(props: {

const projectThreadItems = useMemo(
() =>
enumerateCommandPaletteItems(
buildProjectActionItems({
projects: pickerProjects,
valuePrefix: "new-thread-in",
searchTerms: (project) => {
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
const location = projectEnvironmentLocationById.get(project.environmentId);
return [
...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ??
[]),
...(location ? [location.label] : []),
];
},
renderDescription: (project) => {
const location = projectEnvironmentLocationById.get(project.environmentId) ?? {
kind: "remote",
label: "Remote",
};
return (
<span className="flex min-w-0 items-center gap-1">
<span className="inline-flex min-w-0 items-center gap-1">
{location.kind === "remote" ? (
<ServerIcon aria-hidden className={COMMAND_PALETTE_META_ICON_CLASS} />
) : null}
<span className="truncate">{location.label}</span>
</span>
<CommandPaletteMetaDot />
<span className="truncate">{project.workspaceRoot}</span>
buildProjectActionItems({
projects: pickerProjects,
valuePrefix: "new-thread-in",
searchTerms: (project) => {
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
const location = projectEnvironmentLocationById.get(project.environmentId);
return [
...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ??
[]),
...(location ? [location.label] : []),
];
},
renderDescription: (project) => {
const location = projectEnvironmentLocationById.get(project.environmentId) ?? {
kind: "remote",
label: "Remote",
};
return (
<span className="flex min-w-0 items-center gap-1">
<span className="inline-flex min-w-0 items-center gap-1">
{location.kind === "remote" ? (
<ServerIcon aria-hidden className={COMMAND_PALETTE_META_ICON_CLASS} />
) : null}
<span className="truncate">{location.label}</span>
</span>
<CommandPaletteMetaDot />
<span className="truncate">{project.workspaceRoot}</span>
</span>
);
},
icon: projectFavicon,
runProject: async (project) => {
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
const contextualRefBelongsToGroup =
contextualProjectRef !== null &&
group?.memberProjectRefs.some(
(projectRef) =>
projectRef.environmentId === contextualProjectRef.environmentId &&
projectRef.projectId === contextualProjectRef.projectId,
);
},
icon: projectFavicon,
runProject: async (project) => {
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
const contextualRefBelongsToGroup =
contextualProjectRef !== null &&
group?.memberProjectRefs.some(
(projectRef) =>
projectRef.environmentId === contextualProjectRef.environmentId &&
projectRef.projectId === contextualProjectRef.projectId,
);
await handleNewThread(
contextualRefBelongsToGroup
? contextualProjectRef
: scopeProjectRef(project.environmentId, project.id),
);
},
}),
),
await handleNewThread(
contextualRefBelongsToGroup
? contextualProjectRef
: scopeProjectRef(project.environmentId, project.id),
);
},
}),
[
contextualProjectRef,
handleNewThread,
Expand Down Expand Up @@ -1470,7 +1467,8 @@ function OpenCommandPaletteDialog(props: {
{
value: "projects",
label: "Projects",
items: enumerateCommandPaletteItems(prioritized),
enumerateShortcuts: true,
items: prioritized,
},
],
});
Expand Down Expand Up @@ -1521,7 +1519,14 @@ function OpenCommandPaletteDialog(props: {
title: "New thread in...",
icon: <SquarePenIcon className={ITEM_ICON_CLASS} />,
addonIcon: <SquarePenIcon className={ADDON_ICON_CLASS} />,
groups: [{ value: "projects", label: "Projects", items: projectThreadItems }],
groups: [
{
value: "projects",
label: "Projects",
enumerateShortcuts: true,
items: projectThreadItems,
},
],
});
}

Expand Down
Loading