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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ vi.mock("../../state/environments", () => {
environmentId,
label: environmentId,
connection: { phase: "connected" },
entry: { target: { _tag: "DirectConnectionTarget" } },
entry: { enabled: true, target: { _tag: "DirectConnectionTarget" } },
});
const primary = environment("primary");
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const primaryEnvironment = {
label: "This computer",
connection: { phase: "connected" },
entry: {
enabled: true,
target: new PrimaryConnectionTarget({
environmentId: primaryId,
label: "This computer",
Expand All @@ -164,6 +165,7 @@ const remoteEnvironment = {
label: "Paired computer",
connection: { phase: "connected" },
entry: {
enabled: true,
target: new BearerConnectionTarget({
environmentId: remoteId,
label: "Paired computer",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/onboarding/WelcomeWizard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ vi.mock("../../state/environments", () => {
environmentId: "test-env",
label: "Computer",
connection: { phase: "connected" },
entry: { enabled: true },
};
return {
useEnvironments: () => ({ environments: [environment] }),
Expand Down
37 changes: 21 additions & 16 deletions apps/web/src/components/onboarding/WelcomeWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ import { newProjectId, randomUUID } from "../../lib/utils";
import { agentSessionImport } from "../../state/agentSessions";
import { readProjects, useProjects } from "../../state/entities";
import { useEnvironments, usePrimaryEnvironment } from "../../state/environments";
import { isOnboardingRelayEnvironment } from "../../onboarding/targetEnvironment.logic";
import {
isOnboardingRelayEnvironment,
resolveOnboardingSetup,
} from "../../onboarding/targetEnvironment.logic";
import { useProjectScans } from "../../onboarding/useProjectScans";
import { projectEnvironment } from "../../state/projects";
import { serverEnvironment } from "../../state/server";
Expand All @@ -78,6 +81,7 @@ import { readCodexSetupMode } from "../settings/CodexSetupSection.logic";
import { buildProviderInstanceUpdatePatch } from "../settings/SettingsPanels.logic";
import { TerminalViewport } from "../ThreadTerminalDrawer";
import { CloudEnvironmentConnectRows } from "../cloud/CloudEnvironmentConnectList";
import { presentSavedCloudEnvironmentConnection } from "../cloud/cloudEnvironmentConnectionPresentation";
import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
import { T3Wordmark } from "../T3Wordmark";
import { Alert, AlertDescription } from "../ui/alert";
Expand Down Expand Up @@ -141,11 +145,14 @@ export function WelcomeWizard({
for (const environment of newComputers) {
autoSelectedComputers.current.add(environment.environmentId);
}
// A computer the user switched off stays unselected until they pick it.
const enabledComputers = newComputers.filter((environment) => environment.entry.enabled);
if (enabledComputers.length === 0) return;
setSelection(
(current) =>
new Set([
...(current ?? []),
...newComputers.map((environment) => environment.environmentId),
...enabledComputers.map((environment) => environment.environmentId),
]),
);
}, [environments]);
Expand Down Expand Up @@ -262,11 +269,7 @@ export function WelcomeWizard({
})
}
onContinue={() =>
startSetup(
environments
.filter((environment) => selectedIds.has(environment.environmentId))
.map((environment) => environment.environmentId),
)
startSetup(resolveOnboardingSetup(environments, selectedIds).environmentIds)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
onPaired={(environmentId) => {
setSelection(new Set([...selectedIds, environmentId]));
Expand Down Expand Up @@ -315,14 +318,10 @@ function ConnectionStep({
);
const [pairingOpen, setPairingOpen] = useState(expandPairingInitially);
const [isPairing, setIsPairing] = useState(false);
const ready =
selectedIds.size > 0 &&
[...selectedIds].every((id) =>
environments.some(
(environment) =>
environment.environmentId === id && environment.connection.phase === "connected",
),
);
const { ready, skippedIds } = resolveOnboardingSetup(environments, selectedIds);
const skippedLabels = environments
.filter((environment) => skippedIds.includes(environment.environmentId))
.map((environment) => environment.label);
const continueRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
if (
Expand Down Expand Up @@ -365,7 +364,7 @@ function ConnectionStep({
{environment.label}
</span>
<span className="shrink-0 text-xs text-muted-foreground">
{environment.connection.phase === "connected" ? "Connected" : "Connecting…"}
{presentSavedCloudEnvironmentConnection(environment.connection).buttonLabel}
</span>
</span>
{environment.displayUrl ? (
Expand Down Expand Up @@ -421,6 +420,12 @@ function ConnectionStep({
</Collapsible>
</div>
</div>
{skippedLabels.length > 0 ? (
<p className="mt-4 text-xs text-muted-foreground">
Not connected, so setup skips {skippedLabels.join(", ")}. You can set{" "}
{skippedLabels.length === 1 ? "it" : "them"} up later from Settings.
</p>
) : null}
<div className="mt-6 flex flex-col-reverse gap-4 sm:flex-row sm:items-center sm:justify-between sm:gap-6">
<p className="min-w-0 text-xs leading-relaxed text-muted-foreground">
T3 Code collects anonymous usage data to help us improve it. To read more about how your
Expand Down
47 changes: 47 additions & 0 deletions apps/web/src/onboarding/targetEnvironment.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { describe, expect, it } from "vite-plus/test";

import {
isOnboardingRelayEnvironment,
resolveOnboardingSetup,
resolveOnboardingTargetEnvironment,
} from "./targetEnvironment.logic";

Expand Down Expand Up @@ -209,3 +210,49 @@ describe("isOnboardingRelayEnvironment", () => {
).toEqual([olderRelay]);
});
});

describe("resolveOnboardingSetup", () => {
const computer = (id: string, phase: string) => ({
environmentId: EnvironmentId.make(id),
connection: { phase },
});
const local = computer("local", "connected");

it("skips selected computers that will not connect on their own", () => {
const environments = [
local,
computer("switched-off", "available"),
computer("offline", "offline"),
computer("failing", "reconnecting"),
computer("old-client", "unsupported"),
];
expect(
resolveOnboardingSetup(
environments,
new Set(environments.map((environment) => environment.environmentId)),
),
).toEqual({
ready: true,
environmentIds: [local.environmentId],
skippedIds: environments.slice(1).map((environment) => environment.environmentId),
});
});

it("waits for a first connection attempt to settle", () => {
const connecting = computer("new", "connecting");
expect(
resolveOnboardingSetup(
[local, connecting],
new Set([local.environmentId, connecting.environmentId]),
).ready,
).toBe(false);
});

it("is not ready without a connected selection", () => {
expect(resolveOnboardingSetup([local], new Set()).ready).toBe(false);
expect(
resolveOnboardingSetup([computer("off", "available")], new Set([EnvironmentId.make("off")]))
.ready,
).toBe(false);
});
});
28 changes: 28 additions & 0 deletions apps/web/src/onboarding/targetEnvironment.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,31 @@ export function resolveOnboardingTargetEnvironment<TEnvironment extends Onboardi

return mode === "local" ? null : (connectedRelayEnvironments[0] ?? null);
}

/**
* The computers the wizard sets up from the user's selection. Continue waits
* only on a first connection attempt, which settles on its own. Selected
* computers that are switched off, offline, failing, or unsupported are skipped
* so they can never lock the user out of onboarding.
*/
export function resolveOnboardingSetup(
environments: ReadonlyArray<Pick<OnboardingEnvironment, "environmentId" | "connection">>,
selectedIds: ReadonlySet<EnvironmentId>,
): {
readonly ready: boolean;
readonly environmentIds: ReadonlyArray<EnvironmentId>;
readonly skippedIds: ReadonlyArray<EnvironmentId>;
} {
const selected = environments.filter((environment) => selectedIds.has(environment.environmentId));
const idsInPhase = (keep: (phase: string) => boolean) =>
selected
.filter((environment) => keep(environment.connection.phase))
.map((environment) => environment.environmentId);
const environmentIds = idsInPhase((phase) => phase === "connected");
const settling = selected.some((environment) => environment.connection.phase === "connecting");
return {
ready: environmentIds.length > 0 && !settling,
environmentIds,
skippedIds: idsInPhase((phase) => phase !== "connected" && phase !== "connecting"),
};
}
Loading