TypeScript
fix(mobile): hide threads from switched-off environments (#16886)
Charlie J8d564a3e5c77
diff --git a/packages/client-runtime/src/state/threadShell.test.ts b/packages/client-runtime/src/state/threadShell.test.tsindex 74c93edc3a9..d3653d30035 100644--- a/packages/client-runtime/src/state/threadShell.test.ts+++ b/packages/client-runtime/src/state/threadShell.test.ts@@ -103,6 +103,30 @@ describe("v2 thread shell lists", () => {registry.dispose();});+ it("leaves switched-off environments out of navigation", () => {+ const { registry, threads, catalogValueAtom } = makeHarness([+ environmentId,+ remoteEnvironmentId,+ ]);+ const dispose = registry.mount(threads.navigationThreadShellsAtom);+ const environmentsOf = () =>+ new Set(registry.get(threads.navigationThreadShellsAtom).map((t) => t.environmentId));+ expect(environmentsOf()).toEqual(new Set([environmentId, remoteEnvironmentId]));++ const setRemoteEnabled = (enabled: boolean) => {+ const catalog = registry.get(catalogValueAtom);+ const entries = new Map(catalog.entries);+ entries.set(remoteEnvironmentId, { ...entries.get(remoteEnvironmentId)!, enabled });+ registry.set(catalogValueAtom, { ...catalog, entries });+ };+ setRemoteEnabled(false);+ expect(environmentsOf()).toEqual(new Set([environmentId]));+ setRemoteEnabled(true);+ expect(environmentsOf()).toEqual(new Set([environmentId, remoteEnvironmentId]));+ dispose();+ registry.dispose();+ });+it("shares point and list values without retaining an atom for every listed thread", () => {const harness = makeHarness();const snapshot = {diff --git a/packages/client-runtime/src/state/threadShell.ts b/packages/client-runtime/src/state/threadShell.tsindex a59fbb2375d..bc6d444f471 100644--- a/packages/client-runtime/src/state/threadShell.ts+++ b/packages/client-runtime/src/state/threadShell.ts@@ -202,7 +202,7 @@ export function createEnvironmentThreadShellAtoms(input: {let previousNavigationShells: ReadonlyArray<EnvironmentThreadShell> = [];const navigationThreadShellsAtom = Atom.make((get) => {const next: EnvironmentThreadShell[] = [];- for (const environmentId of get(input.catalogValueAtom).entries.keys()) {+ for (const environmentId of enabledEnvironmentIds(get(input.catalogValueAtom))) {for (const thread of get(environmentThreadsAtom(environmentId))) {if (thread.archivedAt !== null || thread.lineage.relationshipToParent === "subagent")continue;