fix(webui): use file-type icons in file change activity

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-17 23:27:00 +08:00
1 parent d076e4ef13
commit 8de03ac0a2
8 files changed
+132 -68

No files matched your search

+7 -1
View File
@@ -31,6 +31,7 @@ interface FileReferenceChipProps {
path: string;
tooltipPath?: string;
display?: "name" | "path";
showIcon?: boolean;
active?: boolean;
className?: string;
textClassName?: string;
@@ -43,6 +44,7 @@ export function FileReferenceChip({
path,
tooltipPath,
display = "name",
showIcon = true,
active = false,
className,
textClassName,
@@ -97,7 +99,7 @@ export function FileReferenceChip({
],
)}
>
<FileReferenceIcon kind={kind} className="translate-y-[0.12em]" />
{showIcon ? <FileReferenceIcon kind={kind} className="translate-y-[0.12em]" /> : null}
<span
data-sheen-text={active ? displayText : undefined}
className={cn(
@@ -258,6 +260,10 @@ const FILE_ICONS = {
video: FileVideo2,
} satisfies Record<FileReferenceKind, LucideIcon>;
export function fileIconForPath(path: string): LucideIcon {
return FILE_ICONS[fileKindForPath(path)];
}
/** The same file silhouette and stroke in replies, tabs, and attachment tiles. */
export function FileReferenceIcon({ kind, className }: { kind: FileReferenceKind; className?: string }) {
const Icon = FILE_ICONS[kind];
@@ -3,7 +3,7 @@ import type { LucideIcon } from "lucide-react";
import { StreamingLabelSheen } from "@/components/ui/streaming-label-sheen";
import { formControlFocusClassName } from "@/components/ui/form-control";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { HoverHint, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
export type ActivityStepTone = "neutral" | "active" | "success" | "error";
@@ -11,6 +11,7 @@ export type ActivityStepTone = "neutral" | "active" | "success" | "error";
export interface ActivityStepProps {
icon?: LucideIcon;
marker?: ReactNode;
markerLabel?: string;
showMarker?: boolean;
label: ReactNode;
detail?: string;
@@ -30,6 +31,7 @@ export interface ActivityStepProps {
export function ActivityStep({
icon: Icon,
marker,
markerLabel,
showMarker = true,
label,
detail,
@@ -48,6 +50,30 @@ export function ActivityStep({
const lineRef = useRef<HTMLDivElement>(null);
const [hintOpen, setHintOpen] = useState(false);
const textLabel = typeof label === "string" ? [label, detail].filter(Boolean).join("\n") : undefined;
const activityMarker = (
<span
className={cn(
"flex h-5 w-[1.125rem] shrink-0 items-start justify-center pt-[3px]",
markerLabel && ["rounded-sm", formControlFocusClassName],
)}
aria-hidden={markerLabel ? undefined : true}
role={markerLabel ? "img" : undefined}
aria-label={markerLabel}
tabIndex={markerLabel ? 0 : undefined}
>
{marker ?? (
<span
className={cn(
"grid h-3.5 w-3.5 place-items-center transition-colors",
tone === "error" ? "text-destructive/[0.78]" : "text-muted-foreground",
markerClassName,
)}
>
{Icon ? <Icon className="h-3.5 w-3.5" strokeWidth={1.75} aria-hidden /> : null}
</span>
)}
</span>
);
const line = (
<div
ref={lineRef}
@@ -92,26 +118,9 @@ export function ActivityStep({
)}
style={style}
>
{showMarker ? (
<span
className={cn(
"flex h-5 w-[1.125rem] shrink-0 items-start justify-center pt-[3px]",
)}
aria-hidden
>
{marker ?? (
<span
className={cn(
"grid h-3.5 w-3.5 place-items-center transition-colors",
tone === "error" ? "text-destructive/[0.78]" : "text-muted-foreground",
markerClassName,
)}
>
{Icon ? <Icon className="h-3.5 w-3.5" strokeWidth={1.75} /> : null}
</span>
)}
</span>
) : null}
{showMarker ? markerLabel ? (
<HoverHint content={markerLabel}>{activityMarker}</HoverHint>
) : activityMarker : null}
<div className={cn("min-w-0", contentClassName)}>
{typeof label === "string" ? (
<TooltipProvider>
@@ -6,9 +6,9 @@ import {
ChevronUp,
ExternalLink,
} from "lucide-react";
import { Trans, useTranslation } from "react-i18next";
import { useTranslation } from "react-i18next";
import { FileReferenceChip } from "@/components/FileReferenceChip";
import { FileReferenceChip, fileIconForPath } from "@/components/FileReferenceChip";
import { codeLanguageFromPath } from "@/lib/code-language";
import {
hasRenderableFileDiff,
@@ -98,7 +98,8 @@ function FileEditRow({
return (
<div className="min-w-0">
<ActivityStep
showMarker={false}
icon={fileIconForPath(edit.absolute_path || edit.path)}
markerLabel={action}
active={editing}
tone={failed ? "error" : editing ? "active" : "success"}
className="text-xs"
@@ -107,24 +108,16 @@ function FileEditRow({
? t("message.fileEditPreparing", { defaultValue: "Preparing file edit…" })
: (
<span className="flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap">
<Trans
i18nKey="message.agentActivity.actionTargetRich"
values={{ action }}
components={{
action: <span className={cn("shrink-0", failed && "text-destructive/80")} />,
target: (
<FileReferenceChip
path={edit.path}
previewPath={edit.absolute_path || edit.path}
onOpen={onOpenFilePreview}
display="path"
active={editing}
className="min-w-0"
textClassName="truncate text-[12px]"
testId="activity-file-reference"
/>
),
}}
<FileReferenceChip
path={edit.path}
previewPath={edit.absolute_path || edit.path}
onOpen={onOpenFilePreview}
display="path"
showIcon={false}
active={editing}
className="min-w-0"
textClassName="truncate text-[12px]"
testId="activity-file-reference"
/>
{hasCountedDiff ? <DiffPair added={edit.added} deleted={edit.deleted} /> : null}
</span>