fix(web): keep the selected environment when changing projects (#9102)
This commit is contained in:
1 parent
d0b4acbd13
commit
c0995d2eaf
3 files changed
+81
-7
No files matched your search
@@ -323,6 +323,74 @@ describe("environment grouping", () => {
|
||||
expect(entries[1]?.group.displayName).toBe("separate");
|
||||
});
|
||||
|
||||
it("keeps the current environment when available and falls back otherwise", () => {
|
||||
const currentPrimary = makeProject({ repositoryIdentity });
|
||||
const currentRemote = makeProject({
|
||||
id: ProjectId.make("current-remote"),
|
||||
environmentId: remoteEnvironmentId,
|
||||
repositoryIdentity,
|
||||
});
|
||||
const destinationRepositoryIdentity = {
|
||||
canonicalKey: "github.com/example/destination",
|
||||
locator: {
|
||||
source: "git-remote" as const,
|
||||
remoteName: "origin",
|
||||
remoteUrl: "https://github.com/example/destination.git",
|
||||
},
|
||||
};
|
||||
const destinationPrimary = makeProject({
|
||||
id: ProjectId.make("destination-primary"),
|
||||
title: "destination",
|
||||
workspaceRoot: "/tmp/destination",
|
||||
repositoryIdentity: destinationRepositoryIdentity,
|
||||
});
|
||||
const destinationRemote = makeProject({
|
||||
id: ProjectId.make("destination-remote"),
|
||||
environmentId: remoteEnvironmentId,
|
||||
title: "destination",
|
||||
workspaceRoot: "/remote/destination",
|
||||
repositoryIdentity: destinationRepositoryIdentity,
|
||||
});
|
||||
const fallbackPrimary = makeProject({
|
||||
id: ProjectId.make("fallback-primary"),
|
||||
title: "fallback",
|
||||
workspaceRoot: "/tmp/fallback",
|
||||
});
|
||||
const groups = buildSidebarProjectSnapshots({
|
||||
projects: [
|
||||
currentPrimary,
|
||||
currentRemote,
|
||||
destinationPrimary,
|
||||
destinationRemote,
|
||||
fallbackPrimary,
|
||||
],
|
||||
settings: defaultGroupingSettings,
|
||||
primaryEnvironmentId,
|
||||
resolveEnvironmentLabel: () => null,
|
||||
});
|
||||
|
||||
const entries = buildSidebarProjectPickerEntries({
|
||||
groups,
|
||||
preferredProjectRef: {
|
||||
environmentId: remoteEnvironmentId,
|
||||
projectId: currentRemote.id,
|
||||
},
|
||||
});
|
||||
const destination = entries.find(
|
||||
(entry) => entry.group.projectKey === destinationRepositoryIdentity.canonicalKey,
|
||||
);
|
||||
const fallback = entries.find((entry) => entry.group.displayName === "fallback");
|
||||
|
||||
expect(destination?.targetProject).toMatchObject({
|
||||
environmentId: remoteEnvironmentId,
|
||||
id: destinationRemote.id,
|
||||
});
|
||||
expect(fallback?.targetProject).toMatchObject({
|
||||
environmentId: primaryEnvironmentId,
|
||||
id: fallbackPrimary.id,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps manual project order when building grouped sidebar entries", () => {
|
||||
const primary = makeProject({ repositoryIdentity });
|
||||
const remote = makeProject({
|
||||
|
||||
@@ -118,22 +118,23 @@ export function buildSidebarProjectPickerEntries(input: {
|
||||
groups: ReadonlyArray<SidebarProjectSnapshot>;
|
||||
preferredProjectRef: ScopedProjectRef | null;
|
||||
}) {
|
||||
const preferredProjectRef = input.preferredProjectRef;
|
||||
const entries = input.groups.flatMap((group): SidebarProjectPickerEntry[] => {
|
||||
const isPreferred = input.preferredProjectRef
|
||||
const isPreferred = preferredProjectRef
|
||||
? group.memberProjectRefs.some(
|
||||
(projectRef) =>
|
||||
projectRef.environmentId === input.preferredProjectRef?.environmentId &&
|
||||
projectRef.projectId === input.preferredProjectRef.projectId,
|
||||
projectRef.environmentId === preferredProjectRef.environmentId &&
|
||||
projectRef.projectId === preferredProjectRef.projectId,
|
||||
)
|
||||
: false;
|
||||
const preferredProject = isPreferred
|
||||
const preferredProject = preferredProjectRef
|
||||
? (group.memberProjects.find(
|
||||
(project) =>
|
||||
project.environmentId === input.preferredProjectRef?.environmentId &&
|
||||
project.id === input.preferredProjectRef?.projectId,
|
||||
project.environmentId === preferredProjectRef.environmentId &&
|
||||
project.id === preferredProjectRef.projectId,
|
||||
) ??
|
||||
group.memberProjects.find(
|
||||
(project) => project.environmentId === input.preferredProjectRef?.environmentId,
|
||||
(project) => project.environmentId === preferredProjectRef.environmentId,
|
||||
))
|
||||
: null;
|
||||
const targetProject =
|
||||
|
||||
@@ -52,6 +52,11 @@ On mobile, the model picker shows each OpenCode model's upstream provider, such
|
||||
GitHub Copilot, or OpenCode Zen, beneath its name. Search by that provider name to narrow the list
|
||||
when starting a thread or changing an existing thread's model.
|
||||
|
||||
## Changing projects
|
||||
|
||||
On web and desktop, changing the project from a new thread keeps the current environment when that
|
||||
project exists there. If it does not, T3 Code selects another environment that has the project.
|
||||
|
||||
## Notices above the composer
|
||||
|
||||
On web and desktop, loading and syncing statuses fill the available banner width beside the
|
||||
|
||||
Reference in new issue
Block a user