Skip to content

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

refactor(web): Clean up `TableLink` (#16752)

Ben Bachemdb87cc5d0807
diff --git a/web/.storybook/main.ts b/web/.storybook/main.ts
index 6c01465b77..5d02332577 100644
--- a/web/.storybook/main.ts
+++ b/web/.storybook/main.ts
@@ -23,6 +23,7 @@ const DESIGN_COMPONENT_STORIES = [
"SearchInput/SearchInput",
"Spinner/Spinner",
"Switch/Switch",
+ "TextLink/TextLink",
"Toggle/Toggle",
"table/columns/createBadgeTableColumn",
"table/columns/createDateTableColumn",
diff --git a/web/src/components/design-system/TextLink/TextLink.stories.tsx b/web/src/components/design-system/TextLink/TextLink.stories.tsx
new file mode 100644
index 0000000000..203bf87dd3
--- /dev/null
+++ b/web/src/components/design-system/TextLink/TextLink.stories.tsx
@@ -0,0 +1,24 @@
+import { User } from "lucide-react";
+
+import preview from "../../../../.storybook/preview";
+import { TextLink } from "./TextLink";
+
+const meta = preview.meta({
+ component: TextLink,
+});
+
+export const Default = meta.story({
+ args: {
+ path: "#",
+ value: "View user",
+ },
+});
+
+export const WithIcon = meta.story({
+ name: "With Icon",
+ args: {
+ path: "#",
+ value: "View user",
+ icon: User,
+ },
+});
diff --git a/web/src/components/design-system/TextLink/TextLink.tsx b/web/src/components/design-system/TextLink/TextLink.tsx
new file mode 100644
index 0000000000..17039f265f
--- /dev/null
+++ b/web/src/components/design-system/TextLink/TextLink.tsx
@@ -0,0 +1,50 @@
+import Link from "next/link";
+import { type LucideIcon } from "lucide-react";
+
+export function TextLink({
+ path,
+ value,
+ icon,
+ onClick,
+ title,
+}: {
+ path: string;
+ value: string;
+ icon?: LucideIcon;
+ onClick?: (event: React.MouseEvent) => void;
+ title?: string;
+}) {
+ const Icon = icon;
+ const handleClick = (event: React.MouseEvent) => {
+ if (!onClick) return;
+ // Preserve native new-tab gestures when the link has a real destination.
+ const isModifiedClick =
+ event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0;
+ if (path && isModifiedClick) return;
+ event.preventDefault();
+ onClick(event);
+ };
+
+ return (
+ <Link
+ className="text-link hover:text-link-hover inline-block max-w-full text-xs leading-normal font-bold"
+ href={path}
+ title={title ?? value}
+ prefetch={false}
+ onClick={handleClick}
+ >
+ <span className="inline-block max-w-full overflow-hidden align-middle leading-normal text-nowrap text-ellipsis">
+ {Icon ? (
+ <span className="inline-flex max-w-full items-center gap-1">
+ <Icon className="h-3.5 w-3.5 shrink-0" />
+ <span className="truncate" title={title ?? value}>
+ {value}
+ </span>
+ </span>
+ ) : (
+ value
+ )}
+ </span>
+ </Link>
+ );
+}
diff --git a/web/src/components/design-system/table/columns/createFolderKeyTableColumn.tsx b/web/src/components/design-system/table/columns/createFolderKeyTableColumn.tsx
index 1b1a697022..444332c318 100644
--- a/web/src/components/design-system/table/columns/createFolderKeyTableColumn.tsx
+++ b/web/src/components/design-system/table/columns/createFolderKeyTableColumn.tsx
@@ -2,15 +2,16 @@ import { type CellContext, type RowData } from "@tanstack/react-table";
import { Folder } from "lucide-react";
import { TableTextLoadingCell } from "@/src/components/table/loading-cells";
-import TableLink, {
- type TableLinkProps,
-} from "@/src/components/table/table-link";
+import { TextLink } from "@/src/components/design-system/TextLink/TextLink";
import {
createTableColumn,
type TableColumnOptions,
} from "./utils/createTableColumn";
-type LinkProps = Pick<TableLinkProps, "path" | "value" | "title" | "onClick">;
+type LinkProps = Pick<
+ React.ComponentProps<typeof TextLink>,
+ "path" | "value" | "title" | "onClick"
+>;
export function createFolderKeyTableColumn<
TData extends RowData,
@@ -36,22 +37,24 @@ export function createFolderKeyTableColumn<
if (cell.type === "folder") {
return (
- <TableLink
+ <TextLink
path=""
value={cell.name}
- icon={
- <div className="flex flex-row items-center gap-1">
- <Folder className="h-3.5 w-3.5 shrink-0" />
- {cell.name}
- </div>
- }
+ icon={Folder}
onClick={cell.onClick}
title={cell.name}
/>
);
}
- return <TableLink {...cell.props} />;
+ return (
+ <TextLink
+ path={cell.props.path}
+ value={cell.props.value}
+ title={cell.props.title ?? cell.props.value}
+ onClick={cell.props.onClick}
+ />
+ );
},
});
}
diff --git a/web/src/components/design-system/table/columns/createLinkListTableColumn.stories.tsx b/web/src/components/design-system/table/columns/createLinkListTableColumn.stories.tsx
new file mode 100644
index 0000000000..e11b2d43da
--- /dev/null
+++ b/web/src/components/design-system/table/columns/createLinkListTableColumn.stories.tsx
@@ -0,0 +1,87 @@
+import preview from "../../../../../.storybook/preview";
+
+import {
+ DataTable,
+ type AsyncTableData,
+} from "@/src/components/table/data-table";
+import { createLinkListTableColumn } from "./createLinkListTableColumn";
+
+type Row = {
+ isLinkListLoading?: boolean;
+ userIds: string[] | null;
+};
+
+const columns = [
+ createLinkListTableColumn<Row>({
+ accessorKey: "userIds",
+ header: "User IDs",
+ getCell: (userIds, { row }) => {
+ if (row.original.isLinkListLoading) return { type: "loading" };
+ if (!userIds?.length) return undefined;
+
+ return userIds.map((userId) => ({
+ path: `/users/${encodeURIComponent(userId)}`,
+ value: userId,
+ }));
+ },
+ }),
+];
+
+function LinkListTableColumnStory({ data }: { data: AsyncTableData<Row[]> }) {
+ return (
+ <DataTable
+ tableName="link-list-column-story"
+ columns={columns}
+ data={data}
+ hidePagination
+ cellPadding="comfortable"
+ />
+ );
+}
+
+const meta = preview.meta({
+ component: LinkListTableColumnStory,
+ parameters: {
+ layout: "fullscreen",
+ },
+});
+
+export const Default = meta.story({
+ args: {
+ data: {
+ isLoading: false,
+ isError: false,
+ data: [{ userIds: ["user-1", "user-2"] }],
+ },
+ },
+});
+
+export const Empty = meta.story({
+ args: {
+ data: {
+ isLoading: false,
+ isError: false,
+ data: [{ userIds: null }],
+ },
+ },
+});
+
+export const CellLoading = meta.story({
+ name: "Cell Loading",
+ args: {
+ data: {
+ isLoading: false,
+ isError: false,
+ data: [{ isLinkListLoading: true, userIds: null }],
+ },
+ },
+});
+
+export const Loading = meta.story({
+ args: {
+ data: {
+ isLoading: true,
+ isError: false,
+ },
+ },
+});
diff --git a/web/src/components/design-system/table/columns/createLinkListTableColumn.tsx b/web/src/components/design-system/table/columns/createLinkListTableColumn.tsx
new file mode 100644
index 0000000000..5cbade38f4
--- /dev/null
+++ b/web/src/components/design-system/table/columns/createLinkListTableColumn.tsx
@@ -0,0 +1,47 @@
+import { type CellContext, type RowData } from "@tanstack/react-table";
+
+import { TextLink } from "@/src/components/design-system/TextLink/TextLink";
+import { TableTextLoadingCell } from "@/src/components/table/loading-cells";
+import {
+ createTableColumn,
+ type TableColumnOptions,
+} from "./utils/createTableColumn";
+
+type LinkProps = Pick<
+ React.ComponentProps<typeof TextLink>,
+ "path" | "value" | "title" | "onClick"
+>;
+
+export function createLinkListTableColumn<TData extends RowData>({
+ getCell,
+ ...options
+}: TableColumnOptions<TData, string[]> & {
+ getCell: (
+ value: string[] | null | undefined,
+ context: CellContext<TData, string[] | null | undefined>,
+ ) => { type: "loading" } | LinkProps[] | undefined;
+}) {
+ return createTableColumn<TData, string[]>({
+ ...options,
+ loadingCell: <TableTextLoadingCell />,
+ renderCell: (value, context) => {
+ const cell = getCell(value, context);
+ if (!cell) return null;
+ if (!Array.isArray(cell)) return <TableTextLoadingCell />;
+
+ return (
+ <div className="flex gap-1">
+ {cell.map((linkProps) => (
+ <TextLink
+ key={linkProps.path}
+ path={linkProps.path}
+ value={linkProps.value}
+ title={linkProps.title ?? linkProps.value}
+ onClick={linkProps.onClick}
+ />
+ ))}
+ </div>
+ );
+ },
+ });
+}
diff --git a/web/src/components/design-system/table/columns/createLinkTableColumn.tsx b/web/src/components/design-system/table/columns/createLinkTableColumn.tsx
index d50f3b072d..676c408448 100644
--- a/web/src/components/design-system/table/columns/createLinkTableColumn.tsx
+++ b/web/src/components/design-system/table/columns/createLinkTableColumn.tsx
@@ -2,16 +2,14 @@ import { type CellContext, type RowData } from "@tanstack/react-table";
import { type LucideIcon } from "lucide-react";
import { TableTextLoadingCell } from "@/src/components/table/loading-cells";
-import TableLink, {
- type TableLinkProps,
-} from "@/src/components/table/table-link";
+import { TextLink } from "@/src/components/design-system/TextLink/TextLink";
import {
createTableColumn,
type TableColumnOptions,
} from "./utils/createTableColumn";
type LinkTableColumnProps = Pick<
- TableLinkProps,
+ React.ComponentProps<typeof TextLink>,
"path" | "value" | "title" | "onClick"
> & {
icon?: LucideIcon;
@@ -37,11 +35,14 @@ export function createLinkTableColumn<TData extends RowData, TValue = string>({
if (!cell) return null;
if (cell.type === "loading") return <TableTextLoadingCell />;
- const { icon: Icon, ...tableLinkProps } = cell.props;
+ const { icon: Icon, path, value: linkValue, title, onClick } = cell.props;
return (
- <TableLink
- {...tableLinkProps}
- icon={Icon ? <Icon className="h-4 w-4" /> : undefined}
+ <TextLink
+ path={path}
+ value={linkValue}
+ title={title ?? linkValue}
+ onClick={onClick}
+ icon={Icon}
/>
);
},
diff --git a/web/src/components/table/DataTable.stories.tsx b/web/src/components/table/DataTable.stories.tsx
index e119c671b8..30c5694bcf 100644
--- a/web/src/components/table/DataTable.stories.tsx
+++ b/web/src/components/table/DataTable.stories.tsx
@@ -25,7 +25,7 @@ import { createIdTableColumn } from "@/src/components/design-system/table/column
import { createNumberTableColumn } from "@/src/components/design-system/table/columns/createNumberTableColumn";
import { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";
import { Skeleton } from "@/src/components/ui/skeleton";
-import TableLink from "@/src/components/table/table-link";
+import { TextLink } from "@/src/components/design-system/TextLink/TextLink";
import TableIdOrName from "@/src/components/table/table-id";
import { LocalIsoDate } from "@/src/components/LocalIsoDate";
import { MemoizedIOTableCell } from "@/src/components/ui/IOTableCell";
@@ -85,7 +85,7 @@ import {
// instead of TagPromptPopover/TagManager (same visible children).
// - actions: real DropdownMenu + ghost MoreVertical, with a plain menu item
// instead of the tRPC-bound DeleteTraceButton / DeletePrompt.
-// Everything else (TableLink, Badge, IOTableCell, LocalIsoDate, TableIdOrName,
+// Everything else (TextLink, Badge, IOTableCell, LocalIsoDate, TableIdOrName,
// TokenUsageBadge, LevelCountsDisplay, folder links, Skeleton, the
// loading cells) is the actual production component.
//
@@ -1134,12 +1134,12 @@ export const WithGroupedHeaders = meta.story({
// -----------------------------------------------------------------------------
// Reproduces features/prompts/components/prompts-table.tsx cell-for-cell:
// - cellPadding="comfortable" (the Prompts one-off override at prompts-table.tsx:482)
-// - Name column: folder rows use the folder key column (TableLink + Folder
-// icon); prompt rows use TableLink to the prompt.
+// - Name column: folder rows use the folder key column (TextLink + Folder
+// icon); prompt rows use TextLink to the prompt.
// - Versions/Type: folder rows render null -> empty cells (column rhythm
// visibly breaks between folder and prompt rows, as in production).
// - "Latest Version Created At": LocalIsoDate, null on folder rows.
-// - "Number of Observations (7d)": TableLink wrapping the count (0 still links),
+// - "Number of Observations (7d)": TextLink wrapping the count (0 still links),
// with the real Skeleton fallback shape (h-3 w-1/2).
// - Tags: real TagList in the `flex gap-x-1 gap-y-1` wrapper; folder rows
// render the `h-6` spacer.
@@ -1272,11 +1272,17 @@ const promptColumns: LangfuseColumnDef<PromptRow>[] = [
if (row.original.type === "folder") return null;
const n = row.original.numberOfObservations;
// Real cell shows a Skeleton h-3 w-1/2 while metrics load; here metrics
- // are "loaded", so it always renders the TableLink (0 still links).
+ // are "loaded", so it always renders the TextLink (0 still links).
if (n === undefined) {
return <Skeleton className="h-3 w-1/2" />;
}
- return <TableLink path="/observations" value={n.toLocaleString()} />;
+ return (
+ <TextLink
+ path="/observations"
+ value={n.toLocaleString()}
+ title={n.toLocaleString()}
+ />
+ );
},
},
{
@@ -1373,7 +1379,7 @@ export const WithFolderRows = meta.story({
// ProvidedModelNameCell: the name is wrapped in `inline-flex items-center`
// with the icon as a `shrink-0` adornment, so it lands on the same baseline
// as the no-icon rows.
-// - TableLink with a leading icon (ListTree)
+// - TextLink with a leading icon (ListTree)
// - Folder link (Folder icon)
// A second plain-text column shows the row stays aligned across the table.
@@ -1432,29 +1438,16 @@ const iconCellColumns: LangfuseColumnDef<IconCellRow>[] = [
);
case "link":
return (
- <TableLink
- path="#"
- value={name}
- icon={
- <span className="flex flex-row items-center gap-1">
- <ListTree className="h-3.5 w-3.5 shrink-0" />
- {name}
- </span>
- }
- />
+ <TextLink path="#" value={name} icon={ListTree} title={name} />
);
case "folder":
return (
- <TableLink
+ <TextLink
path=""
value={name}
- icon={
- <span className="flex flex-row items-center gap-1">
- <Folder className="h-3.5 w-3.5 shrink-0" />
- {name}
- </span>
- }
+ icon={Folder}
onClick={() => undefined}
+ title={name}
/>
);
case "plain":
diff --git a/web/src/components/table/peek/peek-evaluator-config-detail.tsx b/web/src/components/table/peek/peek-evaluator-config-detail.tsx
index d689ca3b35..7157ed0866 100644
--- a/web/src/components/table/peek/peek-evaluator-config-detail.tsx
+++ b/web/src/components/table/peek/peek-evaluator-config-detail.tsx
@@ -1,6 +1,6 @@
import { useRouter } from "next/router";
import { Skeleton } from "@/src/components/ui/skeleton";
-import TableLink from "@/src/components/table/table-link";
+import { TextLink } from "@/src/components/design-system/TextLink/TextLink";
import { CardDescription } from "@/src/components/ui/card";
import { EvaluatorForm } from "@/src/features/evals/components/evaluator-form";
import { usePeekEvalConfigData } from "@/src/components/table/peek/hooks/usePeekEvalConfigData";
@@ -154,11 +154,13 @@ const PeekViewEvaluatorConfigDetail = ({
<CardDescription className="flex items-center text-sm">
<span className="mr-2 text-sm font-bold">Referenced Evaluator</span>
{evalConfig.evalTemplate && (
- <TableLink
- path={`/project/${projectId}/evals/templates/${evalConfig.evalTemplate.id}`}
- value={evalConfig.evalTemplate.name}
- className="mr-1 flex min-h-6 items-center"
- />
+ <span className="mr-1 flex min-h-6 items-center">
+ <TextLink
+ path={`/project/${projectId}/evals/templates/${evalConfig.evalTemplate.id}`}
+ value={evalConfig.evalTemplate.name}
+ title={evalConfig.evalTemplate.name}
+ />
+ </span>
)}
{evalConfig.evalTemplate && (
<Tooltip>
diff --git a/web/src/components/table/table-link.tsx b/web/src/components/table/table-link.tsx
deleted file mode 100644
index a52537a3a6..0000000000
--- a/web/src/components/table/table-link.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-/* eslint-disable @repo/no-style-props */
-import { cn } from "@/src/utils/tailwind";
-import Link from "next/link";
-
-export type TableLinkProps = {
- path: string;
- value: string;
- icon?: React.ReactNode;
- className?: string;
- onClick?: (event: React.MouseEvent) => void;
- title?: string;
-};
-
-export default function TableLink({
- path,
- value,
- icon,
- className,
- onClick,
- title,
-}: TableLinkProps) {
- const handleClick = (event: React.MouseEvent) => {
- if (!onClick) return;
- // A modifier click (cmd/ctrl+click, shift+click) or a non-primary button
- // (middle-click) is the browser's own "open in a new tab/window" gesture
- // — let it through to the real anchor href instead of hijacking it (e.g. a
- // peek-opening `onClick`), as long as there IS a real destination to open.
- // `path=""` callers (e.g. folder breadcrumbs, which use `onClick` as their
- // only action) have no real destination, so they keep the old
- // always-intercept behavior.
- const isModifiedClick =
- event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0;
- if (path && isModifiedClick) return;
- event.preventDefault();
- onClick(event);
- };
-
- return (
- <Link
- className={cn(
- "text-link hover:text-link-hover inline-block max-w-full text-xs leading-normal font-bold",
- className,
- )}
- href={path}
- title={title || value}
- prefetch={false}
- onClick={handleClick}
- >
- <span className="inline-block max-w-full overflow-hidden align-middle leading-normal text-nowrap text-ellipsis">
- {icon ? <span className="inline-block">{icon}</span> : value}
- </span>
- </Link>
- );
-}
diff --git a/web/src/components/table/use-cases/sessions.tsx b/web/src/components/table/use-cases/sessions.tsx
index 804b6d4c7a..65f97de2cf 100644
--- a/web/src/components/table/use-cases/sessions.tsx
+++ b/web/src/components/table/use-cases/sessions.tsx
@@ -8,9 +8,9 @@ import { TableTextLoadingCell } from "@/src/components/table/loading-cells";
import { createBadgeTableColumn } from "@/src/components/design-system/table/columns/createBadgeTableColumn";
import { createDateTableColumn } from "@/src/components/design-system/table/columns/createDateTableColumn";
import { createLinkTableColumn } from "@/src/components/design-system/table/columns/createLinkTableColumn";
+import { createLinkListTableColumn } from "@/src/components/design-system/table/columns/createLinkListTableColumn";
import { createNumberTableColumn } from "@/src/components/design-system/table/columns/createNumberTableColumn";
import { ResizableFilterLayout } from "@/src/components/table/resizable-filter-layout";
-import TableLink from "@/src/components/table/table-link";
import { type LangfuseColumnDef } from "@/src/components/table/types";
import { TokenUsageBadge } from "@/src/components/token-usage-badge";
import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";
@@ -553,32 +553,22 @@ export default function SessionsTable({
},
columns: scoreColumns,
},
- {
+ createLinkListTableColumn<SessionTableRow>({
accessorKey: "userIds",
enableColumnFilter: !omittedFilter.includes("userIds"),
- id: "userIds",
header: "User IDs",
size: 200,
enableHiding: true,
- loadingCell: <TableTextLoadingCell />,
- cell: ({ row }) => {
- const value: SessionTableRow["userIds"] = row.getValue("userIds");
- if (!sessionMetrics.isSuccess) {
- return <TableTextLoadingCell />;
- }
- return value && Array.isArray(value) ? (
- <div className="flex gap-1">
- {(value as string[]).map((user) => (
- <TableLink
- key={user}
- path={`/project/${projectId}/users/${encodeURIComponent(user)}`}
- value={user}
- />
- ))}
- </div>
- ) : undefined;
+ getCell: (userIds) => {
+ if (!sessionMetrics.isSuccess) return { type: "loading" };
+ if (!userIds?.length) return undefined;
+
+ return userIds.map((userId) => ({
+ path: `/project/${projectId}/users/${encodeURIComponent(userId)}`,
+ value: userId,
+ }));
},
- },
+ }),
createNumberTableColumn<SessionTableRow>({
accessorKey: "countTraces",
header: "Traces",
diff --git a/web/src/features/prompts/components/prompts-table.tsx b/web/src/features/prompts/components/prompts-table.tsx
index 09569d170a..51e52fcc70 100644
--- a/web/src/features/prompts/components/prompts-table.tsx
+++ b/web/src/features/prompts/components/prompts-table.tsx
@@ -5,7 +5,7 @@ import {
DataTableControls,
} from "@/src/components/table/data-table-controls";
import { ResizableFilterLayout } from "@/src/components/table/resizable-filter-layout";
-import TableLink from "@/src/components/table/table-link";
+import { TextLink } from "@/src/components/design-system/TextLink/TextLink";
import { createFolderKeyTableColumn } from "@/src/components/design-system/table/columns/createFolderKeyTableColumn";
import { type LangfuseColumnDef } from "@/src/components/table/types";
import { useDetailPageLists } from "@/src/features/navigate-detail-pages/context";
@@ -340,10 +340,12 @@ export function PromptTable() {
if (!promptMetrics.isSuccess) {
return <Skeleton className="h-3 w-1/2" />;
}
+ const displayValue = numberOfObservations?.toLocaleString() ?? "";
return (
- <TableLink
+ <TextLink
path={`/project/${projectId}/observations?filter=${numberOfObservations ? filter : ""}`}
- value={numberOfObservations?.toLocaleString() ?? ""}
+ value={displayValue}
+ title={displayValue}
/>
);
},