🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(topics): show topic title and description tooltips only when clipped (#19191)
Nimar0c531beae65c
diff --git a/web/src/features/topics/TopicTraceList.tsx b/web/src/features/topics/TopicTraceList.tsxindex 9eb33850b7..08d8cf7d96 100644--- a/web/src/features/topics/TopicTraceList.tsx+++ b/web/src/features/topics/TopicTraceList.tsx@@ -1,5 +1,10 @@/* eslint-disable react/no-unstable-nested-components */-import { type RefObject, type UIEvent, useState } from "react";+import {+ type PointerEvent,+ type RefObject,+ type UIEvent,+ useState,+} from "react";import { ExternalLink } from "@langfuse/icons";import { DataTable } from "@/src/components/table/data-table";import { type LangfuseColumnDef } from "@/src/components/table/types";@@ -16,6 +21,33 @@ const ROW_CHUNK = 100;const LOAD_MORE_THRESHOLD_PX = 400;const FIRST_CELL = "block pr-3 pl-2";+/**+ * `truncate` compares unrounded widths: whole-pixel `scrollWidth` misses+ * sub-pixel overflows that still get an ellipsis, and tight leading overflows+ * the height of text that fits. Assumes no horizontal padding.+ */+function clipsText(element: HTMLElement, clip: "truncate" | "line-clamp") {+ if (clip === "line-clamp") return element.scrollHeight > element.clientHeight;+ const text = document.createRange();+ text.selectNodeContents(element);+ return (+ text.getBoundingClientRect().width > element.getBoundingClientRect().width+ );+}++/**+ * Native tooltip with the full text, only while the element clips it. The list+ * can stay mounted across topics, so a measurement only counts for its text.+ */+function useTruncatedTitle(text: string, clip: "truncate" | "line-clamp") {+ const [clippedText, setClippedText] = useState<string | null>(null);+ return {+ title: clippedText === text ? text : undefined,+ onPointerMove: (event: PointerEvent<HTMLElement>) =>+ setClippedText(clipsText(event.currentTarget, clip) ? text : null),+ };+}+export function TopicTraceList({projectId,title,@@ -38,6 +70,8 @@ export function TopicTraceList({if (nearBottom && visibleCount < rows.length)setShown({ rows, count: visibleCount + ROW_CHUNK });};+ const titleTooltip = useTruncatedTitle(title, "truncate");+ const descriptionTooltip = useTruncatedTitle(description ?? "", "line-clamp");const { isV4 } = useReadPath();const tracingHref = topicTracesHref(projectId, rows, isV4);const columns: LangfuseColumnDef<FacetRow>[] = [@@ -113,13 +147,18 @@ export function TopicTraceList({/>)}</div>- <h3 className="truncate text-lg font-bold" title={title}>+ <h3+ className="truncate text-lg font-bold"+ title={titleTooltip.title}+ onPointerMove={titleTooltip.onPointerMove}+ >{title}</h3>{description && (<pclassName="text-muted-foreground line-clamp-2 text-sm"- title={description}+ title={descriptionTooltip.title}+ onPointerMove={descriptionTooltip.onPointerMove}>{description}</p>diff --git a/web/src/features/topics/TopicTreemapView.stories.tsx b/web/src/features/topics/TopicTreemapView.stories.tsxindex fe403a156b..a12fc02dce 100644--- a/web/src/features/topics/TopicTreemapView.stories.tsx+++ b/web/src/features/topics/TopicTreemapView.stories.tsx@@ -1,5 +1,5 @@import { type ComponentProps } from "react";-import { expect, fn, userEvent, within } from "storybook/test";+import { expect, fn, userEvent, waitFor, within } from "storybook/test";import preview from "../../../.storybook/preview";import { TopicTreemapView } from "./TopicTreemapView";@@ -21,12 +21,14 @@ const names = ["Langfuse trace export","Recommendation requests",];+const LONG_DESCRIPTION =+ "Users asked the in-app assistant how to instrument their application, read traces and observations, configure evaluations and datasets, and interpret dashboard metrics. Many follow-ups asked for step-by-step guidance tailored to a specific SDK, framework, or self-hosted deployment, and several conversations combined product questions with troubleshooting of missing or delayed traces.";const topics = names.map((name, index) => ({id: `topic-${index}`,versionId: `topic-${index}-v1`,runId: "run",name,- description: "",+ description: index === 0 ? LONG_DESCRIPTION : "",count: counts[index],}));const assignedRows = topics.flatMap((topic) =>@@ -276,3 +278,27 @@ export const SelectTopic = meta.story({).toBeVisible();},});++export const DescriptionTooltipWhenClipped = meta.story({+ name: "(Test) Hover shows the full text only when clipped",+ render: (args) => (+ <div className="flex flex-col" style={{ width: 720, height: 900 }}>+ <TopicTreemapView {...args} />+ </div>+ ),+ play: async ({ canvasElement }) => {+ const list = within(+ within(canvasElement).getByRole("region", { name: "Topic traces" }),+ );+ const title = list.getByRole("heading", {+ name: "Langfuse user assistance",+ });+ const description = list.getByText(LONG_DESCRIPTION);+ await userEvent.hover(title);+ await userEvent.hover(description);+ await waitFor(() =>+ expect(description).toHaveAttribute("title", LONG_DESCRIPTION),+ );+ await expect(title).not.toHaveAttribute("title");+ },+});