Skip to content

Commit aa056f7

Browse files
Jacksondr5claude
andauthored
fix(web): the welcome wizard keeps the project selection when you go back a stage (pingdotgg#24719)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 35c7696 commit aa056f7

2 files changed

Lines changed: 69 additions & 7 deletions

File tree

‎apps/web/src/components/onboarding/WelcomeWizard.import.browser.test.tsx‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type CreateProjectInput = {
2222
};
2323
const state = vi.hoisted(() => ({
2424
selectedEnvironment: "primary",
25+
addedEnvironments: [] as string[],
2526
sessions: new Map<string, unknown>(),
2627
projects: null as unknown,
2728
providers: null as unknown,
@@ -67,7 +68,9 @@ vi.mock(import("../../state/environments"), async (original) => {
6768
return {
6869
...(await original()),
6970
usePrimaryEnvironment: (() => primary) as never,
70-
useEnvironments: (() => ({ environments: [environment(state.selectedEnvironment)] })) as never,
71+
useEnvironments: (() => ({
72+
environments: [state.selectedEnvironment, ...state.addedEnvironments].map(environment),
73+
})) as never,
7174
};
7275
});
7376
vi.mock(import("../../state/server"), async (original) => {
@@ -232,6 +235,12 @@ async function click(label: string) {
232235
await act(async () => target.click());
233236
}
234237

238+
async function clickStage(label: string) {
239+
const stage = document.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`);
240+
expect(stage?.disabled).toBe(false);
241+
await act(async () => stage?.click());
242+
}
243+
235244
async function mountImport(remote = false) {
236245
state.selectedEnvironment = remote ? "remote" : "primary";
237246
await using stack = new AsyncDisposableStack();
@@ -253,6 +262,7 @@ async function mountImport(remote = false) {
253262
// Returns the clock spy so each test can `using` it; the spy would otherwise outlive the test.
254263
function setup() {
255264
const now = vi.spyOn(Date, "now").mockReturnValue(NOW);
265+
state.addedEnvironments = [];
256266
state.sessions.clear();
257267
for (const id of [primaryId, remoteId]) {
258268
state.sessions.set(
@@ -282,6 +292,34 @@ function setup() {
282292
return now;
283293
}
284294

295+
it("keeps the project selection after going back a stage", async () => {
296+
using _now = setup();
297+
await using _screen = await mountImport();
298+
await click("Select none");
299+
expect(pageText()).toContain("0 of 2 selected");
300+
301+
await clickStage("Agents, step 2");
302+
await click("Continue");
303+
expect(pageText()).toContain("Import your projects");
304+
expect(pageText()).toContain("0 of 2 selected");
305+
});
306+
307+
it("ticks the recent projects of a computer added after the selection changed", async () => {
308+
using _now = setup();
309+
await using _screen = await mountImport();
310+
await click("Select none");
311+
312+
state.addedEnvironments = ["remote"];
313+
await clickStage("Connect, step 1");
314+
await click("Continue");
315+
await click("Continue");
316+
expect(pageText()).toContain("2 of 4 selected");
317+
318+
await click("Import 2 projects");
319+
const created = state.createProject.mock.calls as Array<[CreateProjectInput]>;
320+
expect(created.map(([call]) => call.environmentId)).toEqual([remoteId, remoteId]);
321+
});
322+
285323
it("rechecks after project creation and can retry its history without recreating the project", async () => {
286324
using _now = setup();
287325
const creation = deferred<void>();

‎apps/web/src/components/onboarding/WelcomeWizard.tsx‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export function WelcomeWizard({
131131
const [setupIds, setSetupIds] = useState<readonly EnvironmentId[]>(
132132
resumeEnvironmentId ? [resumeEnvironmentId] : [],
133133
);
134+
const [importSelection, setImportSelection] = useState<ImportSelection | null>(null);
134135
const [isImporting, setIsImporting] = useState(false);
135136
const finishingPromiseRef = useRef<Promise<boolean> | null>(null);
136137
const completionErrorToastIdRef = useRef<ReturnType<typeof toastManager.add> | null>(null);
@@ -286,6 +287,8 @@ export function WelcomeWizard({
286287
) : (
287288
<ImportStep
288289
scans={scans}
290+
importSelection={importSelection}
291+
onImportSelectionChange={setImportSelection}
289292
isImporting={isImporting}
290293
setIsImporting={setIsImporting}
291294
onDone={finish}
@@ -1190,13 +1193,23 @@ function AgentInstallTerminal({
11901193

11911194
const IMPORT_PERMISSION_MESSAGE = "This connection cannot import projects or thread history.";
11921195

1196+
interface ImportSelection {
1197+
// Computers whose projects were listed when the selection changed; later ones get the defaults.
1198+
readonly environmentIds: ReadonlySet<EnvironmentId>;
1199+
readonly keys: ReadonlySet<string>;
1200+
}
1201+
11931202
function ImportStep({
11941203
scans,
1204+
importSelection,
1205+
onImportSelectionChange,
11951206
isImporting,
11961207
setIsImporting,
11971208
onDone,
11981209
}: {
11991210
readonly scans: ReturnType<typeof useProjectScans>;
1211+
readonly importSelection: ImportSelection | null;
1212+
readonly onImportSelectionChange: (next: ImportSelection) => void;
12001213
readonly isImporting: boolean;
12011214
readonly setIsImporting: (value: boolean) => void;
12021215
readonly onDone: (
@@ -1209,7 +1222,6 @@ function ImportStep({
12091222
const writableEnvironments = useEnvironmentsWithScope(scans, AuthOrchestrationOperateScope);
12101223
const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
12111224
const importThreads = useAtomCommand(agentSessionImport, { reportFailure: false });
1212-
const [selectedPaths, setSelectedPaths] = useState<ReadonlySet<string> | null>(null);
12131225
const importWarningRef = useRef("");
12141226
const importedThreadCountRef = useRef(0);
12151227
const importedProjectsRef = useRef(new Map<string, ScopedProjectRef>());
@@ -1237,8 +1249,20 @@ function ImportStep({
12371249
})),
12381250
),
12391251
);
1240-
const selectedKeys = selectedPaths ?? new Set(recent.map((candidate) => candidate.key));
1241-
const selected = candidates.filter((candidate) => selectedKeys.has(candidate.key));
1252+
const recentKeys = new Set(recent.map((candidate) => candidate.key));
1253+
const selected = candidates.filter((candidate) =>
1254+
importSelection?.environmentIds.has(candidate.environmentId)
1255+
? importSelection.keys.has(candidate.key)
1256+
: recentKeys.has(candidate.key),
1257+
);
1258+
const selectedKeys = new Set(selected.map((candidate) => candidate.key));
1259+
const setSelectedKeys = (keys: ReadonlySet<string>) =>
1260+
onImportSelectionChange({
1261+
environmentIds: new Set(
1262+
scans.flatMap((scan) => (scan.data === null ? [] : [scan.environmentId])),
1263+
),
1264+
keys,
1265+
});
12421266

12431267
const canImport = selected.every((candidate) =>
12441268
writableEnvironments.has(candidate.environmentId),
@@ -1448,15 +1472,15 @@ function ImportStep({
14481472
variant="ghost"
14491473
size="xs"
14501474
disabled={isImporting || selected.length === candidates.length}
1451-
onClick={() => setSelectedPaths(new Set(candidates.map((item) => item.key)))}
1475+
onClick={() => setSelectedKeys(new Set(candidates.map((item) => item.key)))}
14521476
>
14531477
Select all
14541478
</Button>
14551479
<Button
14561480
variant="ghost"
14571481
size="xs"
14581482
disabled={isImporting || selected.length === 0}
1459-
onClick={() => setSelectedPaths(new Set())}
1483+
onClick={() => setSelectedKeys(new Set())}
14601484
>
14611485
Select none
14621486
</Button>
@@ -1509,7 +1533,7 @@ function ImportStep({
15091533
<ImportCandidateList
15101534
candidates={scanCandidates}
15111535
selectedKeys={selectedKeys}
1512-
onSelectionChange={setSelectedPaths}
1536+
onSelectionChange={setSelectedKeys}
15131537
/>
15141538
</fieldset>
15151539
);

0 commit comments

Comments
 (0)