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
52 changes: 51 additions & 1 deletion apps/web/src/app/(authenticated)/home/Home.client.test.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 39 additions & 7 deletions apps/web/src/app/(authenticated)/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,52 @@ export function Home({
| WorkspaceSelection['workspace']
| undefined;

if (!restoredWorkspace || restoredWorkspace.type === 'auto') {
form.setValue('repository', AUTO_WORKSPACE_VALUE);
form.setValue('environmentId', undefined);
form.setValue('branch', '');
} else if (restoredWorkspace.type === 'repository') {
if (restoredWorkspace?.type === 'repository') {
form.setValue('repository', restoredWorkspace.value);
form.setValue('environmentId', undefined);
} else if (restoredWorkspace.type === 'environment') {
hasRestoredWorkspace.current = true;
return;
}

if (restoredWorkspace?.type === 'environment') {
form.setValue('repository', restoredWorkspace.id);
form.setValue('environmentId', restoredWorkspace.id);
hasRestoredWorkspace.current = true;
return;
}

// Auto (or unset) stored preference: wait for environments so we can
// default the sole environment instead of writing Auto over the selector.
if (environments.isPending || !environments.isSuccess) {
return;
}

const soleEnvironment =
environments.data?.length === 1 ? environments.data[0] : undefined;

if (soleEnvironment) {
form.setValue('repository', soleEnvironment.id);
form.setValue('environmentId', soleEnvironment.id);
form.setValue('branch', '');
setWorkspace({
workspace: { type: 'environment', id: soleEnvironment.id },
});
} else {
form.setValue('repository', AUTO_WORKSPACE_VALUE);
form.setValue('environmentId', undefined);
form.setValue('branch', '');
}

hasRestoredWorkspace.current = true;
}, [environmentIdParam, form, setWorkspace, workspace]);
}, [
environmentIdParam,
environments.data,
environments.isPending,
environments.isSuccess,
form,
setWorkspace,
workspace,
]);

const wiggleWorkspace = useCallback(() => {
const el = workspaceRef.current;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion apps/web/src/app/(onboarding)/onboarding/StepInvoke.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ export function StepInvoke({
queryKey: trpc.github.installations.queryKey(),
});

const envs = environments.data;
// Environment may have just been created; refresh so Home can default
// to the sole environment via environmentId immediately after setup.
let envs = environments.data;
try {
const refreshed = await queryClient.fetchQuery(
trpc.environments.list.queryOptions(undefined, { staleTime: 0 }),
);
if (Array.isArray(refreshed)) {
envs = refreshed;
}
} catch {
// Fall back to whatever is already cached.
}

const targetEnv = envs?.[0];

if (targetEnv) {
Expand Down
19 changes: 16 additions & 3 deletions apps/web/src/app/(onboarding)/setup/StepInvoke.client.test.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion apps/web/src/app/(onboarding)/setup/StepInvoke.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,20 @@ export function StepInvoke({
return;
}

const envs = environments.data;
// Environment setup may have just written the first environment. Refresh
// before redirecting so Home can select it via environmentId.
let envs = environments.data;
try {
const refreshed = await queryClient.fetchQuery(
trpc.environments.list.queryOptions(undefined, { staleTime: 0 }),
);
if (Array.isArray(refreshed)) {
envs = refreshed;
}
} catch {
// Fall back to whatever is already cached.
}

const params = new URLSearchParams();
const targetEnv = envs?.[0];

Expand Down
Loading
Loading