fix(web): simplify changed files into a persistent folder tree (#9821)
This commit is contained in:
1 parent
b906ce2d73
commit
dd7bc147f7
6 files changed
+57
-166
No files matched your search
@@ -10,26 +10,21 @@ describe("ChangedFilesCard", () => {
|
||||
<ChangedFilesCard
|
||||
turnId={TurnId.make("turn-1")}
|
||||
files={[{ path: "README.md", kind: "modified", additions: 2, deletions: 1 }]}
|
||||
expanded
|
||||
showCompactPreview={false}
|
||||
allDirectoriesExpanded
|
||||
resolvedTheme="light"
|
||||
onExpandedChange={() => {}}
|
||||
onToggleAllDirectories={() => {}}
|
||||
onOpenTurnDiff={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-changed-files-state="expanded"');
|
||||
expect(markup).toContain('aria-expanded="true"');
|
||||
expect(markup).toContain('aria-label="Collapse all folders"');
|
||||
expect(markup).toContain('data-changed-files-state="tree"');
|
||||
expect(markup).toContain('aria-label="Open diff"');
|
||||
expect(markup).toContain('role="group" aria-label="2 additions, 1 deletions"');
|
||||
expect(markup).toContain("1 changed file");
|
||||
expect(markup).not.toContain("1 changed files");
|
||||
});
|
||||
|
||||
it("renders a scope and representative-file preview for a large latest change", () => {
|
||||
it("shows collapsed folders and root files together", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ChangedFilesCard
|
||||
turnId={TurnId.make("turn-1")}
|
||||
@@ -44,46 +39,39 @@ describe("ChangedFilesCard", () => {
|
||||
},
|
||||
{ path: "README.md", kind: "modified", additions: 3, deletions: 0 },
|
||||
]}
|
||||
expanded={false}
|
||||
showCompactPreview
|
||||
allDirectoriesExpanded={false}
|
||||
resolvedTheme="light"
|
||||
onExpandedChange={() => {}}
|
||||
onToggleAllDirectories={() => {}}
|
||||
onOpenTurnDiff={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-changed-files-state="preview"');
|
||||
expect(markup).toContain('data-changed-files-state="tree"');
|
||||
expect(markup).toContain('aria-expanded="false"');
|
||||
expect(markup).toContain("apps");
|
||||
expect(markup).toContain("2 files");
|
||||
expect(markup).toContain("packages");
|
||||
expect(markup).toContain("root");
|
||||
expect(markup).toContain("App.tsx");
|
||||
expect(markup).toContain("git.ts");
|
||||
expect(markup).toContain("apps/web/src");
|
||||
expect(markup).not.toContain("App.tsx");
|
||||
expect(markup).toContain("packages/shared/src");
|
||||
expect(markup).not.toContain("git.ts");
|
||||
expect(markup).toContain("README.md");
|
||||
expect(markup).toContain("Show all 4 files");
|
||||
expect(markup).not.toContain("Show all");
|
||||
expect(markup).not.toContain("App.test.tsx");
|
||||
});
|
||||
|
||||
it("keeps older collapsed changes to a one-line receipt", () => {
|
||||
it("keeps the folder tree visible when folders are collapsed", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ChangedFilesCard
|
||||
turnId={TurnId.make("turn-1")}
|
||||
files={[{ path: "apps/web/src/App.tsx", kind: "modified", additions: 120, deletions: 20 }]}
|
||||
expanded={false}
|
||||
showCompactPreview={false}
|
||||
allDirectoriesExpanded={false}
|
||||
resolvedTheme="light"
|
||||
onExpandedChange={() => {}}
|
||||
onToggleAllDirectories={() => {}}
|
||||
onOpenTurnDiff={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-changed-files-state="collapsed"');
|
||||
expect(markup).toContain('data-changed-files-state="tree"');
|
||||
expect(markup).toContain("1 changed file");
|
||||
expect(markup).toContain("apps/web/src");
|
||||
expect(markup).not.toContain("Show all");
|
||||
expect(markup).not.toContain("App.tsx");
|
||||
});
|
||||
|
||||
@@ -19,99 +19,59 @@ import { DiffStatLabel, hasNonZeroStat } from "./DiffStatLabel";
|
||||
import { PierreEntryIcon } from "./PierreEntryIcon";
|
||||
import { Button } from "../ui/button";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import {
|
||||
changedFileName,
|
||||
selectChangedFilePreview,
|
||||
summarizeChangedFileScopes,
|
||||
} from "./changedFilesPresentation";
|
||||
|
||||
const EMPTY_DIRECTORY_OVERRIDES: Record<string, boolean> = {};
|
||||
|
||||
export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
turnId: TurnId;
|
||||
files: ReadonlyArray<TurnDiffFileChange>;
|
||||
expanded: boolean;
|
||||
showCompactPreview: boolean;
|
||||
allDirectoriesExpanded: boolean;
|
||||
resolvedTheme: "light" | "dark";
|
||||
onExpandedChange: (expanded: boolean) => void;
|
||||
onToggleAllDirectories: () => void;
|
||||
onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void;
|
||||
}) {
|
||||
const {
|
||||
turnId,
|
||||
files,
|
||||
expanded,
|
||||
showCompactPreview,
|
||||
allDirectoriesExpanded,
|
||||
resolvedTheme,
|
||||
onExpandedChange,
|
||||
onToggleAllDirectories,
|
||||
onOpenTurnDiff,
|
||||
} = props;
|
||||
const summaryStat = useMemo(() => summarizeTurnDiffStats(files), [files]);
|
||||
const scopeSummary = useMemo(() => summarizeChangedFileScopes(files), [files]);
|
||||
const previewFiles = useMemo(() => selectChangedFilePreview(files), [files]);
|
||||
const compactPreviewVisible = showCompactPreview && !expanded;
|
||||
const hasDirectories = files.some((file) => /[/\\]/.test(file.path));
|
||||
|
||||
return (
|
||||
<div
|
||||
className="@container/changed-files mt-4 rounded-2xl border border-border/70 bg-secondary p-2 dark:border-transparent dark:bg-input/32"
|
||||
data-changed-files-state={
|
||||
expanded ? "expanded" : compactPreviewVisible ? "preview" : "collapsed"
|
||||
}
|
||||
className="@container/changed-files mt-4 rounded-lg bg-secondary dark:bg-input/20"
|
||||
data-changed-files-state="tree"
|
||||
>
|
||||
<div
|
||||
data-changed-files-header=""
|
||||
className={cn(
|
||||
"flex items-center justify-between gap-2 rounded-xl",
|
||||
expanded &&
|
||||
"sticky top-2 z-10 mb-2 bg-secondary dark:bg-[color-mix(in_srgb,var(--contrast-foreground)_2.5%,var(--background))]",
|
||||
)}
|
||||
className="sticky top-2 z-10 flex items-center justify-between gap-2 rounded-t-lg bg-secondary px-3 py-2 dark:bg-[color-mix(in_srgb,var(--input)_20%,var(--background))]"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={expanded}
|
||||
data-scroll-anchor-ignore
|
||||
className="group flex min-w-0 flex-1 items-center rounded-xl px-2 py-1.5 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
onClick={() => onExpandedChange(!expanded)}
|
||||
>
|
||||
<span className="flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden">
|
||||
<ChevronRightIcon
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-3.5 shrink-0 text-muted-foreground transition-transform",
|
||||
expanded && "rotate-90",
|
||||
)}
|
||||
/>
|
||||
<span className="flex shrink-0 items-center gap-1 whitespace-nowrap font-medium text-foreground text-xs leading-4">
|
||||
<span>
|
||||
{files.length} changed file{files.length === 1 ? "" : "s"}
|
||||
</span>
|
||||
{hasNonZeroStat(summaryStat) && (
|
||||
<DiffStatLabel
|
||||
additions={summaryStat.additions}
|
||||
className="text-xs leading-4"
|
||||
deletions={summaryStat.deletions}
|
||||
layout="inline"
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
<span className="ml-1 hidden min-w-0 flex-1 truncate text-[11px] text-muted-foreground group-hover:text-foreground/80 @[24rem]/changed-files:inline">
|
||||
{expanded ? "Hide files" : "Show files"}
|
||||
</span>
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs font-medium text-foreground">
|
||||
<span>
|
||||
{files.length} changed file{files.length === 1 ? "" : "s"}
|
||||
</span>
|
||||
</button>
|
||||
<div className="flex shrink-0 items-center gap-1.5 pr-1">
|
||||
{expanded ? (
|
||||
{hasNonZeroStat(summaryStat) && (
|
||||
<DiffStatLabel
|
||||
additions={summaryStat.additions}
|
||||
deletions={summaryStat.deletions}
|
||||
layout="inline"
|
||||
className="text-xs leading-4"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
{hasDirectories && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Button
|
||||
type="button"
|
||||
size="icon-xs"
|
||||
variant="outline"
|
||||
className="!size-[22px]"
|
||||
variant="ghost-muted"
|
||||
aria-label={
|
||||
allDirectoriesExpanded ? "Collapse all folders" : "Expand all folders"
|
||||
}
|
||||
@@ -130,14 +90,14 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
{allDirectoriesExpanded ? "Collapse all folders" : "Expand all folders"}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
)}
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Button
|
||||
type="button"
|
||||
size="xs"
|
||||
variant="outline"
|
||||
variant="ghost-muted"
|
||||
aria-label="Open diff"
|
||||
onClick={() => onOpenTurnDiff(turnId, files[0]?.path)}
|
||||
/>
|
||||
@@ -150,61 +110,14 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
{expanded ? (
|
||||
<ChangedFilesTree
|
||||
key={`changed-files-tree:${turnId}`}
|
||||
turnId={turnId}
|
||||
files={files}
|
||||
allDirectoriesExpanded={allDirectoriesExpanded}
|
||||
resolvedTheme={resolvedTheme}
|
||||
onOpenTurnDiff={onOpenTurnDiff}
|
||||
/>
|
||||
) : compactPreviewVisible ? (
|
||||
<div className="px-2 pb-1.5 pt-1">
|
||||
<p className="flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] text-muted-foreground">
|
||||
{scopeSummary.map((scope, index) => (
|
||||
<span key={scope.label} className="inline-flex items-center gap-1">
|
||||
{index > 0 ? <span aria-hidden="true">·</span> : null}
|
||||
<span className="font-mono text-foreground/75">{scope.label}</span>
|
||||
<span>
|
||||
{scope.fileCount} file{scope.fileCount === 1 ? "" : "s"}
|
||||
</span>
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
<div className="mt-2 flex flex-wrap items-center gap-1.5">
|
||||
{previewFiles.map((file) => (
|
||||
<Tooltip key={file.path}>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex max-w-48 items-center gap-1 rounded-md border border-border/70 bg-background/45 px-1.5 py-1 font-mono text-[10px] text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
onClick={() => onOpenTurnDiff(turnId, file.path)}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<PierreEntryIcon
|
||||
pathValue={file.path}
|
||||
kind="file"
|
||||
theme={resolvedTheme}
|
||||
className="size-3 shrink-0 text-muted-foreground/70"
|
||||
/>
|
||||
<span className="truncate">{changedFileName(file.path)}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">{file.path}</TooltipPopup>
|
||||
</Tooltip>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-md px-1.5 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
onClick={() => onExpandedChange(true)}
|
||||
>
|
||||
Show all {files.length} files
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
<ChangedFilesTree
|
||||
key={`${turnId}:${allDirectoriesExpanded}`}
|
||||
turnId={turnId}
|
||||
files={files}
|
||||
allDirectoriesExpanded={allDirectoriesExpanded}
|
||||
resolvedTheme={resolvedTheme}
|
||||
onOpenTurnDiff={onOpenTurnDiff}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -261,7 +174,8 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
<button
|
||||
type="button"
|
||||
data-scroll-anchor-ignore
|
||||
className="group flex w-full items-center gap-1.5 rounded-xl py-1 pr-3 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background"
|
||||
aria-expanded={isExpanded}
|
||||
className="group flex w-full items-center gap-2 rounded-md py-1.5 pr-2 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background"
|
||||
style={{ paddingLeft: `${leftPadding}px` }}
|
||||
onClick={() => toggleDirectory(node.path)}
|
||||
>
|
||||
@@ -287,9 +201,7 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
)}
|
||||
</button>
|
||||
{isExpanded && (
|
||||
<div className="space-y-0.5">
|
||||
{node.children.map((childNode) => renderTreeNode(childNode, depth + 1))}
|
||||
</div>
|
||||
<div>{node.children.map((childNode) => renderTreeNode(childNode, depth + 1))}</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -299,7 +211,7 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
<button
|
||||
key={`file:${node.path}`}
|
||||
type="button"
|
||||
className="group flex w-full items-center gap-1.5 rounded-xl py-1 pr-3 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background"
|
||||
className="group flex w-full items-center gap-2 rounded-md py-1.5 pr-2 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background"
|
||||
style={{ paddingLeft: `${leftPadding}px` }}
|
||||
onClick={() => onOpenTurnDiff(turnId, node.path)}
|
||||
>
|
||||
@@ -312,7 +224,7 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
theme={resolvedTheme}
|
||||
className="size-3.5 text-muted-foreground/70"
|
||||
/>
|
||||
<span className="truncate font-mono text-[11px] text-muted-foreground/80 group-hover:text-foreground/90">
|
||||
<span className="truncate font-mono text-xs text-foreground/85 group-hover:text-foreground">
|
||||
{node.name}
|
||||
</span>
|
||||
{node.stat && (
|
||||
@@ -324,7 +236,7 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
);
|
||||
};
|
||||
|
||||
return <div className="space-y-0.5">{treeNodes.map((node) => renderTreeNode(node, 0))}</div>;
|
||||
return <div className="p-2">{treeNodes.map((node) => renderTreeNode(node, 0))}</div>;
|
||||
});
|
||||
|
||||
function collectDirectoryPaths(nodes: ReadonlyArray<TurnDiffTreeNode>): string[] {
|
||||
|
||||
@@ -379,9 +379,8 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).toContain("sticky top-2 z-10");
|
||||
expect(markup).not.toContain("self-start");
|
||||
expect(markup).toContain("whitespace-nowrap");
|
||||
expect(markup).toContain("!size-[22px]");
|
||||
expect(markup).toContain("size-3");
|
||||
expect(markup).toContain('aria-label="Collapse all folders"');
|
||||
expect(markup).not.toContain('aria-label="Collapse all folders"');
|
||||
expect(markup).toContain('aria-label="Open diff"');
|
||||
expect(markup).toContain("1 changed file");
|
||||
});
|
||||
|
||||
@@ -111,7 +111,6 @@ import {
|
||||
} from "./ExpandedImagePreview";
|
||||
import { ProposedPlanCard } from "./ProposedPlanCard";
|
||||
import { ChangedFilesCard } from "./ChangedFilesTree";
|
||||
import { shouldAutoExpandChangedFiles } from "./changedFilesPresentation";
|
||||
import { CHAT_TIMELINE_ANCHOR_OFFSET } from "./timelineScrollAnchoring";
|
||||
import { MessageCopyButton } from "./MessageCopyButton";
|
||||
import { PierreEntryIcon } from "./PierreEntryIcon";
|
||||
@@ -2117,30 +2116,21 @@ function AssistantChangedFilesSectionInner({
|
||||
resolvedTheme: "light" | "dark";
|
||||
onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void;
|
||||
}) {
|
||||
const activity = use(TimelineRowActivityCtx);
|
||||
const isLatestTurn = activity.latestTurnId === turnSummary.turnId;
|
||||
const persistedExpanded = useUiStateStore(
|
||||
(store) => store.threadChangedFilesExpandedById[routeThreadKey]?.[turnSummary.turnId],
|
||||
);
|
||||
const setExpanded = useUiStateStore((store) => store.setThreadChangedFilesExpanded);
|
||||
const [autoExpanded] = useState(() =>
|
||||
shouldAutoExpandChangedFiles(checkpointFiles, isLatestTurn),
|
||||
);
|
||||
const [allDirectoriesExpanded, setAllDirectoriesExpanded] = useState(autoExpanded);
|
||||
const expanded = persistedExpanded ?? (isLatestTurn && autoExpanded);
|
||||
const allDirectoriesExpanded = persistedExpanded ?? false;
|
||||
|
||||
return (
|
||||
<ChangedFilesCard
|
||||
turnId={turnSummary.turnId}
|
||||
files={checkpointFiles}
|
||||
expanded={expanded}
|
||||
showCompactPreview={isLatestTurn}
|
||||
allDirectoriesExpanded={allDirectoriesExpanded}
|
||||
resolvedTheme={resolvedTheme}
|
||||
onExpandedChange={(nextExpanded) =>
|
||||
setExpanded(routeThreadKey, turnSummary.turnId, nextExpanded)
|
||||
onToggleAllDirectories={() =>
|
||||
setExpanded(routeThreadKey, turnSummary.turnId, !allDirectoriesExpanded)
|
||||
}
|
||||
onToggleAllDirectories={() => setAllDirectoriesExpanded((current) => !current)}
|
||||
onOpenTurnDiff={onOpenTurnDiff}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -159,7 +159,7 @@ describe("parsePersistedState", () => {
|
||||
invalid: "not-a-date",
|
||||
},
|
||||
defaultAdvertisedEndpointKey: "desktop-core:lan:http",
|
||||
threadChangedFilesExpansionVersion: 1,
|
||||
threadChangedFilesExpansionVersion: 2,
|
||||
threadChangedFilesExpandedById: {
|
||||
"environment:thread-1": {
|
||||
"turn-1": false,
|
||||
@@ -186,8 +186,9 @@ describe("parsePersistedState", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores changed-file expansion values saved with legacy folder semantics", () => {
|
||||
it.each([undefined, 1])("ignores changed-file expansion version %s", (version) => {
|
||||
const parsed = parsePersistedState({
|
||||
...(version === undefined ? {} : { threadChangedFilesExpansionVersion: version }),
|
||||
threadChangedFilesExpandedById: {
|
||||
"environment:thread-1": {
|
||||
"turn-1": false,
|
||||
@@ -296,7 +297,7 @@ describe("uiStateStore persistence", () => {
|
||||
"environment:thread-1": "2026-02-25T12:35:00.000Z",
|
||||
},
|
||||
defaultAdvertisedEndpointKey: "desktop-core:lan:http",
|
||||
threadChangedFilesExpansionVersion: 1,
|
||||
threadChangedFilesExpansionVersion: 2,
|
||||
threadChangedFilesExpandedById: {
|
||||
"environment:thread-1": {
|
||||
"turn-1": false,
|
||||
|
||||
@@ -3,7 +3,8 @@ import { create } from "zustand";
|
||||
import { normalizeProjectPathForComparison } from "./lib/projectPaths";
|
||||
|
||||
export const PERSISTED_STATE_KEY = "t3code:ui-state:v1";
|
||||
const THREAD_CHANGED_FILES_EXPANSION_VERSION = 1;
|
||||
// Version 1 stored card visibility, not folder expansion.
|
||||
const THREAD_CHANGED_FILES_EXPANSION_VERSION = 2;
|
||||
const LEGACY_PERSISTED_STATE_KEYS = [
|
||||
"t3code:renderer-state:v8",
|
||||
"t3code:renderer-state:v7",
|
||||
@@ -25,7 +26,7 @@ export interface PersistedUiState {
|
||||
expandedProjectCwds?: string[];
|
||||
projectOrderCwds?: string[];
|
||||
defaultAdvertisedEndpointKey?: string | null;
|
||||
threadChangedFilesExpansionVersion?: typeof THREAD_CHANGED_FILES_EXPANSION_VERSION;
|
||||
threadChangedFilesExpansionVersion?: number;
|
||||
threadChangedFilesExpandedById?: Record<string, Record<string, boolean>>;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user