Skip to content

Commit f729e8f

Browse files
fix(web): make onboarding a shared multi-computer wizard (#10465)
1 parent 490eb17 commit f729e8f

20 files changed

Lines changed: 1199 additions & 1277 deletions

‎apps/web/src/components/AnimatedHeight.tsx‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { type ReactNode, useEffect, useLayoutEffect, useRef, useState } from "re
44

55
const HEIGHT_TRANSITION_FALLBACK_MS = 250;
66

7-
export function AnimatedHeight({ children }: { readonly children: ReactNode }) {
7+
export function AnimatedHeight({
8+
children,
9+
holdHeight = false,
10+
}: {
11+
readonly children: ReactNode;
12+
/** Retain the previous content height while a replacement is loading. */
13+
readonly holdHeight?: boolean;
14+
}) {
815
const contentRef = useRef<HTMLDivElement>(null);
916
const [heightState, setHeightState] = useState<{
1017
readonly height: number | null;
@@ -22,6 +29,7 @@ export function AnimatedHeight({ children }: { readonly children: ReactNode }) {
2229
}, [heightState.height, heightState.isClipping]);
2330

2431
useLayoutEffect(() => {
32+
if (holdHeight) return;
2533
const element = contentRef.current;
2634
if (!element) return;
2735
let firstFrameId: number | null = null;
@@ -67,7 +75,7 @@ export function AnimatedHeight({ children }: { readonly children: ReactNode }) {
6775
resizeObserver.disconnect();
6876
cancelPendingFrames();
6977
};
70-
}, []);
78+
}, [holdHeight]);
7179

7280
return (
7381
<div
@@ -85,7 +93,9 @@ export function AnimatedHeight({ children }: { readonly children: ReactNode }) {
8593
);
8694
}}
8795
>
88-
<div ref={contentRef}>{children}</div>
96+
<div ref={contentRef} style={holdHeight ? { height: "100%" } : undefined}>
97+
{children}
98+
</div>
8999
</div>
90100
);
91101
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { PlusIcon } from "lucide-react";
2+
import { useCallback } from "react";
3+
4+
import { openCommandPalette } from "../commandPaletteBus";
5+
import { Button } from "./ui/button";
6+
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "./ui/empty";
7+
import { SidebarInset } from "./ui/sidebar";
8+
9+
export function NoProjectsHero() {
10+
const openAddProject = useCallback(() => openCommandPalette({ open: "add-project" }), []);
11+
12+
return (
13+
<SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none bg-background text-foreground">
14+
<div className="flex min-h-0 min-w-0 flex-1 flex-col overflow-x-hidden bg-background">
15+
<Empty className="flex-1">
16+
<div className="w-full max-w-lg px-8 py-12">
17+
<EmptyHeader className="max-w-none">
18+
<EmptyTitle className="text-foreground text-2xl sm:text-3xl">
19+
What should we work on?
20+
</EmptyTitle>
21+
<EmptyDescription className="mt-2 text-sm text-muted-foreground/78">
22+
Add a project to start your first thread.
23+
</EmptyDescription>
24+
<div className="mt-6 flex justify-center">
25+
<Button size="sm" onClick={openAddProject}>
26+
<PlusIcon className="size-4" />
27+
Add project
28+
</Button>
29+
</div>
30+
</EmptyHeader>
31+
</div>
32+
</Empty>
33+
</div>
34+
</SidebarInset>
35+
);
36+
}

‎apps/web/src/components/cloud/CloudEnvironmentConnectList.test.tsx‎

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";
33
import { EnvironmentId } from "@t3tools/contracts";
44
import * as Option from "effect/Option";
55
import { AsyncResult } from "effect/unstable/reactivity";
6-
import { act, type ButtonHTMLAttributes } from "react";
6+
import { act, useState, type ButtonHTMLAttributes, type ReactNode } from "react";
77
import { create, type ReactTestRenderer } from "react-test-renderer";
88
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
99

@@ -42,6 +42,25 @@ vi.mock("~/state/environments", async () => {
4242
return { useRelayEnvironmentDiscovery: () => useSyncExternalStore(subscribe, read, read) };
4343
});
4444
vi.mock("../ConnectionStatusDot", () => ({ ConnectionStatusDot: () => null }));
45+
vi.mock("../ui/tooltip", () => ({
46+
Tooltip: ({ children }: { children: ReactNode }) => children,
47+
TooltipTrigger: ({ children }: { children: ReactNode }) => <span>{children}</span>,
48+
TooltipPopup: () => null,
49+
}));
50+
vi.mock("../ui/checkbox", () => ({
51+
Checkbox: (props: {
52+
checked: boolean;
53+
disabled: boolean;
54+
onCheckedChange: (checked: boolean) => void;
55+
}) => (
56+
<input
57+
type="checkbox"
58+
checked={props.checked}
59+
disabled={props.disabled}
60+
onChange={(event) => props.onCheckedChange(event.target.checked)}
61+
/>
62+
),
63+
}));
4564
vi.mock("../ui/button", () => ({
4665
Button: ({ children, ...props }: ButtonHTMLAttributes<HTMLButtonElement>) => (
4766
<button {...props}>{children}</button>
@@ -118,6 +137,7 @@ beforeEach(() => {
118137
error: Option.none(),
119138
};
120139
discovery.listEnvironments.mockReset().mockResolvedValue(new Map());
140+
discovery.register.mockReset().mockResolvedValue(AsyncResult.success(undefined));
121141
discovery.refresh.mockReset().mockImplementation(async () => {
122142
publish({ environments: new Map(), refreshing: true, offline: false, error: Option.none() });
123143
const environments = await discovery.listEnvironments();
@@ -133,6 +153,71 @@ afterEach(async () => {
133153
});
134154

135155
describe("cloud onboarding discovery", () => {
156+
it("signals that the section can expand after initial discovery settles", async () => {
157+
let finishDiscovery!: (environments: DiscoveredEnvironments) => void;
158+
discovery.listEnvironments.mockReturnValue(
159+
new Promise((resolve) => {
160+
finishDiscovery = resolve;
161+
}),
162+
);
163+
const onDiscoveryReady = vi.fn();
164+
await act(async () => {
165+
renderer = create(
166+
<CloudEnvironmentConnectRows
167+
primaryEnvironmentId={null}
168+
savedEnvironments={[]}
169+
onDiscoveryReady={onDiscoveryReady}
170+
/>,
171+
);
172+
});
173+
expect(onDiscoveryReady).not.toHaveBeenCalled();
174+
await act(async () => {
175+
finishDiscovery(linkedMachines);
176+
});
177+
expect(onDiscoveryReady).toHaveBeenCalledTimes(1);
178+
expect(renderer!.root.findByType("button").children).toEqual(["Connect"]);
179+
});
180+
181+
it("connects and selects discovered computers by default without overwriting deselection", async () => {
182+
discovery.listEnvironments.mockResolvedValue(linkedMachines);
183+
const autoSelectedComputers = new Set<EnvironmentId>();
184+
function Setup() {
185+
const [selectedIds, setSelectedIds] = useState<ReadonlySet<EnvironmentId>>(new Set());
186+
return (
187+
<CloudEnvironmentConnectRows
188+
primaryEnvironmentId={null}
189+
savedEnvironments={[]}
190+
showSavedEnvironments
191+
selection={{
192+
autoSelectedComputers,
193+
selectedIds,
194+
onChange: (id, checked) =>
195+
setSelectedIds((current) => {
196+
const next = new Set(current);
197+
if (checked) next.add(id);
198+
else next.delete(id);
199+
return next;
200+
}),
201+
}}
202+
/>
203+
);
204+
}
205+
await act(async () => {
206+
renderer = create(<Setup />);
207+
});
208+
209+
expect(discovery.register).toHaveBeenCalledTimes(1);
210+
expect(renderer!.root.findByType("input").props.checked).toBe(true);
211+
await act(async () => {
212+
await renderer!.root.findByType("input").props.onChange({ target: { checked: false } });
213+
});
214+
await act(async () => {
215+
publish({ ...discovery.state!, environments: new Map(linkedMachines) });
216+
});
217+
expect(renderer!.root.findByType("input").props.checked).toBe(false);
218+
expect(discovery.register).toHaveBeenCalledTimes(1);
219+
});
220+
136221
it("shows a newly linked computer without remounting and stops polling once found", async () => {
137222
discovery.listEnvironments
138223
.mockResolvedValueOnce(new Map())
@@ -152,6 +237,31 @@ describe("cloud onboarding discovery", () => {
152237
expect(discovery.listEnvironments).toHaveBeenCalledTimes(2);
153238
});
154239

240+
it("keeps a discovered computer visible when it is added to the browser", async () => {
241+
discovery.listEnvironments.mockResolvedValue(linkedMachines);
242+
await mount();
243+
expect(renderer!.root.findByType("button").children).toEqual(["Connect"]);
244+
await act(async () => {
245+
renderer!.update(
246+
<CloudEnvironmentConnectRows
247+
primaryEnvironmentId={null}
248+
savedEnvironments={[
249+
{
250+
environmentId: newMachineId,
251+
connection: { phase: "connected", error: null, traceId: null },
252+
},
253+
]}
254+
showSavedEnvironments
255+
refreshWhileEmpty
256+
/>,
257+
);
258+
});
259+
expect(renderer!.root.findAllByType("p").map((node) => node.children)).toContainEqual([
260+
"Work laptop",
261+
]);
262+
expect(renderer!.root.findByType("button").children).toEqual(["Connected"]);
263+
});
264+
155265
it("waits while hidden and refreshes immediately when visible again", async () => {
156266
page.visibilityState = "hidden";
157267
await mount();

0 commit comments

Comments
 (0)