Skip to content

Commit d7935f1

Browse files
t3dotggclaude
andauthored
feat(web): choose what the thread details card shows (#26904)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 4432fbe commit d7935f1

21 files changed

Lines changed: 514 additions & 153 deletions

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const clientSettings: ClientSettings = {
6565
boringSidebarEnabled: false,
6666
boringSidebarMultilineRows: false,
6767
threadDetailsUsageEnabled: false,
68+
threadDetailsItems: {},
6869
legacySidebarEnabled: false,
6970
sidebarWorkingShelfEnabled: false,
7071
loadBalancingEnabled: false,

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,9 +1228,6 @@ export default function ChatView(props: ChatViewProps) {
12281228
const canChangeEnvironment =
12291229
hasMultipleEnvironments && !envLocked && draftId !== null && !draftThread?.promotedTo;
12301230

1231-
const threadDetailsUsageEnabled = useClientSettings(
1232-
(settings) => settings.threadDetailsUsageEnabled,
1233-
);
12341231
const loadBalancingSettings = useClientSettings((settings) => ({
12351232
loadBalancingEnabled: settings.loadBalancingEnabled,
12361233
loadBalancingWeights: settings.loadBalancingWeights,
@@ -3773,16 +3770,12 @@ export default function ChatView(props: ChatViewProps) {
37733770
onAddProjectScript={saveProjectScriptStable}
37743771
onUpdateProjectScript={updateProjectScriptStable}
37753772
onDeleteProjectScript={deleteProjectScriptStable}
3776-
usage={
3777-
threadDetailsUsageEnabled
3778-
? {
3779-
providerInstanceId: activeProviderInstanceId,
3780-
providers: providerStatuses,
3781-
sources: serverConfig?.usageLimitSources ?? EMPTY_USAGE_LIMIT_SOURCES,
3782-
contextWindow: activeContextWindow,
3783-
}
3784-
: undefined
3785-
}
3773+
usage={{
3774+
providerInstanceId: activeProviderInstanceId,
3775+
providers: providerStatuses,
3776+
sources: serverConfig?.usageLimitSources ?? EMPTY_USAGE_LIMIT_SOURCES,
3777+
contextWindow: activeContextWindow,
3778+
}}
37863779
/>
37873780

37883781
<PullRequestThreadDialogHost

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ interface GitActionsControlProps {
117117
activeThreadRef: ScopedThreadRef | null;
118118
draftId?: DraftId;
119119
compact?: boolean;
120+
showActions?: boolean;
121+
showChanges?: boolean;
120122
onOpenChanges?: () => void;
121123
}
122124

@@ -926,6 +928,8 @@ export default function GitActionsControl({
926928
activeThreadRef,
927929
draftId,
928930
compact = false,
931+
showActions = true,
932+
showChanges = true,
929933
onOpenChanges,
930934
}: GitActionsControlProps) {
931935
const panelAnchorRef = useRef<HTMLDivElement | null>(null);
@@ -1476,7 +1480,7 @@ export default function GitActionsControl({
14761480

14771481
return (
14781482
<>
1479-
{!isRepo ? (
1483+
{!showActions ? null : !isRepo ? (
14801484
<ThreadDetailsControl
14811485
size="xs"
14821486
variant="ghost"
@@ -1618,7 +1622,7 @@ export default function GitActionsControl({
16181622
</div>
16191623
)}
16201624

1621-
{isRepo && !quietEmptyDraft ? (
1625+
{showChanges && isRepo && !quietEmptyDraft ? (
16221626
<ThreadDetailsControl
16231627
type="button"
16241628
variant="ghost"
@@ -1826,13 +1830,16 @@ export default function GitActionsControl({
18261830
</DialogPopup>
18271831
</Dialog>
18281832

1829-
<PublishRepositoryDialog
1830-
open={isPublishDialogOpen}
1831-
onOpenChange={setIsPublishDialogOpen}
1832-
environmentId={activeEnvironmentId}
1833-
threadRef={activeThreadRef}
1834-
gitCwd={gitCwd}
1835-
/>
1833+
{/* Its discovery query should stop when the Git actions row that opens it is hidden. */}
1834+
{showActions ? (
1835+
<PublishRepositoryDialog
1836+
open={isPublishDialogOpen}
1837+
onOpenChange={setIsPublishDialogOpen}
1838+
environmentId={activeEnvironmentId}
1839+
threadRef={activeThreadRef}
1840+
gitCwd={gitCwd}
1841+
/>
1842+
) : null}
18361843

18371844
<Dialog
18381845
open={pendingDefaultBranchAction !== null}

‎apps/web/src/components/chat/OpenInPicker.browser.test.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ describe("host editor access", () => {
189189
});
190190
});
191191

192+
describe("remote editor links", () => {
193+
it("opens the link from the fallback when the picker is not mounted", async () => {
194+
await using fixture = await setup();
195+
const { screen, pressOpenFavorite, FavoriteEditorFallback } = fixture;
196+
state.remote = { mode: "remote-links", host: { kind: "ssh-alias", host: "sol" } };
197+
await act(async () => screen.rerender(<FavoriteEditorFallback />));
198+
199+
expect((await pressOpenFavorite()).defaultPrevented).toBe(true);
200+
expect(state.openUrl).toHaveBeenCalledWith(expect.stringContaining("ssh-remote+sol"));
201+
expect(state.run).not.toHaveBeenCalled();
202+
});
203+
});
204+
192205
describe("open in editor announcement", () => {
193206
it("speaks only after the shortcut opened the editor, from the picker or the fallback", async () => {
194207
await using fixture = await setup();

‎apps/web/src/components/chat/OpenInPickerShortcut.ts‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import type { EditorId, EnvironmentId, ResolvedKeybindingsConfig } from "@t3tools/contracts";
1+
import {
2+
buildRemoteOpenUrl,
3+
type EditorId,
4+
type EnvironmentId,
5+
type ResolvedKeybindingsConfig,
6+
} from "@t3tools/contracts";
27
import { useEffect } from "react";
38

49
import { usePreferredEditor } from "../../editorPreferences";
510
import { editorLabelForPlatform } from "../../editorLabels";
611
import { isOpenFavoriteEditorShortcut } from "../../keybindings";
712
import { announce } from "../../lib/announce";
8-
import { useRemoteOpenState } from "../../remoteOpen";
13+
import { openRemoteEditorUrl, useRemoteCapableEditors, useRemoteOpenState } from "../../remoteOpen";
914
import { registerCommands } from "../../shortcuts/dispatcher";
1015
import { shellEnvironment } from "../../state/shell";
1116
import { useAtomCommand } from "../../state/use-atom-command";
@@ -49,18 +54,39 @@ export function useOpenFavoriteEditorShortcut({
4954
openInCwd: string | null;
5055
}) {
5156
const openInEditorMutation = useAtomCommand(shellEnvironment.openInEditor, "open in editor");
52-
const [preferredEditor] = usePreferredEditor(availableEditors);
5357
const remote = useRemoteOpenState(environmentId);
58+
const remoteCapableEditors = useRemoteCapableEditors();
59+
// Matches the picker: remote editors run on the viewing machine.
60+
const [preferredEditor] = usePreferredEditor(
61+
remote.mode === "local-exec" ? availableEditors : remoteCapableEditors,
62+
);
5463

55-
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a window keydown listener for the open-in-editor shortcut while enabled locally
64+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a window keydown listener for the open-in-editor shortcut while enabled
5665
useEffect(() => {
57-
if (!enabled || remote.mode !== "local-exec") return;
66+
if (!enabled || remote.mode === "remote-unavailable") return;
5867
const handler = (event: globalThis.KeyboardEvent) => {
59-
if (event.defaultPrevented || !isOpenFavoriteEditorShortcut(event, keybindings)) return;
68+
if (
69+
event.repeat ||
70+
event.defaultPrevented ||
71+
!isOpenFavoriteEditorShortcut(event, keybindings)
72+
)
73+
return;
6074
if (!openInCwd || !preferredEditor) return;
6175

6276
event.preventDefault();
6377
const label = editorLabelForPlatform(preferredEditor, navigator.platform);
78+
if (remote.mode === "remote-links") {
79+
const url = buildRemoteOpenUrl({
80+
editor: preferredEditor,
81+
...remote.host,
82+
absolutePath: openInCwd,
83+
});
84+
if (url === undefined) return;
85+
void openRemoteEditorUrl(url).then((opened) => {
86+
if (opened) announce(`Opened in ${label}`);
87+
});
88+
return;
89+
}
6490
void openInEditorMutation({
6591
environmentId,
6692
input: {
@@ -80,6 +106,6 @@ export function useOpenFavoriteEditorShortcut({
80106
openInCwd,
81107
openInEditorMutation,
82108
preferredEditor,
83-
remote.mode,
109+
remote,
84110
]);
85111
}

‎apps/web/src/components/chat/ThreadAutomationsPanel.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ export function ThreadAutomationsPanel(props: {
153153
</Tooltip>
154154
}
155155
>
156-
{tasksQuery.error !== null ? (
157-
<p className="px-2.5 py-1.5 text-2xs text-destructive">
158-
Could not load automations: {tasksQuery.error}
159-
</p>
160-
) : null}
161-
162156
<ul className="m-0 list-none p-0">
163157
{boundTasks.map((task) => (
164158
<li
@@ -242,6 +236,12 @@ export function ThreadAutomationsPanel(props: {
242236
</li>
243237
))}
244238
</ul>
239+
{/* Kept last: the details card treats a section whose last child is empty as empty. */}
240+
{tasksQuery.error !== null ? (
241+
<p className="px-2.5 py-1.5 text-2xs text-destructive">
242+
Could not load automations: {tasksQuery.error}
243+
</p>
244+
) : null}
245245
</ThreadDetailsSection>
246246
);
247247
}

‎apps/web/src/components/chat/ThreadDetailsCard.browser.test.tsx‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ function Card({
4242
threadRef,
4343
inline,
4444
fixture,
45+
rows = 1,
4546
}: {
4647
threadRef: ScopedThreadRef;
4748
inline: boolean;
4849
fixture: ReturnType<typeof setup>;
50+
/** Rows of 100px shown at full density. Compact always takes 50px. */
51+
rows?: number;
4952
}) {
5053
return (
5154
// The web root renders in StrictMode, which re-runs ref callbacks on every mount.
@@ -63,8 +66,17 @@ function Card({
6366
detailsCardPlacement: inline ? placement : null,
6467
}}
6568
>
66-
<ThreadDetailsCard threadRef={threadRef} anchor={fixture.anchor} handle={fixture.handle}>
67-
{() => <p>Details for {threadRef.threadId}</p>}
69+
<ThreadDetailsCard
70+
threadRef={threadRef}
71+
anchor={fixture.anchor}
72+
handle={fixture.handle}
73+
contentKey={String(rows)}
74+
>
75+
{(density) => (
76+
<p style={{ height: density === "full" ? rows * 100 : 50 }}>
77+
Details for {threadRef.threadId}
78+
</p>
79+
)}
6880
</ThreadDetailsCard>
6981
</ChatCanvasContext>
7082
</StrictMode>
@@ -136,3 +148,13 @@ it("reopens after a normal close", async () => {
136148
await setOpen(true);
137149
await expect.element(page.getByText("Details for thread-b")).toBeVisible();
138150
});
151+
152+
it("returns to full density when hidden items make the content fit", async () => {
153+
using fixture = setup();
154+
await using screen = await render(<Card threadRef={threadB} inline fixture={fixture} rows={6} />);
155+
const card = page.getByRole("region", { name: "Thread details" });
156+
await expect.element(card).toHaveAttribute("data-density", "compact");
157+
158+
await screen.rerender(<Card threadRef={threadB} inline fixture={fixture} rows={2} />);
159+
await expect.element(card).toHaveAttribute("data-density", "full");
160+
});

‎apps/web/src/components/chat/ThreadDetailsCard.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { workspaceAreaProps } from "../../lib/workspaceFocus";
2-
import { useLayoutEffect, useState, type ReactNode, type RefObject } from "react";
2+
import {
3+
useLayoutEffect,
4+
useState,
5+
type MouseEventHandler,
6+
type ReactNode,
7+
type RefObject,
8+
} from "react";
39
import type { ScopedThreadRef } from "@t3tools/contracts";
410
import { ScrollArea } from "../ui/scroll-area";
511
import { cn } from "../../lib/utils";
@@ -17,11 +23,16 @@ export function ThreadDetailsCard({
1723
threadRef,
1824
anchor,
1925
handle,
26+
contentKey,
27+
onContextMenu,
2028
children,
2129
}: {
2230
threadRef: ScopedThreadRef;
2331
anchor: RefObject<Element | null>;
2432
handle: ReturnType<typeof PopoverCreateHandle>;
33+
/** Changes when the set of rendered items changes, so cached heights are measured again. */
34+
contentKey: string;
35+
onContextMenu?: MouseEventHandler<HTMLDivElement>;
2536
children: (density: "full" | "compact" | "essential") => ReactNode;
2637
}) {
2738
const detailsArea = workspaceAreaProps("details", 3, "Thread details");
@@ -36,7 +47,7 @@ export function ThreadDetailsCard({
3647
const popoverOpen = useRightPanelStore((state) =>
3748
selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, threadRef, "popover"),
3849
);
39-
const measurementKey = `${threadRef.environmentId}:${threadRef.threadId}:${preferredPlacement?.width ?? "popup"}`;
50+
const measurementKey = `${threadRef.environmentId}:${threadRef.threadId}:${preferredPlacement?.width ?? "popup"}:${contentKey}`;
4051
const [measurements, setMeasurements] = useState({
4152
key: measurementKey,
4253
heights: { full: 0, compact: 0 },
@@ -109,6 +120,7 @@ export function ThreadDetailsCard({
109120
"max-h-[min(calc(100dvh-6.5rem),calc(var(--available-height,100dvh)-1rem))]",
110121
)}
111122
style={placement ? { maxHeight: height } : undefined}
123+
onContextMenu={onContextMenu}
112124
data-thread-details-card
113125
>
114126
<ScrollArea scrollFade className="min-h-0">
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
getClientSettings,
3+
updateClientSettings,
4+
useClientSettings,
5+
} from "../../hooks/useSettings";
6+
import { MenuCheckboxItem, MenuGroup, MenuGroupLabel, MenuItem, MenuSeparator } from "../ui/menu";
7+
import {
8+
isDefaultThreadDetailsVisibility,
9+
resolveThreadDetailsVisibility,
10+
RESET_THREAD_DETAILS_ITEMS,
11+
setThreadDetailsItem,
12+
THREAD_DETAILS_ITEMS,
13+
} from "./threadDetailsItems";
14+
15+
/** Menu body that shows and hides thread details items. The card's context menu and Settings share it. */
16+
export function ThreadDetailsItemsMenuItems() {
17+
const visibility = useClientSettings(resolveThreadDetailsVisibility);
18+
return (
19+
<>
20+
<MenuGroup>
21+
<MenuGroupLabel>Show in thread details</MenuGroupLabel>
22+
{THREAD_DETAILS_ITEMS.map((item) => (
23+
<MenuCheckboxItem
24+
key={item.id}
25+
checked={visibility[item.id]}
26+
onCheckedChange={(checked) =>
27+
updateClientSettings({
28+
threadDetailsItems: setThreadDetailsItem(getClientSettings(), item, checked),
29+
})
30+
}
31+
>
32+
{item.label}
33+
</MenuCheckboxItem>
34+
))}
35+
</MenuGroup>
36+
<MenuSeparator />
37+
<MenuItem
38+
disabled={isDefaultThreadDetailsVisibility(visibility)}
39+
onClick={() => updateClientSettings(RESET_THREAD_DETAILS_ITEMS)}
40+
>
41+
Reset to default
42+
</MenuItem>
43+
</>
44+
);
45+
}

0 commit comments

Comments
 (0)