Skip to content

Commit ec5d1c0

Browse files
committed
fix(web): describe split terminal closes
1 parent a620ebe commit ec5d1c0

4 files changed

Lines changed: 40 additions & 12 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,7 +3464,7 @@ function ChatViewContent(props: ChatViewProps) {
34643464
const requestCloseTerminal = useCallback(
34653465
(terminalId: string) => {
34663466
const label = activeTerminalLabelsById.get(terminalId) ?? getTerminalLabel(terminalId);
3467-
void confirmTerminalClose(label).then((confirmed) => {
3467+
void confirmTerminalClose([label]).then((confirmed) => {
34683468
if (confirmed) closeTerminal(terminalId);
34693469
});
34703470
},
@@ -3473,7 +3473,7 @@ function ChatViewContent(props: ChatViewProps) {
34733473
const requestClosePanelTerminal = useCallback(
34743474
(terminalId: string) => {
34753475
const label = activeTerminalLabelsById.get(terminalId) ?? getTerminalLabel(terminalId);
3476-
void confirmTerminalClose(label).then((confirmed) => {
3476+
void confirmTerminalClose([label]).then((confirmed) => {
34773477
if (confirmed) closePanelTerminal(terminalId);
34783478
});
34793479
},
@@ -3562,10 +3562,15 @@ function ChatViewContent(props: ChatViewProps) {
35623562
finishClose();
35633563
return;
35643564
}
3565-
const label =
3565+
const activeLabel =
35663566
activeTerminalLabelsById.get(surface.activeTerminalId) ??
35673567
getTerminalLabel(surface.activeTerminalId);
3568-
void confirmTerminalClose(label).then((confirmed) => {
3568+
const otherLabels = surface.terminalIds
3569+
.filter((terminalId) => terminalId !== surface.activeTerminalId)
3570+
.map(
3571+
(terminalId) => activeTerminalLabelsById.get(terminalId) ?? getTerminalLabel(terminalId),
3572+
);
3573+
void confirmTerminalClose([activeLabel, ...otherLabels]).then((confirmed) => {
35693574
if (confirmed) finishClose();
35703575
});
35713576
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ export default function ThreadTerminalDrawer({
12771277
const confirmCloseTerminal = useCallback(
12781278
(terminalId: string) => {
12791279
const label = terminalLabelById.get(terminalId) ?? getTerminalLabel(terminalId);
1280-
void confirmTerminalClose(label).then((confirmed) => {
1280+
void confirmTerminalClose([label]).then((confirmed) => {
12811281
if (confirmed) onCloseTerminal(terminalId);
12821282
});
12831283
},

‎apps/web/src/lib/terminalCloseConfirm.test.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("terminal close confirmation", () => {
3131

3232
expect(isTerminalCloseConfirmPending()).toBe(false);
3333

34-
const confirmation = confirmTerminalClose("Terminal 1");
34+
const confirmation = confirmTerminalClose(["Terminal 1"]);
3535
expect(isTerminalCloseConfirmPending()).toBe(true);
3636

3737
settle(true);
@@ -48,18 +48,31 @@ describe("terminal close confirmation", () => {
4848
}),
4949
);
5050

51-
const confirmation = confirmTerminalClose("Terminal 1");
51+
const confirmation = confirmTerminalClose(["Terminal 1"]);
5252
expect(isTerminalCloseConfirmPending()).toBe(true);
5353

5454
reject(new Error("dialog failed"));
5555
await expect(confirmation).resolves.toBe(false);
5656
expect(isTerminalCloseConfirmPending()).toBe(false);
5757
});
5858

59+
it("names every terminal in a multi-terminal close", async () => {
60+
confirmMock.mockResolvedValue(true);
61+
62+
await expect(confirmTerminalClose(["Terminal 1", "Development server"])).resolves.toBe(true);
63+
expect(confirmMock).toHaveBeenCalledWith(
64+
[
65+
"Close 2 terminals?",
66+
'This stops their running processes and clears their histories: "Terminal 1", "Development server".',
67+
].join("\n"),
68+
{ variant: "destructive" },
69+
);
70+
});
71+
5972
it("closes without prompting when no local API is available", async () => {
6073
readLocalApiMock.mockReturnValue(undefined);
6174

62-
await expect(confirmTerminalClose("Terminal 1")).resolves.toBe(true);
75+
await expect(confirmTerminalClose(["Terminal 1"])).resolves.toBe(true);
6376
expect(confirmMock).not.toHaveBeenCalled();
6477
});
6578
});

‎apps/web/src/lib/terminalCloseConfirm.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ export function isTerminalCloseConfirmPending(): boolean {
1313
* the tab strip. Auto-exit cleanup and bulk tab closes skip this path and close
1414
* directly.
1515
*/
16-
export async function confirmTerminalClose(label: string): Promise<boolean> {
16+
export async function confirmTerminalClose(
17+
labels: readonly [string, ...string[]],
18+
): Promise<boolean> {
1719
const localApi = readLocalApi();
1820
if (!localApi) return true;
1921
pendingConfirmations += 1;
2022
try {
2123
return await localApi.dialogs.confirm(
22-
[`Close terminal "${label}"?`, "This stops the running process and clears its history."].join(
23-
"\n",
24-
),
24+
labels.length === 1
25+
? [
26+
`Close terminal "${labels[0]}"?`,
27+
"This stops the running process and clears its history.",
28+
].join("\n")
29+
: [
30+
`Close ${labels.length} terminals?`,
31+
`This stops their running processes and clears their histories: ${labels
32+
.map((label) => `"${label}"`)
33+
.join(", ")}.`,
34+
].join("\n"),
2535
{ variant: "destructive" },
2636
);
2737
} catch {

0 commit comments

Comments
 (0)