Skip to content

Commit 4b88862

Browse files
PR Batch Testerclaude
andcommitted
fix(clients): the switched-off question names a few computers, not all
With many switched-off computers the question listed every name and the text ran past the dialog. It now names the first three and says how many more, and the failure message does the same. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e4239ca commit 4b88862

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

‎apps/mobile/src/components/SwitchedOffEnvironmentsNotice.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { useAtomValue } from "@effect/atom-react";
2-
import { switchedOffSavedEnvironments } from "@t3tools/client-runtime/state/connections";
2+
import {
3+
summarizeEnvironmentLabels,
4+
switchedOffSavedEnvironments,
5+
} from "@t3tools/client-runtime/state/connections";
36
import { isAtomCommandInterrupted } from "@t3tools/client-runtime/state/runtime";
47
import * as SecureStore from "expo-secure-store";
58
import { useEffect, useState } from "react";
@@ -51,7 +54,7 @@ export function SwitchedOffEnvironmentsNotice() {
5154
return;
5255
}
5356
const one = switchedOff.length === 1;
54-
const names = switchedOff.map(({ label }) => label).join(", ");
57+
const names = summarizeEnvironmentLabels(switchedOff);
5558
Alert.alert(
5659
one ? `${names} is switched off` : `${switchedOff.length} computers are switched off`,
5760
`${one ? "" : `${names}. `}An earlier update could switch computers off by mistake. Turn ${one ? "it" : "them"} back on to see ${one ? "its" : "their"} threads again.`,
@@ -81,7 +84,7 @@ export function SwitchedOffEnvironmentsNotice() {
8184
// An interrupted switch stays unanswered but is not an error to show.
8285
if (failed.length === 0) return;
8386
Alert.alert(
84-
`Could not switch on ${failed.map(({ environment }) => environment.label).join(", ")}`,
87+
`Could not switch on ${summarizeEnvironmentLabels(failed.map(({ environment }) => environment))}`,
8588
`Switch ${failed.length === 1 ? "it" : "them"} on in Settings → Environments.`,
8689
);
8790
},

‎apps/web/src/components/SwitchedOffEnvironmentsNotice.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { useAtomValue } from "@effect/atom-react";
2-
import { switchedOffSavedEnvironments } from "@t3tools/client-runtime/state/connections";
2+
import {
3+
summarizeEnvironmentLabels,
4+
switchedOffSavedEnvironments,
5+
} from "@t3tools/client-runtime/state/connections";
36
import { isAtomCommandInterrupted } from "@t3tools/client-runtime/state/runtime";
47
import * as Schema from "effect/Schema";
58
import { useEffect } from "react";
@@ -75,12 +78,12 @@ export function SwitchedOffEnvironmentsNotice() {
7578
toastManager.add(
7679
stackedThreadToast({
7780
type: "error",
78-
title: `Could not switch on ${failed.map(({ environment }) => environment.label).join(", ")}`,
81+
title: `Could not switch on ${summarizeEnvironmentLabels(failed.map(({ environment }) => environment))}`,
7982
description: `Switch ${failed.length === 1 ? "it" : "them"} on in Settings → Connections.`,
8083
}),
8184
);
8285
};
83-
const names = switchedOff.map(({ label }) => label).join(", ");
86+
const names = summarizeEnvironmentLabels(switchedOff);
8487
const id = toastManager.add({
8588
title:
8689
switchedOff.length === 1
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, expect, it } from "@effect/vitest";
2+
3+
import { summarizeEnvironmentLabels } from "./connections.ts";
4+
5+
const named = (...labels: ReadonlyArray<string>) => labels.map((label) => ({ label }));
6+
7+
describe("summarizeEnvironmentLabels", () => {
8+
it("lists every name when there are only a few", () => {
9+
expect(summarizeEnvironmentLabels(named("laptop", "server"))).toBe("laptop, server");
10+
});
11+
12+
it("names the first few and counts the rest", () => {
13+
expect(summarizeEnvironmentLabels(named("a", "b", "c", "d", "e"))).toBe("a, b, c and 2 more");
14+
});
15+
});

‎packages/client-runtime/src/state/connections.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ export function switchedOffSavedEnvironments(
5555
.map(([environmentId, entry]) => ({ environmentId, label: entry.target.label }));
5656
}
5757

58+
/** Names for a notice line: the first few, then how many more. */
59+
export function summarizeEnvironmentLabels(
60+
environments: ReadonlyArray<{ readonly label: string }>,
61+
shown = 3,
62+
): string {
63+
const names = environments.slice(0, shown).map(({ label }) => label);
64+
const rest = environments.length - names.length;
65+
return rest > 0 ? `${names.join(", ")} and ${rest} more` : names.join(", ");
66+
}
67+
5868
const EMPTY_ENVIRONMENT_CATALOG_STATE: EnvironmentCatalogState = Object.freeze({
5969
isReady: false,
6070
entries: new Map(),

0 commit comments

Comments
 (0)