From 4c2c4396b062feaccf909604fe88e689b02cf71a Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Tue, 8 Sep 2026 16:00:54 +0800 Subject: [PATCH] fix(webui): use styled tooltips for model presets and activity previews (#5701) * fix(webui): show effective preset in styled model tooltip * fix(webui): use shared tooltip for activity previews --- .../components/thread/ModelPresetBadge.tsx | 206 +++++++++--------- .../thread/activity/ActivityStep.tsx | 46 ++-- webui/src/tests/model-preset-badge.test.tsx | 60 +++++ webui/src/tests/reasoning-row.test.tsx | 22 ++ webui/src/tests/thread-shell.test.tsx | 27 ++- 5 files changed, 236 insertions(+), 125 deletions(-) create mode 100644 webui/src/tests/model-preset-badge.test.tsx create mode 100644 webui/src/tests/reasoning-row.test.tsx diff --git a/webui/src/components/thread/ModelPresetBadge.tsx b/webui/src/components/thread/ModelPresetBadge.tsx index 51c2492ae..bf3fa01d0 100644 --- a/webui/src/components/thread/ModelPresetBadge.tsx +++ b/webui/src/components/thread/ModelPresetBadge.tsx @@ -14,6 +14,7 @@ import { floatingItemFocusClassName, } from "@/components/ui/floating-surface"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { useLogoFallback } from "@/hooks/useLogoFallback"; import { inferProviderFromModelName, providerBrand } from "@/lib/provider-brand"; import { cn } from "@/lib/utils"; @@ -114,6 +115,7 @@ export function ModelPresetBadge({ }: ModelPresetBadgeProps) { const { t } = useTranslation(); const [open, setOpen] = useState(false); + const [tooltipOpen, setTooltipOpen] = useState(false); const [motion, setMotion] = useState(null); const [motionWidth, setMotionWidth] = useState(null); const gestureRef = useRef(null); @@ -135,11 +137,14 @@ export function ModelPresetBadge({ const displayLabel = fallbackDisplayLabel || label; const displayModelDetail = fallbackPreset ? fallbackPreset.model - : fallbackModelName - ? null - : modelDetail; + : fallbackModelName || modelDetail; const displayProvider = fallbackPreset?.provider || (fallbackModelName ? inferProviderFromModelName(fallbackModelName) : provider); + const tooltipLabel = [...new Set([ + displayLabel, + displayModelDetail, + fallbackModelName ? null : providerLabel, + ].filter(Boolean))].join(" · "); const presets = !activeName ? modelPresets : listedIndex < 0 @@ -278,20 +283,19 @@ export function ModelPresetBadge({ label={displayLabel} modelDetail={displayModelDetail} provider={displayProvider} - providerLabel={fallbackModelName ? null : providerLabel} needsSetup={needsSetup} needsAttention={needsSetup && attentionRequest > 0} fallbackModelName={fallbackModelName} - fallbackFromLabel={fallbackModelName ? label : null} isHero={isHero} /> ); - if (!canSwitch) { - const Container = opensSetup ? "button" : "span"; - return ( + const Container = opensSetup ? "button" : "span"; + const badge = !canSwitch ? ( + {pill} - ); - } - - return ( + + ) : ( { @@ -314,86 +316,88 @@ export function ModelPresetBadge({ }} > - + + { + if (motion.settling && event.currentTarget === event.target) clearMotion(); + }} + style={{ + paddingTop: isHero ? "10px" : "12px", + transform: `translate3d(0, ${-pillStride * (2 + motion.remainder)}px, 0)`, + }} + > + {PILL_OFFSETS.map((offset) => { + const preset = presets[wrapIndex(motion.index + offset, presets.length)]; + return ( + + ); + })} + + + + ) : pill} + + ); + + return ( + + + {badge} + {tooltipLabel} + + + ); } function PresetOption({ @@ -495,11 +508,9 @@ function PresetPill({ label, modelDetail, provider, - providerLabel, needsSetup = false, needsAttention = false, fallbackModelName, - fallbackFromLabel, isHero, offset, scale, @@ -507,11 +518,9 @@ function PresetPill({ label: string; modelDetail?: string | null; provider?: string | null; - providerLabel?: string | null; needsSetup?: boolean; needsAttention?: boolean; fallbackModelName?: string | null; - fallbackFromLabel?: string | null; isHero: boolean; offset?: number; scale?: number; @@ -521,10 +530,6 @@ function PresetPill({ const inferredProvider = needsSetup ? null : provider || inferProviderFromModelName(modelDetail || label); - const title = [...new Set([label, modelDetail, providerLabel].filter(Boolean))].join(" · "); - const fallbackTitle = fallbackModelName - ? `${fallbackFromLabel || label} · using ${fallbackModelName}` - : title; useLayoutEffect(() => { const node = labelRef.current; @@ -541,7 +546,6 @@ function PresetPill({ data-fallback={fallbackModelName ? "true" : undefined} data-needs-setup={needsSetup ? "true" : undefined} data-preset-offset={offset} - title={fallbackTitle || undefined} className={cn( "composer-model-badge composer-model-pill inline-flex h-full max-w-full min-w-0 shrink-0 items-center rounded-full border border-border/55 bg-card font-medium text-foreground/70", "w-fit", diff --git a/webui/src/components/thread/activity/ActivityStep.tsx b/webui/src/components/thread/activity/ActivityStep.tsx index 4031fbf16..92b02b56f 100644 --- a/webui/src/components/thread/activity/ActivityStep.tsx +++ b/webui/src/components/thread/activity/ActivityStep.tsx @@ -2,6 +2,7 @@ import type { CSSProperties, ReactNode } from "react"; import type { LucideIcon } from "lucide-react"; import { StreamingLabelSheen } from "@/components/MessageBubble"; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; export type ActivityStepTone = "neutral" | "active" | "success" | "error"; @@ -33,6 +34,25 @@ export function ActivityStep({ markerClassName, style, }: ActivityStepProps) { + const line = ( +
+ + {label} + +
+ ); + return (
-
- - {label} - -
+ {typeof label === "string" ? ( + + + {line} + + {label} + + + + ) : line}
); diff --git a/webui/src/tests/model-preset-badge.test.tsx b/webui/src/tests/model-preset-badge.test.tsx new file mode 100644 index 000000000..1c82976ba --- /dev/null +++ b/webui/src/tests/model-preset-badge.test.tsx @@ -0,0 +1,60 @@ +import { fireEvent, render, screen, waitFor } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { describe, expect, it, vi } from "vitest"; + +import { ModelPresetBadge } from "@/components/thread/ModelPresetBadge"; + +const presets = [ + { name: "zhipu", model: "glm-5", provider: "zhipu" }, + { name: "codex", model: "openai-codex/gpt-5.5", provider: "openai_codex" }, +]; + +describe("ModelPresetBadge fallback tooltip", () => { + it("shows only the effective preset on hover and preserves the preset picker", async () => { + const user = userEvent.setup(); + const onPresetChange = vi.fn(); + const { container } = render( + , + ); + + const trigger = screen.getByRole("button", { name: "codex" }); + expect(container.querySelector("[title]")).toBeNull(); + await user.hover(trigger); + const tooltip = await screen.findByRole("tooltip"); + expect(tooltip).toHaveTextContent("codex · openai-codex/gpt-5.5"); + expect(tooltip).not.toHaveTextContent("zhipu"); + await user.click(trigger); + expect(await screen.findByRole("listbox")).toBeInTheDocument(); + await waitFor(() => expect(screen.queryByRole("tooltip")).not.toBeInTheDocument()); + await user.click(screen.getByRole("option", { name: "codex" })); + expect(onPresetChange).toHaveBeenCalledWith("codex"); + }); + + it("exposes the current preset to keyboard focus without a picker", async () => { + render( + , + ); + const trigger = screen.getByLabelText("codex"); + expect(trigger).toHaveAttribute("tabindex", "0"); + fireEvent.focus(trigger); + expect(await screen.findByRole("tooltip")).toHaveTextContent( + "codex · openai-codex/gpt-5.5", + ); + fireEvent.keyDown(trigger, { key: "Escape" }); + await waitFor(() => expect(screen.queryByRole("tooltip")).not.toBeInTheDocument()); + }); +}); diff --git a/webui/src/tests/reasoning-row.test.tsx b/webui/src/tests/reasoning-row.test.tsx new file mode 100644 index 000000000..ea8d2e52e --- /dev/null +++ b/webui/src/tests/reasoning-row.test.tsx @@ -0,0 +1,22 @@ +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { expect, it } from "vitest"; + +import { ReasoningRow } from "@/components/thread/activity/ReasoningRow"; + +it("shows the reasoning preview in the shared tooltip on hover and keyboard focus", async () => { + const user = userEvent.setup(); + const text = 'The user is saying "hi" again. I should respond in Chinese, concisely and in a friendly manner.'; + const { container } = render(); + const line = screen.getByTestId("activity-line"); + + expect(container.querySelector("[title]")).toBeNull(); + await user.hover(line); + expect(await screen.findByRole("tooltip")).toHaveTextContent(text); + await user.unhover(line); + await user.tab(); + expect(line).toHaveFocus(); + expect(await screen.findByRole("tooltip")).toHaveTextContent(text); + await user.keyboard("{Escape}"); + expect(screen.queryByRole("tooltip")).not.toBeInTheDocument(); +}); diff --git a/webui/src/tests/thread-shell.test.tsx b/webui/src/tests/thread-shell.test.tsx index 1c32d4d50..9dfcd0938 100644 --- a/webui/src/tests/thread-shell.test.tsx +++ b/webui/src/tests/thread-shell.test.tsx @@ -784,8 +784,10 @@ describe("ThreadShell", () => { ), ); - expect(await screen.findByTitle("fast · gpt-5.5 · OpenAI Codex")).toBeInTheDocument(); - expect(screen.queryByTitle("Default · deepseek-v4-pro · DeepSeek")).not.toBeInTheDocument(); + fireEvent.focus(await screen.findByLabelText("fast")); + expect(await screen.findByRole("tooltip")).toHaveTextContent("fast · gpt-5.5 · OpenAI Codex"); + fireEvent.blur(screen.getByLabelText("fast")); + expect(screen.queryByLabelText("Default")).not.toBeInTheDocument(); }); it("falls back to the current preset while a renamed session reference is stale", async () => { @@ -809,7 +811,9 @@ describe("ThreadShell", () => { ), ); - expect(await screen.findByTitle("fast · gpt-5.5 · OpenAI Codex")).toBeInTheDocument(); + fireEvent.focus(await screen.findByLabelText("fast")); + expect(await screen.findByRole("tooltip")).toHaveTextContent("fast · gpt-5.5 · OpenAI Codex"); + fireEvent.blur(screen.getByLabelText("fast")); expect(screen.queryByRole("button", { name: "Choose your AI" })).not.toBeInTheDocument(); }); @@ -891,7 +895,9 @@ describe("ThreadShell", () => { ), ); - expect(await screen.findByTitle("fast · gpt-4 · Company Proxy")).toBeInTheDocument(); + fireEvent.focus(await screen.findByLabelText("fast")); + expect(await screen.findByRole("tooltip")).toHaveTextContent("fast · gpt-4 · Company Proxy"); + fireEvent.blur(screen.getByLabelText("fast")); expect(screen.queryByRole("button", { name: "Choose your AI" })).not.toBeInTheDocument(); }); @@ -943,10 +949,13 @@ describe("ThreadShell", () => { expect(screen.queryByText("Default")).not.toBeInTheDocument(); expect(screen.getByText("deepseek-chat")).toBeInTheDocument(); expect(badge).toHaveAttribute("data-fallback", "true"); - expect(badge).toHaveAttribute( - "title", - "Default · using deepseek/deepseek-chat", + expect(badge).not.toHaveAttribute("title"); + fireEvent.focus(screen.getByLabelText("deepseek-chat")); + expect(await screen.findByRole("tooltip")).toHaveTextContent( + "deepseek-chat · deepseek/deepseek-chat", ); + expect(screen.getByRole("tooltip")).not.toHaveTextContent("Default"); + fireEvent.blur(screen.getByLabelText("deepseek-chat")); expect(logo).toBeInTheDocument(); act(() => { @@ -1328,7 +1337,9 @@ describe("ThreadShell", () => { await act(async () => { rerender(view(session("chat-new", "fast"))); }); - expect(screen.getByTitle("fast · gpt-5.5 · OpenAI Codex")).toBeInTheDocument(); + fireEvent.focus(await screen.findByLabelText("fast")); + expect(await screen.findByRole("tooltip")).toHaveTextContent("fast · gpt-5.5 · OpenAI Codex"); + fireEvent.blur(screen.getByLabelText("fast")); expect(screen.queryByText("Default")).not.toBeInTheDocument(); expect(client.sendMessage).not.toHaveBeenCalled();