Skip to content

Commit de30caf

Browse files
committed
fix(web): keep environmentPresentations where tests expect it
Moving environmentPresentations into state/server.ts broke test files that mock that module. It is back in state/presentation.ts, unchanged. The shortcut atom now reads each environment's connection and config from the catalog directly, in the same order and through the same presentEnvironmentConnection call and predicate that Settings uses.
1 parent 7f6d079 commit de30caf

2 files changed

Lines changed: 39 additions & 13 deletions

File tree

‎apps/web/src/state/presentation.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import { useAtomValue } from "@effect/atom-react";
22
import type { EnvironmentPresentation } from "@t3tools/client-runtime/connection";
3-
import { createEnvironmentSummaryAtoms } from "@t3tools/client-runtime/state/presentation";
3+
import {
4+
createEnvironmentPresentationAtoms,
5+
createEnvironmentSummaryAtoms,
6+
} from "@t3tools/client-runtime/state/presentation";
47
import type { EnvironmentId } from "@t3tools/contracts";
58
import { Atom } from "effect/unstable/reactivity";
69

710
import { environmentCatalog } from "../connection/catalog";
8-
import { environmentPresentations } from "./server";
11+
import { serverEnvironment } from "./server";
912

10-
export { environmentPresentations };
13+
export const environmentPresentations = createEnvironmentPresentationAtoms({
14+
catalogValueAtom: environmentCatalog.catalogValueAtom,
15+
stateAtom: environmentCatalog.stateAtom,
16+
serverConfigValueAtom: serverEnvironment.configValueAtom,
17+
});
1118

1219
export const environmentSummaries = createEnvironmentSummaryAtoms({
1320
catalogValueAtom: environmentCatalog.catalogValueAtom,

‎apps/web/src/state/server.ts‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import {
1010
type ServerProvider,
1111
type ServerSettings,
1212
} from "@t3tools/contracts";
13-
import type { EnvironmentPresentation } from "@t3tools/client-runtime/connection";
14-
import { createEnvironmentPresentationAtoms } from "@t3tools/client-runtime/state/presentation";
13+
import {
14+
AVAILABLE_CONNECTION_STATE,
15+
presentEnvironmentConnection,
16+
type EnvironmentPresentation,
17+
} from "@t3tools/client-runtime/connection";
1518
import { createServerEnvironmentAtoms } from "@t3tools/client-runtime/state/server";
1619
import { createOutdatedServerUpdateCommand } from "@t3tools/client-runtime/state/outdatedServerUpdate";
1720
import { createEnvironmentServerConfigsAtom } from "@t3tools/client-runtime/state/shell";
@@ -43,13 +46,6 @@ export const environmentServerConfigsAtom = createEnvironmentServerConfigsAtom({
4346
catalogValueAtom: environmentCatalog.catalogValueAtom,
4447
serverConfigValueAtom: serverEnvironment.configValueAtom,
4548
});
46-
// Lives here, not in ./presentation, so shortcuts can read connection phases
47-
// without an import cycle; ./presentation re-exports it.
48-
export const environmentPresentations = createEnvironmentPresentationAtoms({
49-
catalogValueAtom: environmentCatalog.catalogValueAtom,
50-
stateAtom: environmentCatalog.stateAtom,
51-
serverConfigValueAtom: serverEnvironment.configValueAtom,
52-
});
5349

5450
interface PrimaryServerState {
5551
readonly config: ServerConfig | null;
@@ -142,10 +138,33 @@ export function createShortcutKeybindingsAtom(input: {
142138
);
143139
}
144140

141+
// Each environment's connection and config in catalog order, presented as
142+
// ./presentation does for Settings; that module imports this one.
143+
const environmentConnectionsAtom = Atom.make((get) => {
144+
const environments = new Map<
145+
EnvironmentId,
146+
Pick<EnvironmentPresentation, "connection" | "serverConfig">
147+
>();
148+
for (const [environmentId, entry] of get(environmentCatalog.catalogValueAtom).entries) {
149+
const state = Option.getOrElse(
150+
AsyncResult.value(get(environmentCatalog.stateAtom(environmentId))),
151+
() => AVAILABLE_CONNECTION_STATE,
152+
);
153+
environments.set(environmentId, {
154+
connection:
155+
entry.unsupportedReason === undefined
156+
? presentEnvironmentConnection(state)
157+
: { phase: "unsupported", error: entry.unsupportedReason, traceId: null },
158+
serverConfig: get(serverEnvironment.configValueAtom(environmentId)),
159+
});
160+
}
161+
return environments;
162+
});
163+
145164
export const primaryServerKeybindingsAtom = createShortcutKeybindingsAtom({
146165
primaryEnvironmentIdAtom,
147166
primaryConfigAtom: primaryServerConfigAtom,
148-
environmentsAtom: environmentPresentations.presentationsAtom,
167+
environmentsAtom: environmentConnectionsAtom,
149168
}).pipe(Atom.withLabel("web-primary-server-keybindings"));
150169

151170
export const primaryServerAvailableEditorsAtom = Atom.make(

0 commit comments

Comments
 (0)