Skip to content

Commit 154914b

Browse files
committed
feat(web): choose whether thread details open by default
1 parent 8e1bb03 commit 154914b

8 files changed

Lines changed: 108 additions & 15 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,11 +979,15 @@ export default function ChatView(props: ChatViewProps) {
979979
const [threadPanelPresentation, setThreadPanelPresentation] =
980980
useState<ThreadPanelPresentation>("inline");
981981
const [threadPanelPopoverHandle] = useState(PopoverCreateHandle);
982+
const threadDetailsOpenByDefault = useClientSettings(
983+
(settings) => settings.threadDetailsOpenByDefault,
984+
);
982985
const threadPanelOpen = useRightPanelStore((state) =>
983986
selectThreadPanelOpen(
984987
state.threadPanelVisibilityByThreadKey,
985988
activeThreadRef,
986989
threadPanelPresentation,
990+
threadDetailsOpenByDefault,
987991
),
988992
);
989993

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ScopedThreadRef } from "@t3tools/contracts";
33
import { ScrollArea } from "../ui/scroll-area";
44
import { cn } from "../../lib/utils";
55
import { Popover, PopoverPopup, PopoverCreateHandle } from "../ui/popover";
6+
import { useClientSettings } from "../../hooks/useSettings";
67
import { selectThreadPanelOpen, useRightPanelStore } from "../../rightPanelStore";
78
import type { ThreadPanelPresentation } from "../../rightPanelLayout";
89
import { useChatCanvas } from "./ChatCanvasContext";
@@ -46,11 +47,22 @@ export function ThreadDetailsCard({
4647
: null;
4748
const mode = placement ? "inline" : "popover";
4849
const topInset = canvas?.detailsCardTopInset ?? 0;
50+
const inlineOpenByDefault = useClientSettings((settings) => settings.threadDetailsOpenByDefault);
4951
const inlineOpen = useRightPanelStore((state) =>
50-
selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, threadRef, "inline"),
52+
selectThreadPanelOpen(
53+
state.threadPanelVisibilityByThreadKey,
54+
threadRef,
55+
"inline",
56+
inlineOpenByDefault,
57+
),
5158
);
5259
const popoverOpen = useRightPanelStore((state) =>
53-
selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, threadRef, "popover"),
60+
selectThreadPanelOpen(
61+
state.threadPanelVisibilityByThreadKey,
62+
threadRef,
63+
"popover",
64+
inlineOpenByDefault,
65+
),
5466
);
5567
const [contentElement, setContentElement] = useState<HTMLDivElement | null>(null);
5668
const measurementKey = `${threadRef.environmentId}:${threadRef.threadId}:${preferredPlacement?.width ?? "popup"}`;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ThreadPreviewState } from "../../previewStateStore";
33
import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
44
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
55
import { resolveExplicitDiffOpenOnActivate } from "../ChatView.logic";
6+
import { getClientSettings } from "../../hooks/useSettings";
67
import { useStableCallback } from "../../hooks/useStableCallback";
78
import { type ScopedThreadRef, type RunId } from "@t3tools/contracts";
89
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
@@ -219,7 +220,13 @@ export function useRightPanelActions(input: RightPanelActionsInput) {
219220
const toggleRightPanelStable = useStableCallback(toggleRightPanel);
220221
const toggleThreadPanel = () => {
221222
if (!activeThreadRef) return;
222-
useRightPanelStore.getState().toggleThreadPanel(activeThreadRef, threadPanelPresentation);
223+
useRightPanelStore
224+
.getState()
225+
.toggleThreadPanel(
226+
activeThreadRef,
227+
threadPanelPresentation,
228+
getClientSettings().threadDetailsOpenByDefault,
229+
);
223230
};
224231
const toggleThreadPanelStable = useStableCallback(toggleThreadPanel);
225232
const toggleRightPanelMaximized = () => {

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ export function useSettingsRestore(onRestored?: () => void) {
472472
...(settings.proactivePanelsEnabled !== DEFAULT_UNIFIED_SETTINGS.proactivePanelsEnabled
473473
? ["Proactive panels"]
474474
: []),
475+
...(settings.threadDetailsOpenByDefault !== DEFAULT_UNIFIED_SETTINGS.threadDetailsOpenByDefault
476+
? ["Thread details"]
477+
: []),
475478
...(settings.showSkillsInSlashMenu !== DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu
476479
? ["Show skills in slash menu"]
477480
: []),
@@ -595,6 +598,7 @@ export function useSettingsRestore(onRestored?: () => void) {
595598
diffIgnoreWhitespace: DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace,
596599
diffLayout: DEFAULT_UNIFIED_SETTINGS.diffLayout,
597600
proactivePanelsEnabled: DEFAULT_UNIFIED_SETTINGS.proactivePanelsEnabled,
601+
threadDetailsOpenByDefault: DEFAULT_UNIFIED_SETTINGS.threadDetailsOpenByDefault,
598602
showSkillsInSlashMenu: DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu,
599603
composerCollapseOnScroll: DEFAULT_UNIFIED_SETTINGS.composerCollapseOnScroll,
600604
composerRichTextEnabled: DEFAULT_UNIFIED_SETTINGS.composerRichTextEnabled,
@@ -1349,6 +1353,33 @@ export function GeneralSettingsPanel() {
13491353
}
13501354
/>
13511355

1356+
<SettingsRow
1357+
{...searchableSetting("thread-details")}
1358+
description="Open the thread details card in threads where you haven't opened or closed it yourself."
1359+
resetAction={
1360+
settings.threadDetailsOpenByDefault !==
1361+
DEFAULT_UNIFIED_SETTINGS.threadDetailsOpenByDefault ? (
1362+
<SettingResetButton
1363+
label="thread details"
1364+
onClick={() =>
1365+
updateSettings({
1366+
threadDetailsOpenByDefault: DEFAULT_UNIFIED_SETTINGS.threadDetailsOpenByDefault,
1367+
})
1368+
}
1369+
/>
1370+
) : null
1371+
}
1372+
control={
1373+
<Switch
1374+
checked={settings.threadDetailsOpenByDefault}
1375+
onCheckedChange={(checked) =>
1376+
updateSettings({ threadDetailsOpenByDefault: Boolean(checked) })
1377+
}
1378+
aria-label="Thread details"
1379+
/>
1380+
}
1381+
/>
1382+
13521383
<SettingsRow
13531384
{...searchableSetting("skills-in-slash-menu")}
13541385
description="Also include skills in the / command menu. Skills always appear when you type $."

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ export const SETTINGS_SEARCH_ITEMS = [
450450
to: "/settings/general",
451451
searchTerms: ["automatically open diff pull request pr right panel agent completion"],
452452
},
453+
{
454+
id: "thread-details",
455+
title: "Thread details",
456+
to: "/settings/general",
457+
searchTerms: ["card panel hide collapse default new thread workspace scripts branch git"],
458+
},
453459
{
454460
id: "skills-in-slash-menu",
455461
title: "Show skills in slash menu",

‎apps/web/src/rightPanelStore.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
pullRequestSurfaceId,
1111
selectActiveRightPanel,
1212
selectActiveRightPanelSurface,
13+
selectThreadPanelOpen,
1314
selectThreadPanelVisibility,
1415
selectThreadRightPanelState,
1516
useRightPanelStore,
@@ -696,7 +697,30 @@ describe("rightPanelStore", () => {
696697
useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
697698
refA,
698699
),
699-
).toEqual({ inlineOpen: true, popoverOpen: false });
700+
).toEqual({ popoverOpen: false });
701+
});
702+
703+
it("follows the thread details default until the thread gets its own choice", async () => {
704+
const inlineOpen = (ref: typeof refA, openByDefault: boolean) =>
705+
selectThreadPanelOpen(
706+
useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
707+
ref,
708+
"inline",
709+
openByDefault,
710+
);
711+
712+
useRightPanelStore.getState().toggleThreadPanel(refA, "inline", false);
713+
useRightPanelStore.getState().setThreadPanelOpen(refB, "inline", true);
714+
await reloadRightPanelStore();
715+
716+
const refC = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-C"));
717+
expect(inlineOpen(refC, false)).toBe(false);
718+
expect(inlineOpen(refC, true)).toBe(true);
719+
expect(inlineOpen(refA, false)).toBe(true);
720+
expect(inlineOpen(refB, false)).toBe(true);
721+
722+
useRightPanelStore.getState().toggleThreadPanel(refA, "inline", false);
723+
expect(inlineOpen(refA, true)).toBe(false);
700724
});
701725

702726
it("keeps an open popover visible by promoting it to inline when the real panel closes", () => {

‎apps/web/src/rightPanelStore.ts‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ export interface ThreadRightPanelState {
9696
}
9797

9898
export interface ThreadPanelVisibility {
99-
inlineOpen: boolean;
99+
/** Absent until the user opens or closes the card here; absent threads follow the setting. */
100+
inlineOpen?: boolean;
100101
popoverOpen: boolean;
101102
}
102103

@@ -186,7 +187,11 @@ interface RightPanelStoreState {
186187
presentation: ThreadPanelPresentation,
187188
open: boolean,
188189
) => void;
189-
toggleThreadPanel: (ref: ScopedThreadRef, presentation: ThreadPanelPresentation) => void;
190+
toggleThreadPanel: (
191+
ref: ScopedThreadRef,
192+
presentation: ThreadPanelPresentation,
193+
inlineOpenByDefault: boolean,
194+
) => void;
190195
removeThread: (ref: ScopedThreadRef) => void;
191196
}
192197

@@ -196,10 +201,7 @@ const EMPTY_THREAD_STATE: ThreadRightPanelState = {
196201
surfaces: [],
197202
};
198203

199-
const DEFAULT_THREAD_PANEL_VISIBILITY: ThreadPanelVisibility = {
200-
inlineOpen: true,
201-
popoverOpen: false,
202-
};
204+
const DEFAULT_THREAD_PANEL_VISIBILITY: ThreadPanelVisibility = { popoverOpen: false };
203205

204206
const singletonSurface = (
205207
kind: Exclude<RightPanelKind, "file" | "preview" | "terminal" | "pull-request">,
@@ -329,7 +331,7 @@ const updateThreadPanelVisibilityMap = (
329331
): Record<string, ThreadPanelVisibility> => {
330332
const current = byThreadKey[threadKey] ?? DEFAULT_THREAD_PANEL_VISIBILITY;
331333
const next = updater(current);
332-
if (next.inlineOpen && !next.popoverOpen) {
334+
if (next.inlineOpen === undefined && !next.popoverOpen) {
333335
if (!(threadKey in byThreadKey)) return byThreadKey;
334336
const { [threadKey]: _removed, ...rest } = byThreadKey;
335337
return rest;
@@ -1058,14 +1060,14 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
10581060
},
10591061
),
10601062
})),
1061-
toggleThreadPanel: (ref, presentation) =>
1063+
toggleThreadPanel: (ref, presentation, inlineOpenByDefault) =>
10621064
set((state) => ({
10631065
threadPanelVisibilityByThreadKey: updateThreadPanelVisibilityMap(
10641066
state.threadPanelVisibilityByThreadKey,
10651067
scopedThreadKey(ref),
10661068
(visibility) =>
10671069
presentation === "inline"
1068-
? { ...visibility, inlineOpen: !visibility.inlineOpen }
1070+
? { ...visibility, inlineOpen: !(visibility.inlineOpen ?? inlineOpenByDefault) }
10691071
: { ...visibility, popoverOpen: !visibility.popoverOpen },
10701072
),
10711073
})),
@@ -1110,7 +1112,9 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
11101112
threadPanelVisibilityByThreadKey: Object.fromEntries(
11111113
Object.entries(state.threadPanelVisibilityByThreadKey).flatMap(
11121114
([threadKey, visibility]) =>
1113-
visibility.inlineOpen ? [] : [[threadKey, { inlineOpen: false, popoverOpen: false }]],
1115+
visibility.inlineOpen === undefined
1116+
? []
1117+
: [[threadKey, { inlineOpen: visibility.inlineOpen, popoverOpen: false }]],
11141118
),
11151119
),
11161120
}),
@@ -1165,9 +1169,12 @@ export function selectThreadPanelOpen(
11651169
byThreadKey: Record<string, ThreadPanelVisibility>,
11661170
ref: ScopedThreadRef | null | undefined,
11671171
presentation: ThreadPanelPresentation,
1172+
inlineOpenByDefault: boolean,
11681173
): boolean {
11691174
const visibility = selectThreadPanelVisibility(byThreadKey, ref);
1170-
return presentation === "inline" ? visibility.inlineOpen : visibility.popoverOpen;
1175+
return presentation === "inline"
1176+
? (visibility.inlineOpen ?? inlineOpenByDefault)
1177+
: visibility.popoverOpen;
11711178
}
11721179

11731180
export function selectActiveRightPanel(

‎packages/contracts/src/settings.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ export const ClientSettingsSchema = Schema.Struct({
434434
Schema.withDecodingDefault(Effect.succeed("steer")),
435435
),
436436
proactivePanelsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
437+
threadDetailsOpenByDefault: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
437438
showSkillsInSlashMenu: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
438439
legacySidebarEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
439440
sidebarWorkingShelfEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
@@ -1660,6 +1661,7 @@ export const ClientSettingsPatch = Schema.Struct({
16601661
sendShortcut: Schema.optionalKey(Schema.Literals(["enter", "mod-enter-multiline", "mod-enter"])),
16611662
followUpBehavior: Schema.optionalKey(Schema.Literals(["queue", "steer"])),
16621663
proactivePanelsEnabled: Schema.optionalKey(Schema.Boolean),
1664+
threadDetailsOpenByDefault: Schema.optionalKey(Schema.Boolean),
16631665
showSkillsInSlashMenu: Schema.optionalKey(Schema.Boolean),
16641666
legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),
16651667
sidebarWorkingShelfEnabled: Schema.optionalKey(Schema.Boolean),

0 commit comments

Comments
 (0)