Skip to content
TypeScript

fix(web): the welcome wizard keeps the project selection when you go back a stage (#24719)

Jackson Milleraa056f7d0fcb
diff --git a/apps/web/src/components/onboarding/WelcomeWizard.import.browser.test.tsx b/apps/web/src/components/onboarding/WelcomeWizard.import.browser.test.tsx
index 5f4bc3fbb69..c55691d9ca5 100644
--- a/apps/web/src/components/onboarding/WelcomeWizard.import.browser.test.tsx
+++ b/apps/web/src/components/onboarding/WelcomeWizard.import.browser.test.tsx
@@ -22,6 +22,7 @@ type CreateProjectInput = {
};
const state = vi.hoisted(() => ({
selectedEnvironment: "primary",
+ addedEnvironments: [] as string[],
sessions: new Map<string, unknown>(),
projects: null as unknown,
providers: null as unknown,
@@ -67,7 +68,9 @@ vi.mock(import("../../state/environments"), async (original) => {
return {
...(await original()),
usePrimaryEnvironment: (() => primary) as never,
- useEnvironments: (() => ({ environments: [environment(state.selectedEnvironment)] })) as never,
+ useEnvironments: (() => ({
+ environments: [state.selectedEnvironment, ...state.addedEnvironments].map(environment),
+ })) as never,
};
});
vi.mock(import("../../state/server"), async (original) => {
@@ -232,6 +235,12 @@ async function click(label: string) {
await act(async () => target.click());
}
+async function clickStage(label: string) {
+ const stage = document.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`);
+ expect(stage?.disabled).toBe(false);
+ await act(async () => stage?.click());
+}
+
async function mountImport(remote = false) {
state.selectedEnvironment = remote ? "remote" : "primary";
await using stack = new AsyncDisposableStack();
@@ -253,6 +262,7 @@ async function mountImport(remote = false) {
// Returns the clock spy so each test can `using` it; the spy would otherwise outlive the test.
function setup() {
const now = vi.spyOn(Date, "now").mockReturnValue(NOW);
+ state.addedEnvironments = [];
state.sessions.clear();
for (const id of [primaryId, remoteId]) {
state.sessions.set(
@@ -282,6 +292,34 @@ function setup() {
return now;
}
+it("keeps the project selection after going back a stage", async () => {
+ using _now = setup();
+ await using _screen = await mountImport();
+ await click("Select none");
+ expect(pageText()).toContain("0 of 2 selected");
+
+ await clickStage("Agents, step 2");
+ await click("Continue");
+ expect(pageText()).toContain("Import your projects");
+ expect(pageText()).toContain("0 of 2 selected");
+});
+
+it("ticks the recent projects of a computer added after the selection changed", async () => {
+ using _now = setup();
+ await using _screen = await mountImport();
+ await click("Select none");
+
+ state.addedEnvironments = ["remote"];
+ await clickStage("Connect, step 1");
+ await click("Continue");
+ await click("Continue");
+ expect(pageText()).toContain("2 of 4 selected");
+
+ await click("Import 2 projects");
+ const created = state.createProject.mock.calls as Array<[CreateProjectInput]>;
+ expect(created.map(([call]) => call.environmentId)).toEqual([remoteId, remoteId]);
+});
+
it("rechecks after project creation and can retry its history without recreating the project", async () => {
using _now = setup();
const creation = deferred<void>();
diff --git a/apps/web/src/components/onboarding/WelcomeWizard.tsx b/apps/web/src/components/onboarding/WelcomeWizard.tsx
index 5dc5f0e28e0..2eb6bcd6739 100644
--- a/apps/web/src/components/onboarding/WelcomeWizard.tsx
+++ b/apps/web/src/components/onboarding/WelcomeWizard.tsx
@@ -131,6 +131,7 @@ export function WelcomeWizard({
const [setupIds, setSetupIds] = useState<readonly EnvironmentId[]>(
resumeEnvironmentId ? [resumeEnvironmentId] : [],
);
+ const [importSelection, setImportSelection] = useState<ImportSelection | null>(null);
const [isImporting, setIsImporting] = useState(false);
const finishingPromiseRef = useRef<Promise<boolean> | null>(null);
const completionErrorToastIdRef = useRef<ReturnType<typeof toastManager.add> | null>(null);
@@ -286,6 +287,8 @@ export function WelcomeWizard({
) : (
<ImportStep
scans={scans}
+ importSelection={importSelection}
+ onImportSelectionChange={setImportSelection}
isImporting={isImporting}
setIsImporting={setIsImporting}
onDone={finish}
@@ -1190,13 +1193,23 @@ function AgentInstallTerminal({
const IMPORT_PERMISSION_MESSAGE = "This connection cannot import projects or thread history.";
+interface ImportSelection {
+ // Computers whose projects were listed when the selection changed; later ones get the defaults.
+ readonly environmentIds: ReadonlySet<EnvironmentId>;
+ readonly keys: ReadonlySet<string>;
+}
+
function ImportStep({
scans,
+ importSelection,
+ onImportSelectionChange,
isImporting,
setIsImporting,
onDone,
}: {
readonly scans: ReturnType<typeof useProjectScans>;
+ readonly importSelection: ImportSelection | null;
+ readonly onImportSelectionChange: (next: ImportSelection) => void;
readonly isImporting: boolean;
readonly setIsImporting: (value: boolean) => void;
readonly onDone: (
@@ -1209,7 +1222,6 @@ function ImportStep({
const writableEnvironments = useEnvironmentsWithScope(scans, AuthOrchestrationOperateScope);
const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
const importThreads = useAtomCommand(agentSessionImport, { reportFailure: false });
- const [selectedPaths, setSelectedPaths] = useState<ReadonlySet<string> | null>(null);
const importWarningRef = useRef("");
const importedThreadCountRef = useRef(0);
const importedProjectsRef = useRef(new Map<string, ScopedProjectRef>());
@@ -1237,8 +1249,20 @@ function ImportStep({
})),
),
);
- const selectedKeys = selectedPaths ?? new Set(recent.map((candidate) => candidate.key));
- const selected = candidates.filter((candidate) => selectedKeys.has(candidate.key));
+ const recentKeys = new Set(recent.map((candidate) => candidate.key));
+ const selected = candidates.filter((candidate) =>
+ importSelection?.environmentIds.has(candidate.environmentId)
+ ? importSelection.keys.has(candidate.key)
+ : recentKeys.has(candidate.key),
+ );
+ const selectedKeys = new Set(selected.map((candidate) => candidate.key));
+ const setSelectedKeys = (keys: ReadonlySet<string>) =>
+ onImportSelectionChange({
+ environmentIds: new Set(
+ scans.flatMap((scan) => (scan.data === null ? [] : [scan.environmentId])),
+ ),
+ keys,
+ });
const canImport = selected.every((candidate) =>
writableEnvironments.has(candidate.environmentId),
@@ -1448,7 +1472,7 @@ function ImportStep({
variant="ghost"
size="xs"
disabled={isImporting || selected.length === candidates.length}
- onClick={() => setSelectedPaths(new Set(candidates.map((item) => item.key)))}
+ onClick={() => setSelectedKeys(new Set(candidates.map((item) => item.key)))}
>
Select all
</Button>
@@ -1456,7 +1480,7 @@ function ImportStep({
variant="ghost"
size="xs"
disabled={isImporting || selected.length === 0}
- onClick={() => setSelectedPaths(new Set())}
+ onClick={() => setSelectedKeys(new Set())}
>
Select none
</Button>
@@ -1509,7 +1533,7 @@ function ImportStep({
<ImportCandidateList
candidates={scanCandidates}
selectedKeys={selectedKeys}
- onSelectionChange={setSelectedPaths}
+ onSelectionChange={setSelectedKeys}
/>
</fieldset>
);