| author | |
| committer | |
| log | 035058a23e651ea5f407c9ab73cf5329cc40c102 |
| tree | 62b54752c2635f22c4aba2ae6e30891df26ec4fb |
| parent | 421088c27367da227d922ce999c1637416a6d0f4 |
| signature | Signed by PGP key B5690EEEBB952194 |
3 files changed, 51 insertions(+), 5 deletions(-)
apps/mobile/src/features/connection/environmentSections.test.ts+30-1| ... | ... | @@ -2,7 +2,7 @@ import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | 2 | import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay"; |
| 3 | 3 | import { describe, expect, it } from "vite-plus/test"; |
| 4 | 4 | import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types"; |
| 5 | import { splitEnvironmentSections } from "./environmentSections"; | |
| 5 | import { relayManagedEnvironmentIds, splitEnvironmentSections } from "./environmentSections"; | |
| 6 | 6 | |
| 7 | 7 | function connectedEnvironment( |
| 8 | 8 | input: Omit<Partial<ConnectedEnvironmentSummary>, "environmentId"> & { |
| ... | ... | @@ -34,6 +34,17 @@ function cloudEnvironment(environmentId: string): RelayClientEnvironmentRecord { |
| 34 | 34 | }; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | describe("relayManagedEnvironmentIds", () => { | |
| 38 | it("leaves out a backend that was saved directly", () => { | |
| 39 | const ids = relayManagedEnvironmentIds([ | |
| 40 | connectedEnvironment({ environmentId: "environment-local", isRelayManaged: false }), | |
| 41 | connectedEnvironment({ environmentId: "environment-cloud", isRelayManaged: true }), | |
| 42 | ]); | |
| 43 | ||
| 44 | expect([...ids]).toEqual([EnvironmentId.make("environment-cloud")]); | |
| 45 | }); | |
| 46 | }); | |
| 47 | ||
| 37 | 48 | describe("mobile environment settings sections", () => { |
| 38 | 49 | it("keeps saved relay-managed connections under T3 Connect", () => { |
| 39 | 50 | const local = connectedEnvironment({ |
| ... | ... | @@ -111,6 +122,24 @@ describe("mobile environment settings sections", () => { |
| 111 | 122 | expect(sections.availableCloudEnvironments).toEqual([]); |
| 112 | 123 | }); |
| 113 | 124 | |
| 125 | it("still offers a cloud environment saved directly as a local backend", () => { | |
| 126 | const local = connectedEnvironment({ | |
| 127 | environmentId: "environment-cloud", | |
| 128 | isRelayManaged: false, | |
| 129 | }); | |
| 130 | ||
| 131 | const sections = splitEnvironmentSections({ | |
| 132 | connectedEnvironments: [local], | |
| 133 | cloudEnvironments: [cloudEnvironment("environment-cloud")], | |
| 134 | }); | |
| 135 | ||
| 136 | expect(sections.localEnvironments).toEqual([local]); | |
| 137 | expect(sections.connectedCloudEnvironments).toEqual([]); | |
| 138 | expect( | |
| 139 | sections.availableCloudEnvironments.map((environment) => environment.environmentId), | |
| 140 | ).toEqual([EnvironmentId.make("environment-cloud")]); | |
| 141 | }); | |
| 142 | ||
| 114 | 143 | it("keeps failed relay environments in the local connection row", () => { |
| 115 | 144 | const cloud = connectedEnvironment({ |
| 116 | 145 | environmentId: "environment-cloud", |
apps/mobile/src/features/connection/environmentSections.ts+19-3| ... | ... | @@ -1,3 +1,4 @@ |
| 1 | import type { EnvironmentId } from "@t3tools/contracts"; | |
| 1 | 2 | import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay"; |
| 2 | 3 | import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types"; |
| 3 | 4 | |
| ... | ... | @@ -12,10 +13,25 @@ export interface EnvironmentSections { |
| 12 | 13 | readonly availableCloudEnvironments: ReadonlyArray<RelayClientEnvironmentRecord>; |
| 13 | 14 | } |
| 14 | 15 | |
| 15 | export function splitEnvironmentSections(input: EnvironmentSectionsInput): EnvironmentSections { | |
| 16 | const savedEnvironmentIds = new Set( | |
| 17 | input.connectedEnvironments.map((environment) => environment.environmentId), | |
| 16 | /** | |
| 17 | * Ids of the environments that already occupy a T3 Connect slot. A backend saved directly is | |
| 18 | * not one of them, so it must not suppress the cloud environment that happens to share its id. | |
| 19 | */ | |
| 20 | export function relayManagedEnvironmentIds( | |
| 21 | environments: ReadonlyArray<{ | |
| 22 | readonly environmentId: EnvironmentId; | |
| 23 | readonly isRelayManaged: boolean; | |
| 24 | }>, | |
| 25 | ): ReadonlySet<EnvironmentId> { | |
| 26 | return new Set( | |
| 27 | environments | |
| 28 | .filter((environment) => environment.isRelayManaged) | |
| 29 | .map((environment) => environment.environmentId), | |
| 18 | 30 | ); |
| 31 | } | |
| 32 | ||
| 33 | export function splitEnvironmentSections(input: EnvironmentSectionsInput): EnvironmentSections { | |
| 34 | const savedEnvironmentIds = relayManagedEnvironmentIds(input.connectedEnvironments); | |
| 19 | 35 | |
| 20 | 36 | return { |
| 21 | 37 | localEnvironments: input.connectedEnvironments.filter( |
apps/mobile/src/features/connection/useConnectionController.ts+2-1| ... | ... | @@ -20,6 +20,7 @@ import { useEnvironments } from "../../state/environments"; |
| 20 | 20 | import { relayEnvironmentDiscovery } from "../../state/relay"; |
| 21 | 21 | import { useAtomCommand } from "../../state/use-atom-command"; |
| 22 | 22 | import { projectWorkspaceEnvironment, type WorkspaceEnvironment } from "../../state/workspaceModel"; |
| 23 | import { relayManagedEnvironmentIds } from "./environmentSections"; | |
| 23 | 24 | |
| 24 | 25 | export interface RelayEnvironmentView { |
| 25 | 26 | readonly environment: RelayClientEnvironmentRecord; |
| ... | ... | @@ -49,7 +50,7 @@ export function useConnectionController() { |
| 49 | 50 | [environments], |
| 50 | 51 | ); |
| 51 | 52 | const registeredIds = useMemo( |
| 52 | () => new Set(connectedEnvironments.map((environment) => environment.environmentId)), | |
| 53 | () => relayManagedEnvironmentIds(connectedEnvironments), | |
| 53 | 54 | [connectedEnvironments], |
| 54 | 55 | ); |
| 55 | 56 | const relayEnvironments = useMemo<ReadonlyArray<RelayEnvironmentView>>( |