Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(topics): clean up trace list labels (#18648)

Nimar64ba74f971cb
diff --git a/web/src/components/design-system/Badge/Badge.stories.tsx b/web/src/components/design-system/Badge/Badge.stories.tsx
index 8678b781d6..19167f0aa1 100644
--- a/web/src/components/design-system/Badge/Badge.stories.tsx
+++ b/web/src/components/design-system/Badge/Badge.stories.tsx
@@ -25,6 +25,16 @@ const allColors = Object.keys({
green: true,
ghost: true,
filled: true,
+ violetTint: true,
+ skyTint: true,
+ emeraldTint: true,
+ amberTint: true,
+ pinkTint: true,
+ indigoTint: true,
+ tealTint: true,
+ orangeTint: true,
+ limeTint: true,
+ fuchsiaTint: true,
} satisfies Record<Color, true>) as Color[];
export const Default = meta.story({});
@@ -88,3 +98,32 @@ export const VariantMatrix = meta.story({
</div>
),
});
+
+export const LongWrappedLabel = meta.story({
+ name: "(Test) Long Wrapped Label",
+ args: {
+ text: "Quality dashboard widgets and score distribution",
+ shouldWrap: true,
+ },
+ render: (args) => (
+ <div className="w-36">
+ <Badge {...args} />
+ </div>
+ ),
+ play: async ({ canvas, args }) => {
+ const label = canvas.getByText(args.text);
+ const badge = label.parentElement!;
+ const range = document.createRange();
+ range.selectNodeContents(label);
+ const lines = Array.from(range.getClientRects());
+ await expect(lines.length).toBeGreaterThan(1);
+ for (const line of lines) {
+ await expect(line.right).toBeLessThanOrEqual(
+ badge.getBoundingClientRect().right,
+ );
+ await expect(line.bottom).toBeLessThanOrEqual(
+ badge.getBoundingClientRect().bottom,
+ );
+ }
+ },
+});
diff --git a/web/src/components/design-system/Badge/Badge.tsx b/web/src/components/design-system/Badge/Badge.tsx
index 48c01e42e2..e566e8ccf0 100644
--- a/web/src/components/design-system/Badge/Badge.tsx
+++ b/web/src/components/design-system/Badge/Badge.tsx
@@ -25,6 +25,26 @@ const badgeVariants = cva(
green: "border-transparent bg-light-green text-dark-green",
ghost: "border-0 bg-transparent px-0 text-foreground-secondary",
filled: "border-transparent bg-muted text-foreground-secondary",
+ violetTint:
+ "border-category-violet/40 bg-category-violet/10 text-foreground-secondary",
+ skyTint:
+ "border-category-sky/40 bg-category-sky/10 text-foreground-secondary",
+ emeraldTint:
+ "border-category-emerald/40 bg-category-emerald/10 text-foreground-secondary",
+ amberTint:
+ "border-category-amber/40 bg-category-amber/10 text-foreground-secondary",
+ pinkTint:
+ "border-category-pink/40 bg-category-pink/10 text-foreground-secondary",
+ indigoTint:
+ "border-category-indigo/40 bg-category-indigo/10 text-foreground-secondary",
+ tealTint:
+ "border-category-teal/40 bg-category-teal/10 text-foreground-secondary",
+ orangeTint:
+ "border-category-orange/40 bg-category-orange/10 text-foreground-secondary",
+ limeTint:
+ "border-category-lime/40 bg-category-lime/10 text-foreground-secondary",
+ fuchsiaTint:
+ "border-category-fuchsia/40 bg-category-fuchsia/10 text-foreground-secondary",
},
interactive: {
true: "underline-dotted",
@@ -35,6 +55,10 @@ const badgeVariants = cva(
sans: "font-sans",
mono: "font-mono",
},
+ shouldWrap: {
+ true: "h-auto leading-snug",
+ false: "",
+ },
},
defaultVariants: {
color: "primary",
@@ -45,7 +69,10 @@ const badgeVariants = cva(
},
);
-type BadgeShellProps = Omit<ComponentPropsWithoutRef<"span">, "className"> &
+type BadgeShellProps = Omit<
+ ComponentPropsWithoutRef<"span">,
+ "className" | "style"
+> &
VariantProps<typeof badgeVariants> & {
asChild?: boolean;
};
@@ -62,6 +89,7 @@ export function BadgeShell({
size,
interactive,
font,
+ shouldWrap,
...props
}: BadgeShellProps) {
const Component = asChild ? Slot : "span";
@@ -70,7 +98,7 @@ export function BadgeShell({
<Component
className={cn(
"group/badge",
- badgeVariants({ color, size, interactive, font }),
+ badgeVariants({ color, size, interactive, font, shouldWrap }),
)}
{...props}
/>
@@ -92,16 +120,20 @@ export function Badge({
label,
title,
interactive,
+ shouldWrap,
trailingIcon: TrailingIcon,
trailingIconTone = "default",
...props
}: BadgeProps) {
return (
- <BadgeShell color={color} {...props}>
+ <BadgeShell color={color} shouldWrap={shouldWrap} {...props}>
{label && <span className="shrink-0 py-0.5">{label}:</span>}
<span
className={cn(
- "py-0.5 text-ellipsis whitespace-nowrap",
+ "py-0.5",
+ shouldWrap
+ ? "min-w-0 break-words whitespace-normal"
+ : "text-ellipsis whitespace-nowrap",
interactive
? "underline-dotted overflow-clip"
: "overflow-x-clip overflow-y-visible",
diff --git a/web/src/features/topics/CurrentTopics.tsx b/web/src/features/topics/CurrentTopics.tsx
index 217f238ca3..358b4228ac 100644
--- a/web/src/features/topics/CurrentTopics.tsx
+++ b/web/src/features/topics/CurrentTopics.tsx
@@ -11,7 +11,6 @@ import { type LangfuseColumnDef } from "@/src/components/table/types";
import { usePeekNavigation } from "@/src/components/table/peek/hooks/usePeekNavigation";
import { api, type RouterOutputs } from "@/src/utils/api";
import { Button } from "@/src/components/design-system/Button/Button";
-import { Badge } from "@/src/components/design-system/Badge/Badge";
import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
import { TextLink } from "@/src/components/design-system/TextLink/TextLink";
@@ -19,7 +18,8 @@ import { Tabs } from "@/src/components/design-system/Tabs/Tabs";
import { useIsMobile } from "@/src/hooks/use-mobile";
import { TopicEmbeddingMap } from "./TopicEmbeddingMap";
import { TopicGroupCard } from "./TopicGroupCard";
-import { topicColor } from "./topic-map-colors";
+import { topicBadgeColor, topicColor } from "./topic-map-colors";
+import { TopicBadge } from "./TopicBadge";
import { SummaryInspector } from "./SummaryInspector";
import { isValidTopicTimeRange } from "./time-range";
@@ -244,6 +244,7 @@ function CurrentFacet({
projectId={projectId}
facetId={facet.facetId}
rows={visible}
+ topics={topics}
pagination={pagination}
onPaginationChange={setPagination}
/>
@@ -298,12 +299,14 @@ function CurrentTraceTable({
projectId,
facetId,
rows,
+ topics,
pagination,
onPaginationChange,
}: {
projectId: string;
facetId: string;
rows: Facet["rows"];
+ topics: { id: string }[];
pagination: PaginationState;
onPaginationChange: OnChangeFn<PaginationState>;
}) {
@@ -314,6 +317,9 @@ function CurrentTraceTable({
queryParams: ["observation", "display", "timestamp", "traceId"],
});
const peekConfig = { itemType: "TRACE" as const, ...peekNavigation };
+ const topicColors = new Map(
+ topics.map((topic, index) => [topic.id, topicBadgeColor(index)]),
+ );
const pageIndex = Math.min(
pagination.pageIndex,
Math.max(0, Math.ceil(rows.length / pagination.pageSize) - 1),
@@ -350,10 +356,10 @@ function CurrentTraceTable({
size: 148,
minSize: 100,
cell: ({ row }) => (
- <Badge
- text={
- row.original.topicName ?? row.original.outcome.replaceAll("_", " ")
- }
+ <TopicBadge
+ row={row.original}
+ color={topicColors.get(row.original.topicId ?? "")}
+ size="default"
/>
),
},
@@ -379,13 +385,13 @@ function CurrentTraceTable({
<div className="flex flex-col items-start gap-1 py-1">
{isMobile && (
<div className="flex w-full min-w-0 items-center justify-between gap-2">
- <Badge
- text={
- row.original.topicName ??
- row.original.outcome.replaceAll("_", " ")
- }
- size="sm"
- />
+ <div className="min-w-0">
+ <TopicBadge
+ row={row.original}
+ color={topicColors.get(row.original.topicId ?? "")}
+ size="sm"
+ />
+ </div>
<TextLink
path={`/project/${projectId}/traces/${encodeURIComponent(row.original.traceId)}`}
value="Open trace"
@@ -397,8 +403,8 @@ function CurrentTraceTable({
{row.original.summary || "No applicable summary."}
</p>
<Button
- text="Inspect transcript"
- variant="ghost"
+ text="Debug transcript"
+ variant="secondary"
size="sm"
onClick={inspectTranscript}
/>
diff --git a/web/src/features/topics/TopicBadge.tsx b/web/src/features/topics/TopicBadge.tsx
new file mode 100644
index 0000000000..4b9ac59b96
--- /dev/null
+++ b/web/src/features/topics/TopicBadge.tsx
@@ -0,0 +1,19 @@
+import { type ComponentProps } from "react";
+import { Badge } from "@/src/components/design-system/Badge/Badge";
+
+export function TopicBadge({ row, color, size }: TopicBadgeProps) {
+ return (
+ <Badge
+ text={row.topicName ?? row.outcome.replaceAll("_", " ")}
+ color={color}
+ size={size}
+ shouldWrap
+ />
+ );
+}
+
+type TopicBadgeProps = {
+ row: { topicName: string | null; outcome: string };
+ color: ComponentProps<typeof Badge>["color"];
+ size: "default" | "sm";
+};
diff --git a/web/src/features/topics/TopicEmbeddingMap.tsx b/web/src/features/topics/TopicEmbeddingMap.tsx
index 3e93d33820..99bb928bd6 100644
--- a/web/src/features/topics/TopicEmbeddingMap.tsx
+++ b/web/src/features/topics/TopicEmbeddingMap.tsx
@@ -3,6 +3,7 @@ import { Alert } from "@/src/components/design-system/Alert/Alert";
import { usePeekNavigation } from "@/src/components/table/peek/hooks/usePeekNavigation";
import { api, type RouterOutputs } from "@/src/utils/api";
import { EmbeddingMapView } from "./EmbeddingMapView";
+import { TopicMapLoading } from "./TopicMapLoading";
type Topic = Pick<
RouterOutputs["topics"]["currentResults"][number]["topics"][number],
@@ -50,12 +51,7 @@ export function TopicEmbeddingMap({
</Alert.Description>
</Alert>
);
- if (!query.data)
- return (
- <div className="bg-muted/20 flex h-72 items-center justify-center rounded-lg border text-sm">
- Loading embedding map…
- </div>
- );
+ if (!query.data) return <TopicMapLoading fillContainer={fillContainer} />;
if (query.data.status !== "ready")
return (
<p className="text-muted-foreground rounded-lg border p-4 text-sm">
diff --git a/web/src/features/topics/TopicMapLoading.stories.tsx b/web/src/features/topics/TopicMapLoading.stories.tsx
new file mode 100644
index 0000000000..ee03fbc470
--- /dev/null
+++ b/web/src/features/topics/TopicMapLoading.stories.tsx
@@ -0,0 +1,49 @@
+import { expect, fn, waitFor, within } from "storybook/test";
+import preview from "../../../.storybook/preview";
+import { EmbeddingMapView } from "./EmbeddingMapView";
+import { TopicMapLoading } from "./TopicMapLoading";
+
+const meta = preview.meta({
+ component: TopicMapLoading,
+ render: (args) => (
+ <div className="grid grid-cols-2 gap-2">
+ <div className="flex h-[680px] min-h-0 flex-col">
+ <TopicMapLoading {...args} />
+ </div>
+ <div className="flex h-[680px] min-h-0 flex-col">
+ <EmbeddingMapView
+ projectId="project"
+ data={{ points: [], missingSummaryCount: 0, unpositionedCount: 0 }}
+ topics={[]}
+ selectedTopic={null}
+ selectedTraceId={null}
+ onSelectTopic={fn()}
+ onSelectTrace={fn()}
+ onOpenTrace={fn()}
+ fillContainer={args.fillContainer}
+ />
+ </div>
+ </div>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const loading = canvas.getByRole("status");
+ const loaded = canvas.getByRole("region", { name: "Embedding map" });
+ await waitFor(() => {
+ const loadingBounds = loading.getBoundingClientRect();
+ const loadedBounds = loaded.getBoundingClientRect();
+ expect(loadingBounds.width).toBeCloseTo(loadedBounds.width, 1);
+ expect(loadingBounds.height).toBeCloseTo(loadedBounds.height, 1);
+ });
+ },
+});
+
+export const FillContainer = meta.story({
+ name: "(Test) Loading matches loaded container size",
+ args: { fillContainer: true },
+});
+
+export const Standalone = meta.story({
+ name: "(Test) Loading matches loaded standalone size",
+ args: { fillContainer: false },
+});
diff --git a/web/src/features/topics/TopicMapLoading.tsx b/web/src/features/topics/TopicMapLoading.tsx
new file mode 100644
index 0000000000..7bab20229d
--- /dev/null
+++ b/web/src/features/topics/TopicMapLoading.tsx
@@ -0,0 +1,28 @@
+import { cn } from "@/src/utils/tailwind";
+
+export function TopicMapLoading({ fillContainer }: TopicMapLoadingProps) {
+ return (
+ <div
+ role="status"
+ className={cn(
+ "bg-muted/20 flex min-w-0 flex-col overflow-hidden rounded-lg border text-sm",
+ fillContainer && "h-full min-h-0",
+ )}
+ >
+ <div
+ className={cn(
+ "flex items-center justify-center",
+ fillContainer
+ ? "min-h-0 flex-1"
+ : "h-[clamp(380px,64vh,820px)] min-h-[340px]",
+ )}
+ >
+ Loading embedding map…
+ </div>
+ </div>
+ );
+}
+
+type TopicMapLoadingProps = {
+ fillContainer: boolean;
+};
diff --git a/web/src/features/topics/topic-map-colors.ts b/web/src/features/topics/topic-map-colors.ts
index 39bd575b30..65060092a9 100644
--- a/web/src/features/topics/topic-map-colors.ts
+++ b/web/src/features/topics/topic-map-colors.ts
@@ -1,14 +1,21 @@
+/** Canvas colors match the category tokens in styles/globals.css. */
const COLORS = [
- "#7c3aed",
- "#0284c7",
- "#059669",
- "#d97706",
- "#db2777",
- "#4f46e5",
- "#0d9488",
- "#c2410c",
- "#65a30d",
- "#a21caf",
-];
+ { color: "#7c3aed", badgeColor: "violetTint" },
+ { color: "#0284c7", badgeColor: "skyTint" },
+ { color: "#059669", badgeColor: "emeraldTint" },
+ { color: "#d97706", badgeColor: "amberTint" },
+ { color: "#db2777", badgeColor: "pinkTint" },
+ { color: "#4f46e5", badgeColor: "indigoTint" },
+ { color: "#0d9488", badgeColor: "tealTint" },
+ { color: "#c2410c", badgeColor: "orangeTint" },
+ { color: "#65a30d", badgeColor: "limeTint" },
+ { color: "#a21caf", badgeColor: "fuchsiaTint" },
+] as const;
+
export const topicColor = (index: number) =>
- index < 0 ? "#94a3b8" : COLORS[index % COLORS.length];
+ index < 0 ? "#94a3b8" : COLORS[index % COLORS.length].color;
+
+export const topicBadgeColor = (
+ index: number,
+): (typeof COLORS)[number]["badgeColor"] | "primary" =>
+ index < 0 ? "primary" : COLORS[index % COLORS.length].badgeColor;
diff --git a/web/src/styles/globals.css b/web/src/styles/globals.css
index 382242f911..d6ee641265 100644
--- a/web/src/styles/globals.css
+++ b/web/src/styles/globals.css
@@ -137,6 +137,18 @@
--color-light-teal: hsl(var(--light-teal));
--color-dark-teal: hsl(var(--dark-teal));
+ /* Match the canvas palette in features/topics/topic-map-colors.ts. */
+ --color-category-violet: #7c3aed;
+ --color-category-sky: #0284c7;
+ --color-category-emerald: #059669;
+ --color-category-amber: #d97706;
+ --color-category-pink: #db2777;
+ --color-category-indigo: #4f46e5;
+ --color-category-teal: #0d9488;
+ --color-category-orange: #c2410c;
+ --color-category-lime: #65a30d;
+ --color-category-fuchsia: #a21caf;
+
/* Search-bar query syntax highlighting (key:value token parts). Operators
(`:` `-` `(` `)`) reuse muted-foreground, so no token for them here. */
--color-qlang-field: hsl(var(--qlang-field));