Skip to content

Commit 6da69f3

Browse files
committed
feat(web): choose whether thread details open by default
1 parent 5432d8e commit 6da69f3

8 files changed

Lines changed: 107 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
@@ -985,11 +985,15 @@ export default function ChatView(props: ChatViewProps) {
985985
const [threadPanelPresentation, setThreadPanelPresentation] =
986986
useState<ThreadPanelPresentation>("inline");
987987
const [threadPanelPopoverHandle] = useState(PopoverCreateHandle);
988+
const threadDetailsOpenByDefault = useClientSettings(
989+
(settings) => settings.threadDetailsOpenByDefault,
990+
);
988991
const threadPanelOpen = useRightPanelStore((state) =>
989992
selectThreadPanelOpen(
990993
state.threadPanelVisibilityByThreadKey,
991994
activeThreadRef,
992995
threadPanelPresentation,
996+
threadDetailsOpenByDefault,
993997
),
994998
);
995999

‎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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ export function useSettingsRestore(onRestored?: () => void) {
477477
...(settings.composerCollapseOnScroll !== DEFAULT_UNIFIED_SETTINGS.composerCollapseOnScroll
478478
? ["Collapse composer on scroll"]
479479
: []),
480+
...(settings.threadDetailsOpenByDefault !== DEFAULT_UNIFIED_SETTINGS.threadDetailsOpenByDefault
481+
? ["Thread details"]
482+
: []),
480483
...(settings.composerRichTextEnabled !== DEFAULT_UNIFIED_SETTINGS.composerRichTextEnabled
481484
? ["Rich text composer"]
482485
: []),
@@ -596,6 +599,7 @@ export function useSettingsRestore(onRestored?: () => void) {
596599
proactivePanelsEnabled: DEFAULT_UNIFIED_SETTINGS.proactivePanelsEnabled,
597600
showSkillsInSlashMenu: DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu,
598601
composerCollapseOnScroll: DEFAULT_UNIFIED_SETTINGS.composerCollapseOnScroll,
602+
threadDetailsOpenByDefault: DEFAULT_UNIFIED_SETTINGS.threadDetailsOpenByDefault,
599603
composerRichTextEnabled: DEFAULT_UNIFIED_SETTINGS.composerRichTextEnabled,
600604
sendShortcut: DEFAULT_UNIFIED_SETTINGS.sendShortcut,
601605
followUpBehavior: DEFAULT_UNIFIED_SETTINGS.followUpBehavior,
@@ -1153,6 +1157,32 @@ export function ChatSettingsPanel() {
11531157
/>
11541158
}
11551159
/>
1160+
<SettingsRow
1161+
{...searchableSetting("thread-details")}
1162+
description="Open the thread details card in threads where you haven't opened or closed it yourself."
1163+
resetAction={
1164+
settings.threadDetailsOpenByDefault !==
1165+
DEFAULT_UNIFIED_SETTINGS.threadDetailsOpenByDefault ? (
1166+
<SettingResetButton
1167+
label="thread details"
1168+
onClick={() =>
1169+
updateSettings({
1170+
threadDetailsOpenByDefault: DEFAULT_UNIFIED_SETTINGS.threadDetailsOpenByDefault,
1171+
})
1172+
}
1173+
/>
1174+
) : null
1175+
}
1176+
control={
1177+
<Switch
1178+
checked={settings.threadDetailsOpenByDefault}
1179+
onCheckedChange={(checked) =>
1180+
updateSettings({ threadDetailsOpenByDefault: Boolean(checked) })
1181+
}
1182+
aria-label="Thread details"
1183+
/>
1184+
}
1185+
/>
11561186
<AdvancedSettings targetIds={[searchableSetting("skills-in-slash-menu").id]}>
11571187
<SettingsRow
11581188
{...searchableSetting("skills-in-slash-menu")}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,12 @@ export const SETTINGS_SEARCH_ITEMS = [
530530
to: "/settings/chat",
531531
searchTerms: ["composer rest resting scroll wheel conversation timeline shrink minimize"],
532532
},
533+
{
534+
id: "thread-details",
535+
title: "Thread details",
536+
to: "/settings/chat",
537+
searchTerms: ["card panel hide collapse default new thread workspace scripts branch git"],
538+
},
533539
{
534540
id: "send-shortcut",
535541
title: "Send shortcut",

‎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)