Skip to content
Merged
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
20 changes: 20 additions & 0 deletions apps/web/src/components/CommandPalette.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Thread } from "../types";
import { makeThreadFixture } from "../test-fixtures";
import {
buildNestedSearchItems,
resolveCommandPaletteProject,
buildThreadActionItems,
buildLinkedThreadActionItems,
filterPinnedBrowseEntries,
Expand Down Expand Up @@ -918,3 +919,22 @@ describe("returning from file and content search", () => {
expect(reduceCommandPaletteUiState(closed, { _tag: "SetOpen", open: true })).toEqual(root);
});
});

it("resolves project metadata and browse roots within the active environment", () => {
const local = { title: "Local project", workspaceRoot: "/local/repo" };
const remote = { title: "Remote project", workspaceRoot: "/remote/repo" };
const projects = new Map([
["local:shared-project", local],
["remote:shared-project", remote],
]);
expect(
resolveCommandPaletteProject(projects, EnvironmentId.make("local"), PROJECT_ID),
).toBeUndefined();
const sharedId = ProjectId.make("shared-project");
expect(resolveCommandPaletteProject(projects, EnvironmentId.make("local"), sharedId)).toBe(local);
expect(resolveCommandPaletteProject(projects, EnvironmentId.make("remote"), sharedId)).toBe(
remote,
);
expect(resolveCommandPaletteProject(projects, null, sharedId)).toBeUndefined();
expect(resolveCommandPaletteProject(projects, EnvironmentId.make("local"), null)).toBeUndefined();
});
9 changes: 9 additions & 0 deletions apps/web/src/components/CommandPalette.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "@t3tools/client-runtime/operations/projects";
import {
type EnvironmentId,
type ProjectId,
type EnvironmentMachineKind,
type FilesystemBrowseEntry,
type KeybindingCommand,
Expand Down Expand Up @@ -860,3 +861,11 @@ export function overlayModeForCommand(command: string | null): SearchOverlayMode
? OVERLAY_MODE_BY_COMMAND[command as keyof typeof OVERLAY_MODE_BY_COMMAND]
: null;
}

export function resolveCommandPaletteProject<TProject>(
projects: ReadonlyMap<string, TProject>,
environmentId: EnvironmentId | null,
projectId: ProjectId | null,
) {
return environmentId && projectId ? projects.get(`${environmentId}:${projectId}`) : undefined;
}
15 changes: 10 additions & 5 deletions apps/web/src/components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import {
resolveWslProjectSelection,
} from "../wslPaths";
import {
resolveCommandPaletteProject,
ADDON_ICON_CLASS,
browseInputEndPaddingClass,
buildBrowseGroups,
Expand Down Expand Up @@ -611,7 +612,7 @@ function OpenCommandPaletteDialog(props: {
return ensureBrowseDirectoryPath(baseDirectory);
};

const { projectCwdById, projectByKey, projectTitleById } = useProjectLookups();
const { projectByKey } = useProjectLookups();

const activeThreadKey = activeThread
? scopedThreadKey(scopeThreadRef(activeThread.environmentId, activeThread.id))
Expand All @@ -637,9 +638,12 @@ function OpenCommandPaletteDialog(props: {
const canTriage =
useAtomValue(serverEnvironment.prepareTriage.permissionAtom(triageEnvironmentId)) &&
supportsTriage(triageEnvironmentId);
const currentProjectCwd = currentProjectId
? (projectCwdById.get(currentProjectId) ?? null)
: null;
const currentProject = resolveCommandPaletteProject(
projectByKey,
currentProjectEnvironmentId,
currentProjectId,
);
const currentProjectCwd = currentProject?.workspaceRoot ?? null;
const currentProjectCwdForBrowse =
browseEnvironmentId && currentProjectEnvironmentId === browseEnvironmentId
? currentProjectCwd
Expand Down Expand Up @@ -1155,7 +1159,8 @@ function OpenCommandPaletteDialog(props: {
if (projects.length > 0) {
const activeProjectTitle =
projectPickerEntries.find((entry) => entry.isPreferred)?.group.displayName ??
(currentProjectId ? (projectTitleById.get(currentProjectId) ?? null) : null);
currentProject?.title ??
null;

if (activeProjectTitle) {
actionItems.push({
Expand Down
9 changes: 1 addition & 8 deletions apps/web/src/components/CommandPaletteLookups.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
type ClientSettings,
type EnvironmentId,
type ProjectId,
resolveEnvironmentMachineKind,
} from "@t3tools/contracts";

Expand Down Expand Up @@ -41,16 +40,10 @@ export function useEnvironmentLookups() {

export function useProjectLookups() {
const projects = useProjects();
const projectCwdById = new Map<ProjectId, string>(
projects.map((project) => [project.id, project.workspaceRoot]),
);
const projectByKey = new Map(
projects.map((project) => [`${project.environmentId}:${project.id}`, project]),
);
const projectTitleById = new Map<ProjectId, string>(
projects.map((project) => [project.id, project.title]),
);
return { projectCwdById, projectByKey, projectTitleById };
return { projectByKey };
}

export const selectCommandPaletteClientSettings = (settings: ClientSettings) => ({
Expand Down
Loading