Skip to content

Commit c3b87bb

Browse files
committed
feat(web): choose whether thread details open by default
1 parent ac8dce0 commit c3b87bb

12 files changed

Lines changed: 96 additions & 21 deletions

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1931,8 +1931,16 @@ export default function ChatView(props: ChatViewProps) {
19311931
? activePreviewMiniPlayer
19321932
: null;
19331933
const canvasPreview = useThreadPreviewCanvasSource(activeThreadRef, shownPreviewMiniPlayer);
1934+
const threadDetailsOpenByDefault = useClientSettings(
1935+
(settings) => settings.threadDetailsOpenByDefault,
1936+
);
19341937
const threadPanelInlineOpen = useRightPanelStore((state) =>
1935-
selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, activeThreadRef, "inline"),
1938+
selectThreadPanelOpen(
1939+
state.threadPanelVisibilityByThreadKey,
1940+
activeThreadRef,
1941+
"inline",
1942+
threadDetailsOpenByDefault,
1943+
),
19361944
);
19371945
// Selects only the mode, so canvas resizes rerender the chat view only when the
19381946
// card switches presentation.
@@ -1952,6 +1960,7 @@ export default function ChatView(props: ChatViewProps) {
19521960
state.threadPanelVisibilityByThreadKey,
19531961
activeThreadRef,
19541962
threadPanelPresentation,
1963+
threadDetailsOpenByDefault,
19551964
),
19561965
);
19571966
const supportsThreadPullRequests = serverConfig !== null;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useStore } from "zustand";
33
import { ChatCanvasContext } from "./ChatCanvasContext";
44
import type { ChatCanvasPreview } from "./chatCanvasLayout";
55
import { resolveChatCanvasModel, type ChatCanvasStore } from "./canvasStore";
6+
import { useClientSettings } from "../../hooks/useSettings";
67
import { selectThreadPanelOpen, useRightPanelStore } from "../../rightPanelStore";
78
import { observeResize } from "../../lib/observeResize";
89
import type { ScopedThreadRef } from "@t3tools/contracts";
@@ -67,10 +68,16 @@ export function ChatCanvas({
6768
if (timelineElement) observed.push(timelineElement);
6869
return observeResize(observed, measure);
6970
}, [store, composerOverlayElement, timelineElement, detailsCardTopInset]);
71+
const inlineOpenByDefault = useClientSettings((settings) => settings.threadDetailsOpenByDefault);
7072
const detailsCardInlineOpen = useRightPanelStore((state) =>
7173
threadRef === null
7274
? false
73-
: selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, threadRef, "inline"),
75+
: selectThreadPanelOpen(
76+
state.threadPanelVisibilityByThreadKey,
77+
threadRef,
78+
"inline",
79+
inlineOpenByDefault,
80+
),
7481
);
7582
const model = resolveChatCanvasModel({
7683
measurements,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const popoverOpen = (threadRef: ScopedThreadRef) =>
3636
useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
3737
threadRef,
3838
"popover",
39+
true,
3940
);
4041

4142
function Card({

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { ScopedThreadRef } from "@t3tools/contracts";
1010
import { ScrollArea } from "../ui/scroll-area";
1111
import { cn } from "../../lib/utils";
1212
import { Popover, PopoverPopup, PopoverCreateHandle } from "../ui/popover";
13+
import { useClientSettings } from "../../hooks/useSettings";
1314
import { selectThreadPanelOpen, useRightPanelStore } from "../../rightPanelStore";
1415
import { useChatCanvas } from "./ChatCanvasContext";
1516
import {
@@ -41,11 +42,22 @@ export function ThreadDetailsCard({
4142
const placement = canvas?.detailsCardPlacement ?? null;
4243
const mode = placement ? "inline" : "popover";
4344
const topInset = canvas?.detailsCardTopInset ?? 0;
45+
const inlineOpenByDefault = useClientSettings((settings) => settings.threadDetailsOpenByDefault);
4446
const inlineOpen = useRightPanelStore((state) =>
45-
selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, threadRef, "inline"),
47+
selectThreadPanelOpen(
48+
state.threadPanelVisibilityByThreadKey,
49+
threadRef,
50+
"inline",
51+
inlineOpenByDefault,
52+
),
4653
);
4754
const popoverOpen = useRightPanelStore((state) =>
48-
selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, threadRef, "popover"),
55+
selectThreadPanelOpen(
56+
state.threadPanelVisibilityByThreadKey,
57+
threadRef,
58+
"popover",
59+
inlineOpenByDefault,
60+
),
4961
);
5062
const measurementKey = `${threadRef.environmentId}:${threadRef.threadId}:${preferredPlacement?.width ?? "popup"}:${contentKey}`;
5163
const [measurements, setMeasurements] = useState({

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ import {
1515
/** Menu body that shows and hides thread details items. The card's context menu and Settings share it. */
1616
export function ThreadDetailsItemsMenuItems() {
1717
const visibility = useClientSettings(resolveThreadDetailsVisibility);
18+
const openByDefault = useClientSettings((settings) => settings.threadDetailsOpenByDefault);
1819
return (
1920
<>
21+
<MenuCheckboxItem
22+
checked={openByDefault}
23+
onCheckedChange={(checked) => updateClientSettings({ threadDetailsOpenByDefault: checked })}
24+
>
25+
Open in new threads
26+
</MenuCheckboxItem>
27+
<MenuSeparator />
2028
<MenuGroup>
2129
<MenuGroupLabel>Show in thread details</MenuGroupLabel>
2230
{THREAD_DETAILS_ITEMS.map((item) => (
@@ -35,7 +43,7 @@ export function ThreadDetailsItemsMenuItems() {
3543
</MenuGroup>
3644
<MenuSeparator />
3745
<MenuItem
38-
disabled={isDefaultThreadDetailsVisibility(visibility)}
46+
disabled={openByDefault && isDefaultThreadDetailsVisibility(visibility)}
3947
onClick={() => updateClientSettings(RESET_THREAD_DETAILS_ITEMS)}
4048
>
4149
Reset to default

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ export function isDefaultThreadDetailsVisibility(visibility: ThreadDetailsVisibi
6161
export const RESET_THREAD_DETAILS_ITEMS = {
6262
threadDetailsItems: {},
6363
threadDetailsUsageEnabled: false,
64+
threadDetailsOpenByDefault: true,
6465
} satisfies Partial<ClientSettings>;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ThreadPreviewState } from "../../previewStateStore";
44
import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
55
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
66
import { resolveExplicitDiffOpenOnActivate } from "../ChatView.logic";
7+
import { getClientSettings } from "../../hooks/useSettings";
78
import { useStableCallback } from "../../hooks/useStableCallback";
89
import { type ScopedThreadRef, type RunId } from "@t3tools/contracts";
910
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
@@ -231,17 +232,19 @@ export function useRightPanelActions(input: RightPanelActionsInput) {
231232
const toggleThreadPanel = () => {
232233
if (!activeThreadRef) return;
233234
const store = useRightPanelStore.getState();
235+
const { threadDetailsOpenByDefault } = getClientSettings();
234236
if (threadPanelPresentation === "inline") {
235237
const open = selectThreadPanelOpen(
236238
store.threadPanelVisibilityByThreadKey,
237239
activeThreadRef,
238240
"inline",
241+
threadDetailsOpenByDefault,
239242
);
240243
if (!open) requestWorkspaceFocus({ area: "details" });
241244
else if (document.activeElement?.closest('[data-workspace-area="details"]'))
242245
requestWorkspaceContentFocus();
243246
}
244-
store.toggleThreadPanel(activeThreadRef, threadPanelPresentation);
247+
store.toggleThreadPanel(activeThreadRef, threadPanelPresentation, threadDetailsOpenByDefault);
245248
};
246249
const toggleThreadPanelStable = useStableCallback(toggleThreadPanel);
247250
const toggleRightPanelMaximized = () => {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import { searchableSetting } from "./settingsSearch";
1515

1616
export function ThreadDetailsItemsRow() {
1717
const visibility = useClientSettings(resolveThreadDetailsVisibility);
18+
const openByDefault = useClientSettings((settings) => settings.threadDetailsOpenByDefault);
1819
const enabled = THREAD_DETAILS_ITEMS.filter((item) => visibility[item.id]).length;
1920
return (
2021
<SettingsRow
2122
{...searchableSetting("thread-details-items")}
22-
description="Choose what the thread details card shows. You can also right-click the card."
23+
description="Choose what the thread details card shows and whether it opens in new threads. You can also right-click the card."
2324
resetAction={
24-
isDefaultThreadDetailsVisibility(visibility) ? null : (
25+
openByDefault && isDefaultThreadDetailsVisibility(visibility) ? null : (
2526
<SettingResetButton
2627
label="thread details"
2728
onClick={() => updateClientSettings(RESET_THREAD_DETAILS_ITEMS)}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export const SETTINGS_SEARCH_ITEMS = [
340340
title: "Thread details",
341341
to: "/settings/appearance",
342342
searchTerms: [
343-
"customize show hide panel card environment editor scripts branch pull request git changes servers automations lineage usage limits 5 hour weekly quota tokens context window",
343+
"customize show hide open closed new threads default panel card environment editor scripts branch pull request git changes servers automations lineage usage limits 5 hour weekly quota tokens context window",
344344
],
345345
},
346346
{

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
pullRequestSurfaceId,
1212
selectActiveRightPanel,
1313
selectActiveRightPanelSurface,
14+
selectThreadPanelOpen,
1415
selectThreadPanelVisibility,
1516
selectThreadRightPanelState,
1617
useRightPanelStore,
@@ -714,7 +715,30 @@ describe("rightPanelStore", () => {
714715
useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
715716
refA,
716717
),
717-
).toEqual({ inlineOpen: true, popoverOpen: false });
718+
).toEqual({ popoverOpen: false });
719+
});
720+
721+
it("follows the thread details default until the thread gets its own choice", async () => {
722+
const inlineOpen = (ref: typeof refA, openByDefault: boolean) =>
723+
selectThreadPanelOpen(
724+
useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
725+
ref,
726+
"inline",
727+
openByDefault,
728+
);
729+
730+
useRightPanelStore.getState().toggleThreadPanel(refA, "inline", false);
731+
useRightPanelStore.getState().setThreadPanelOpen(refB, "inline", true);
732+
await reloadRightPanelStore();
733+
734+
const refC = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-C"));
735+
expect(inlineOpen(refC, false)).toBe(false);
736+
expect(inlineOpen(refC, true)).toBe(true);
737+
expect(inlineOpen(refA, false)).toBe(true);
738+
expect(inlineOpen(refB, false)).toBe(true);
739+
740+
useRightPanelStore.getState().toggleThreadPanel(refA, "inline", false);
741+
expect(inlineOpen(refA, true)).toBe(false);
718742
});
719743

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

0 commit comments

Comments
 (0)