🪢 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
refactor(web): Migrate audit log settings table to design system (#17822)
Ben Bachem767e7677865a
diff --git a/web/src/components/SettingsTable/SettingsTable.tsx b/web/src/components/SettingsTable/SettingsTable.tsxindex 7fbca81f8f..1683baf3c9 100644--- a/web/src/components/SettingsTable/SettingsTable.tsx+++ b/web/src/components/SettingsTable/SettingsTable.tsx@@ -1,4 +1,4 @@-import { useState } from "react";+import { useState, type ComponentProps } from "react";import {ActionButton,type ActionButtonProps,@@ -15,6 +15,11 @@ import { MultiSelectInput } from "@/src/components/design-system/MultiSelectInpuimport { SearchInput } from "@/src/components/design-system/SearchInput/SearchInput";import { SettingsTableCard } from "@/src/components/layouts/settings-table-card";import { DataTableColumnVisibilityFilter } from "@/src/components/table/data-table-column-visibility-filter";+import { type RowHeight } from "@/src/components/table/data-table-row-height-switch";+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";+import { Button } from "@/src/components/ui/button";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics";+import { Rows3 } from "lucide-react";import { type LangfuseColumnDef } from "@/src/components/table/types";import { cn } from "@/src/utils/tailwind";import {@@ -22,9 +27,14 @@ import {useColumnVisibility,} from "@/src/features/column-visibility";-type SettingsTableToolbarAction = ActionButtonProps extends infer TAction+export type SettingsTableToolbarAction = ActionButtonProps extends infer TAction? TAction extends ActionButtonProps- ? Omit<TAction, "children"> & { id: string; label: string }+ ? Omit<TAction, "children" | "size"> & {+ id: string;+ label: string;+ size?: Exclude<NonNullable<ActionButtonProps["size"]>, "icon">;+ dropdown?: Omit<ComponentProps<typeof DropdownMenu>, "children">;+ }: never: never;@@ -51,6 +61,10 @@ export type SettingsTableProps<TData extends object> = Omit<};filters?: SettingsTableFilter[];toolbarActions?: SettingsTableToolbarAction[];+ rowHeightControl?: {+ rowHeight: RowHeight;+ onRowHeightChange: (height: RowHeight) => void;+ };pagination?: PaginationBarProps;};@@ -61,9 +75,11 @@ export function SettingsTable<TData extends object>({search,filters,toolbarActions,+ rowHeightControl,pagination,...tableProps}: SettingsTableProps<TData>) {+ const capture = usePostHogClientCapture();const [columnVisibility, setColumnVisibility] = useColumnVisibility(columnVisibilityKey ?? `${tableProps.tableName}ColumnVisibility`,columns,@@ -83,7 +99,11 @@ export function SettingsTable<TData extends object>({const hasFilters = Boolean(filters?.length);const hasToolbar = Boolean(- search || hasFilters || columnVisibilityKey || toolbarActions,+ search ||+ hasFilters ||+ columnVisibilityKey ||+ toolbarActions ||+ rowHeightControl,);return (@@ -148,11 +168,63 @@ export function SettingsTable<TData extends object>({isV4/>)}- {toolbarActions?.map(({ id, label, ...action }) => (- <ActionButton key={id} {...action}>- {label}- </ActionButton>- ))}+ {rowHeightControl && (+ <DropdownMenu+ title="Row height"+ items={(+ [+ { id: "s", title: "Small" },+ { id: "m", title: "Medium" },+ { id: "l", title: "Large" },+ ] as const+ ).map(({ id, title }) => ({+ type: "checkbox" as const,+ id,+ title,+ checked: rowHeightControl.rowHeight === id,+ closeOnCheckedChange: false,+ onCheckedChange: () => {+ capture("table:row_height_switch_select", {+ rowHeight: id,+ tableName: tableProps.tableName,+ isV4: true,+ });+ rowHeightControl.onRowHeightChange(id);+ },+ }))}+ >+ {({ getTriggerProps }) => (+ <Button+ {...getTriggerProps()}+ variant="outline"+ size="icon"+ title="Row height"+ aria-label="Row height"+ >+ <Rows3 className="h-4 w-4" />+ </Button>+ )}+ </DropdownMenu>+ )}+ {toolbarActions?.map(({ id, label, dropdown, ...action }) => {+ if (dropdown) {+ return (+ <DropdownMenu key={id} {...dropdown}>+ {({ getTriggerProps }) => (+ <ActionButton {...action} {...getTriggerProps()}>+ {label}+ </ActionButton>+ )}+ </DropdownMenu>+ );+ }++ return (+ <ActionButton key={id} {...action}>+ {label}+ </ActionButton>+ );+ })}</div></div>)}diff --git a/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx b/web/src/components/design-system/DropdownMenu/DropdownMenu.tsxindex 4356a9d2f9..36730b24d5 100644--- a/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx+++ b/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx@@ -174,6 +174,7 @@ type DropdownMenuProps = {placement?: Placement;search?: { placeholder: string };title?: string;+ description?: string;};function DropdownMenu(props: DropdownMenuProps) {@@ -194,6 +195,7 @@ function DropdownMenu(props: DropdownMenuProps) {function DropdownMenuNode({ariaLabel,children,+ description,disabled = false,items,maxHeight = "15rem",@@ -319,7 +321,7 @@ function DropdownMenuNode({refs.setFloating(element);register(element);}}- className={menuVariants()}+ className={menuVariants({ className: description && "w-80" })}style={{ ...floatingStyles, maxHeight }}{...getFloatingProps({ onScroll: recompute })}{...(ariaLabel || title@@ -332,6 +334,11 @@ function DropdownMenuNode({{title ? (<div className="border-border bg-popover sticky top-0 z-1 border-b px-3 py-2.5 text-sm font-bold">{title}+ {description && (+ <p className="text-muted-foreground mt-1 text-xs font-normal">+ {description}+ </p>+ )}</div>) : null}{search ? (diff --git a/web/src/components/design-system/table/Table.tsx b/web/src/components/design-system/table/Table.tsxindex 046c5f5e7e..8c16269eb2 100644--- a/web/src/components/design-system/table/Table.tsx+++ b/web/src/components/design-system/table/Table.tsx@@ -45,6 +45,7 @@ export interface TableProps<TData> {onColumnVisibilityChange?: OnChangeFn<VisibilityState>;columnOrder?: ColumnOrderState;onColumnOrderChange?: OnChangeFn<ColumnOrderState>;+ rowHeight?: "s" | "m" | "l";}export function Table<TData extends object>({@@ -61,6 +62,7 @@ export function Table<TData extends object>({onColumnVisibilityChange,columnOrder,onColumnOrderChange,+ rowHeight,}: TableProps<TData>) {const tableColumns = useMemo<ColumnDef<TData>[]>(() => {if (!actions) return columns;@@ -149,7 +151,7 @@ export function Table<TData extends object>({key={header.id}aria-sort={ariaSort}className={cn(- "group bg-background text-muted-foreground relative h-10 border-b p-1 text-left align-middle font-bold first:pl-2",+ "group bg-background text-muted-foreground relative h-10 border-b p-2 text-left align-middle font-bold",column.headerClassName,column.hideBelowMd && "hidden md:table-cell",)}@@ -253,7 +255,11 @@ export function Table<TData extends object>({Array.from({ length: loadingRowCount }).map((_, rowIndex) => (<trkey={`loading-row-${rowIndex}`}- className="h-12"+ className={cn(+ "h-12",+ rowHeight === "m" && "h-24",+ rowHeight === "l" && "h-64",+ )}aria-hidden="true">{visibleColumns.map((column, columnIndex) => {@@ -262,7 +268,10 @@ export function Table<TData extends object>({<tdkey={column.id}className={cn(- "h-full overflow-hidden border-b p-2 align-middle text-xs whitespace-nowrap first:pl-2",+ "h-full overflow-hidden border-b align-middle text-xs whitespace-nowrap",+ column.columnDef.cellPadding === "none"+ ? "p-0"+ : "p-2",column.columnDef.cellClassName,column.columnDef.hideBelowMd &&"hidden md:table-cell",@@ -304,6 +313,8 @@ export function Table<TData extends object>({key={row.id}className={cn("hover:bg-accent h-12 transition-colors",+ rowHeight === "m" && "h-24",+ rowHeight === "l" && "h-64",onRowClick ? "cursor-pointer" : "cursor-default",)}tabIndex={onRowClick ? 0 : undefined}@@ -323,12 +334,20 @@ export function Table<TData extends object>({<tdkey={cell.id}className={cn(- "h-full overflow-hidden border-b p-2 align-middle text-xs whitespace-nowrap first:pl-2",+ "h-full overflow-hidden border-b align-middle text-xs whitespace-nowrap",+ column.cellPadding === "none" ? "p-0" : "p-2",column.cellClassName,column.hideBelowMd && "hidden md:table-cell",)}>- <div className="flex min-w-0 items-center overflow-hidden">+ <div+ className={cn(+ "flex min-w-0 items-center overflow-hidden",+ rowHeight === "s" && "h-8",+ rowHeight === "m" && "h-20",+ rowHeight === "l" && "h-60",+ )}+ >{flexRender(column.cell, cell.getContext())}</div></td>diff --git a/web/src/components/design-system/table/columns/createActorTableColumn.stories.tsx b/web/src/components/design-system/table/columns/createActorTableColumn.stories.tsxnew file mode 100644index 0000000000..a79e2a109e--- /dev/null+++ b/web/src/components/design-system/table/columns/createActorTableColumn.stories.tsx@@ -0,0 +1,51 @@+import preview from "../../../../../.storybook/preview";++import { Table } from "@/src/components/design-system/table/Table";+import {+ createActorTableColumn,+ type TableActor,+} from "./createActorTableColumn";++type Row = { actor: TableActor | null };++const rows: Row[] = [+ {+ actor: {+ type: "USER",+ body: {+ id: "user-1",+ name: "Ada Lovelace",+ email: "[email protected]",+ image: null,+ },+ },+ },+ {+ actor: {+ type: "API_KEY",+ body: { id: "api-key-1", publicKey: "pk-example" },+ },+ },+ { actor: null },+];++function ActorTableColumnStory({ variant }: { variant: "avatar" | "text" }) {+ return (+ <Table+ tableName="Actors"+ columns={[+ createActorTableColumn<Row>({+ accessorKey: "actor",+ header: "Actor",+ variant,+ }),+ ]}+ data={{ status: "success", data: rows }}+ />+ );+}++const meta = preview.meta({ component: ActorTableColumnStory });++export const Avatar = meta.story({ args: { variant: "avatar" } });+export const Text = meta.story({ args: { variant: "text" } });diff --git a/web/src/components/design-system/table/columns/createActorTableColumn.tsx b/web/src/components/design-system/table/columns/createActorTableColumn.tsxnew file mode 100644index 0000000000..5759d01c30--- /dev/null+++ b/web/src/components/design-system/table/columns/createActorTableColumn.tsx@@ -0,0 +1,67 @@+import { type RowData } from "@tanstack/react-table";+import { KeyRound } from "lucide-react";++import {+ UserTableCell,+ type UserTableColumnValue,+} from "@/src/components/design-system/table/components/UserTableCell/UserTableCell";+import {+ createTableColumn,+ type TableColumnOptions,+} from "./utils/createTableColumn";++export type TableActor =+ | {+ type: "USER";+ body: UserTableColumnValue;+ }+ | {+ type: "API_KEY";+ body: { id?: string | null; publicKey?: string | null };+ };++export function createActorTableColumn<TData extends RowData>({+ variant,+ emptyValue = "—",+ unknownUserValue = "Unknown user",+ ...options+}: TableColumnOptions<TData, TableActor> & {+ variant: "avatar" | "text";+ emptyValue?: string;+ unknownUserValue?: string;+}) {+ return createTableColumn<TData, TableActor>({+ ...options,+ loadingCell: <UserTableCell variant="loading" presentation={variant} />,+ renderCell: (actor) => {+ if (!actor) return <span>{emptyValue}</span>;++ if (actor.type === "API_KEY") {+ const label = actor.body.publicKey ?? actor.body.id ?? emptyValue;+ return (+ <span+ className="flex min-w-0 items-center gap-2"+ title={`API key ${label}`}+ >+ <KeyRound+ className="text-muted-foreground size-4 shrink-0"+ aria-hidden="true"+ />+ <span className="truncate font-mono" title={label}>+ {label}+ </span>+ </span>+ );+ }++ return (+ <UserTableCell+ user={actor.body}+ variant={variant}+ emptyValue={unknownUserValue}+ avatarSize="sm"+ />+ );+ },+ });+}diff --git a/web/src/components/design-system/table/columns/createButtonTableColumn.tsx b/web/src/components/design-system/table/columns/createButtonTableColumn.tsxindex 5a96995415..5bc79d6718 100644--- a/web/src/components/design-system/table/columns/createButtonTableColumn.tsx+++ b/web/src/components/design-system/table/columns/createButtonTableColumn.tsx@@ -26,7 +26,7 @@ export function createButtonTableColumn<TData extends RowData, TValue>({renderCell: (_, context) => {const buttonProps = getButton(context);return (- <div className="ml-auto">+ <div><Button size="sm" {...buttonProps} /></div>);diff --git a/web/src/components/design-system/table/columns/createIOTableColumn.tsx b/web/src/components/design-system/table/columns/createIOTableColumn.tsxindex fb58bdc628..8d8cd55b2e 100644--- a/web/src/components/design-system/table/columns/createIOTableColumn.tsx+++ b/web/src/components/design-system/table/columns/createIOTableColumn.tsx@@ -59,6 +59,7 @@ export function createIOTableColumn<TData extends RowData, TValue = unknown>({return createTableColumn<TData, TValue>({...options,+ cellPadding: "none",cellBackground: ioCellBackgrounds[variant],loadingCell,renderCell: (value, context) => {diff --git a/web/src/components/design-system/table/columns/createUserTableColumn.tsx b/web/src/components/design-system/table/columns/createUserTableColumn.tsxindex 82c153e61b..e826a6d7e4 100644--- a/web/src/components/design-system/table/columns/createUserTableColumn.tsx+++ b/web/src/components/design-system/table/columns/createUserTableColumn.tsx@@ -1,21 +1,14 @@-/* eslint-disable boundaries/dependencies */import { type CellContext, type RowData } from "@tanstack/react-table";-import { Avatar } from "@/src/components/design-system/Avatar/Avatar";-import { EMPTY_VALUE_PLACEHOLDER } from "@/src/components/design-system/table/constants";-import { Skeleton } from "@/src/components/ui/skeleton";+import {+ UserTableCell,+ type UserTableColumnValue,+} from "@/src/components/design-system/table/components/UserTableCell/UserTableCell";import {createTableColumn,type TableColumnOptions,} from "./utils/createTableColumn";-type UserTableColumnValue = {- name?: string | null;- email?: string | null;- image?: string | null;- id?: string | null;-};-type UserTableColumnPresentation = { variant: "avatar" } | { variant: "text" };type UserTableColumnCell =| { type: "loading" }@@ -48,15 +41,9 @@ export function createUserTableColumn<context: CellContext<TData, TValue | null | undefined>,) => UserTableColumnCell;}) {- const loadingCell =- variant === "avatar" ? (- <div className="flex w-full min-w-0 items-center space-x-2">- <Skeleton className="h-7 w-7 shrink-0 rounded-full" />- <Skeleton className="h-4 max-w-24 min-w-12 flex-1" />- </div>- ) : (- <Skeleton className="h-4 w-1/2" />- );+ const loadingCell = (+ <UserTableCell variant="loading" presentation={variant} />+ );return createTableColumn<TData, TValue>({...options,@@ -81,35 +68,21 @@ export function createUserTableColumn<if (!cell) {const placeholder = nullValue ?? emptyValue;- return placeholder ? (+ if (!placeholder) return null;+ return (<span className="block w-full truncate" title={placeholder}>{placeholder}</span>- ) : null;- }- if (cell.type === "loading") return loadingCell;-- const { name, email, image, id } = cell.user;- const label =- name ?? email ?? id ?? emptyValue ?? EMPTY_VALUE_PLACEHOLDER;- if (variant === "text") {- return (- <span className="block truncate" title={label}>- {label}- </span>);}+ if (cell.type === "loading") return loadingCell;return (- <div- className="flex min-w-0 items-center space-x-2"- title={email ?? label}- >- <Avatar size="md" src={image ?? undefined} displayName={label} />- <span className="truncate" title={email ?? label}>- {label}- </span>- </div>+ <UserTableCell+ user={cell.user}+ variant={variant}+ emptyValue={emptyValue}+ />);},});diff --git a/web/src/components/design-system/table/components/UserTableCell/UserTableCell.tsx b/web/src/components/design-system/table/components/UserTableCell/UserTableCell.tsxnew file mode 100644index 0000000000..5dfc78f9fc--- /dev/null+++ b/web/src/components/design-system/table/components/UserTableCell/UserTableCell.tsx@@ -0,0 +1,63 @@+/* eslint-disable boundaries/dependencies */+import { Avatar } from "@/src/components/design-system/Avatar/Avatar";+import { EMPTY_VALUE_PLACEHOLDER } from "@/src/components/design-system/table/constants";+import { Skeleton } from "@/src/components/ui/skeleton";++export type UserTableColumnValue = {+ name?: string | null;+ email?: string | null;+ image?: string | null;+ id?: string | null;+};++export function UserTableCell({+ user,+ variant,+ presentation,+ emptyValue,+ avatarSize = "md",+}:+ | {+ variant: "avatar" | "text";+ user: UserTableColumnValue;+ emptyValue?: string;+ avatarSize?: "sm" | "md";+ presentation?: never;+ }+ | {+ variant: "loading";+ presentation: "avatar" | "text";+ user?: never;+ emptyValue?: never;+ avatarSize?: never;+ }) {+ if (variant === "loading") {+ if (presentation === "text") return <Skeleton className="h-4 w-1/2" />;++ return (+ <div className="flex w-full min-w-0 items-center space-x-2">+ <Skeleton className="h-7 w-7 shrink-0 rounded-full" />+ <Skeleton className="h-4 max-w-24 min-w-12 flex-1" />+ </div>+ );+ }++ const { name, email, image, id } = user;+ const label = name ?? email ?? id ?? emptyValue ?? EMPTY_VALUE_PLACEHOLDER;+ if (variant === "text") {+ return (+ <span className="block truncate" title={label}>+ {label}+ </span>+ );+ }++ return (+ <div className="flex min-w-0 items-center space-x-2" title={email ?? label}>+ <Avatar size={avatarSize} src={image ?? undefined} displayName={label} />+ <span className="truncate" title={email ?? label}>+ {label}+ </span>+ </div>+ );+}diff --git a/web/src/ee/features/audit-log-viewer/AuditLogsSettingsPage.tsx b/web/src/ee/features/audit-log-viewer/AuditLogsSettingsPage.tsxindex cd8478b772..ad3f716a03 100644--- a/web/src/ee/features/audit-log-viewer/AuditLogsSettingsPage.tsx+++ b/web/src/ee/features/audit-log-viewer/AuditLogsSettingsPage.tsx@@ -1,7 +1,7 @@/* eslint-disable no-nested-ternary */import Header from "@/src/components/layouts/header";import { Alert } from "@/src/components/design-system/Alert/Alert";-import { AuditLogsTable } from "@/src/ee/features/audit-log-viewer/AuditLogsTable";+import { ConnectedAuditLogsTable } from "@/src/ee/features/audit-log-viewer/AuditLogsTable/ConnectedAuditLogsTable";import { useHasEntitlement } from "@/src/features/entitlements";import { useHasProjectAccess } from "@/src/features/rbac";@@ -25,7 +25,7 @@ export function AuditLogsSettingsPage(props: { projectId: string }) {</Alert.Description></Alert>) : (- <AuditLogsTable scope="project" projectId={props.projectId} />+ <ConnectedAuditLogsTable scope="project" projectId={props.projectId} />);return (diff --git a/web/src/ee/features/audit-log-viewer/AuditLogsTable.tsx b/web/src/ee/features/audit-log-viewer/AuditLogsTable.tsxdeleted file mode 100644index 0fafc387a9..0000000000--- a/web/src/ee/features/audit-log-viewer/AuditLogsTable.tsx+++ /dev/null@@ -1,189 +0,0 @@-/* eslint-disable no-nested-ternary */-import { DataTable } from "@/src/components/table/data-table";-import { type LangfuseColumnDef } from "@/src/components/table/types";-import { api, type RouterOutputs } from "@/src/utils/api";-import { safeExtract } from "@/src/utils/map-utils";-import { useQueryParams, withDefault, NumberParam } from "use-query-params";-import { createIOTableColumn } from "@/src/components/design-system/table/columns/createIOTableColumn";-import { Avatar } from "@/src/components/design-system/Avatar/Avatar";-import { cn } from "@/src/utils/tailwind";-import { useRowHeightLocalStorage } from "@/src/components/table/data-table-row-height-switch";-import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";-import { SettingsTableCard } from "@/src/components/layouts/settings-table-card";-import { BatchExportTableButton } from "@/src/components/BatchExportTableButton";-import { BatchExportTableName } from "@langfuse/shared";-import { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";-import { useHasProjectAccess } from "@/src/features/rbac";--// Both endpoints return the same shape-type AuditLogRow = RouterOutputs["auditLogs"]["all"]["data"][number];--type AuditLogsTableProps =- | { scope: "project"; projectId: string }- | { scope: "organization"; orgId: string };--export function AuditLogsTable(props: AuditLogsTableProps) {- const hasBatchExportAccess = useHasProjectAccess({- projectId: props.scope === "project" ? props.projectId : undefined,- scope: "batchExports:create",- });- const [paginationState, setPaginationState] = useQueryParams({- pageIndex: withDefault(NumberParam, 0),- pageSize: withDefault(NumberParam, 50),- });-- // Use the appropriate query based on scope- const projectAuditLogs = api.auditLogs.all.useQuery(- {- projectId: props.scope === "project" ? props.projectId : "",- page: paginationState.pageIndex,- limit: paginationState.pageSize,- },- { enabled: props.scope === "project" },- );-- const orgAuditLogs = api.auditLogs.allByOrg.useQuery(- {- orgId: props.scope === "organization" ? props.orgId : "",- page: paginationState.pageIndex,- limit: paginationState.pageSize,- },- { enabled: props.scope === "organization" },- );-- const auditLogs = props.scope === "project" ? projectAuditLogs : orgAuditLogs;-- const tableId = props.scope === "project" ? "auditLogs" : "orgAuditLogs";- const [rowHeight, setRowHeight] = useRowHeightLocalStorage(tableId, "s");-- const columns: LangfuseColumnDef<AuditLogRow>[] = [- {- accessorKey: "createdAt",- header: "Time",- cell: (row) => {- const date = row.getValue() as Date;- return date.toLocaleString();- },- },- {- accessorKey: "actor",- header: "Actor",- headerTooltip: {- description: "The actor within Langfuse who performed the action.",- },- cell: (row) => {- const actor = row.getValue() as AuditLogRow["actor"];- if (actor?.type === "USER") {- const user = actor.body;- return (- <div className="flex items-center gap-2">- <Avatar- size="sm"- src={user?.image ?? undefined}- displayName={user?.name ?? user?.email ?? "User"}- />- <span- className={cn(- "text-sm",- !user?.name && "text-muted-foreground",- )}- >- {user?.name ?? user?.email ?? user.id}- </span>- </div>- );- }-- if (actor?.type === "API_KEY") {- const apiKey = actor.body;- return (- <div className="flex items-center gap-2">- <span className="text-sm">{apiKey?.publicKey ?? apiKey?.id}</span>- </div>- );- }-- return null;- },- },- createTextTableColumn<AuditLogRow>({- accessorKey: "resourceType",- header: "Resource Type",- }),- createTextTableColumn<AuditLogRow>({- accessorKey: "resourceId",- header: "Resource ID",- }),- createTextTableColumn<AuditLogRow>({- accessorKey: "action",- header: "Action",- }),- createIOTableColumn<AuditLogRow>({- accessorKey: "before",- header: "Before",- size: 300,- getCell: (value) => value || undefined,- singleLine: rowHeight === "s",- }),- createIOTableColumn<AuditLogRow>({- accessorKey: "after",- header: "After",- size: 300,- getCell: (value) => value || undefined,- singleLine: rowHeight === "s",- }),- ];-- return (- <>- <DataTableToolbar- tableName="audit-logs"- columns={columns}- rowHeight={rowHeight}- setRowHeight={setRowHeight}- actionButtons={- props.scope === "project" && hasBatchExportAccess- ? [- <BatchExportTableButton- key="audit-logs-export"- projectId={props.projectId}- tableName={BatchExportTableName.AuditLogs}- filterState={[]}- orderByState={{ column: "createdAt", order: "DESC" }}- />,- ]- : []- }- className="px-0"- />- <SettingsTableCard>- <DataTable- tableName={tableId}- columns={columns}- data={- auditLogs.isPending- ? { isLoading: true, isError: false }- : auditLogs.isError- ? {- isLoading: false,- isError: true,- error: auditLogs.error.message,- }- : {- isLoading: false,- isError: false,- data: safeExtract(auditLogs.data, "data", []),- }- }- pagination={{- totalCount: auditLogs.data?.totalCount ?? 0,- onChange: setPaginationState,- state: paginationState,- }}- rowHeight={rowHeight}- cellPadding="comfortable"- />- </SettingsTableCard>- </>- );-}diff --git a/web/src/ee/features/audit-log-viewer/AuditLogsTable/AuditLogsTable.stories.tsx b/web/src/ee/features/audit-log-viewer/AuditLogsTable/AuditLogsTable.stories.tsxnew file mode 100644index 0000000000..a75f9f3e30--- /dev/null+++ b/web/src/ee/features/audit-log-viewer/AuditLogsTable/AuditLogsTable.stories.tsx@@ -0,0 +1,113 @@+import { useState } from "react";+import { fn } from "storybook/test";++import preview from "../../../../../.storybook/preview";+import { AuditLogsTable, type AuditLogRow } from "./AuditLogsTable";++const meta = preview.meta({ component: AuditLogsTable });++const rows = [+ {+ id: "audit-log-1",+ createdAt: new Date("2026-09-01T12:00:00Z"),+ updatedAt: new Date("2026-09-01T12:00:00Z"),+ type: "USER",+ apiKeyId: null,+ userId: "user-1",+ orgId: "org-1",+ userOrgRole: "ADMIN",+ projectId: "project-1",+ userProjectRole: null,+ resourceType: "project",+ resourceId: "project-1",+ action: "update",+ before: JSON.stringify({+ name: "Old name",+ settings: {+ environment: "production",+ retention: "30 days",+ description: "Previous configuration for this project",+ notifications: { email: true, slack: false, webhook: false },+ access: { defaultRole: "viewer", allowedDomains: ["example.com"] },+ },+ }),+ after: JSON.stringify({+ name: "New name",+ settings: {+ environment: "production",+ retention: "90 days",+ description: "Updated configuration for this project",+ notifications: { email: true, slack: true, webhook: true },+ access: {+ defaultRole: "editor",+ allowedDomains: ["example.com", "langfuse.com"],+ },+ },+ }),+ actor: {+ type: "USER",+ body: {+ id: "user-1",+ name: "Ada Lovelace",+ email: "[email protected]",+ image: null,+ },+ },+ },+ {+ id: "audit-log-2",+ createdAt: new Date("2026-09-02T12:00:00Z"),+ updatedAt: new Date("2026-09-02T12:00:00Z"),+ type: "API_KEY",+ apiKeyId: "api-key-1",+ userId: null,+ orgId: "org-1",+ userOrgRole: null,+ projectId: "project-1",+ userProjectRole: null,+ resourceType: "prompt",+ resourceId: "prompt-1",+ action: "create",+ before: null,+ after: '{"name":"New prompt"}',+ actor: {+ type: "API_KEY",+ body: { id: "api-key-1", publicKey: "pk-example" },+ },+ },+] satisfies AuditLogRow[];++export const Default = meta.story({+ args: {+ tableName: "auditLogs",+ data: { status: "success", data: rows },+ pagination: {+ totalCount: rows.length,+ state: { pageIndex: 0, pageSize: 50 },+ onChange: fn(),+ },+ rowHeight: "s",+ onRowHeightChange: fn(),+ },+ render: (args) => {+ const [rowHeight, setRowHeight] = useState(args.rowHeight);++ return (+ <AuditLogsTable+ {...args}+ rowHeight={rowHeight}+ onRowHeightChange={(height) => {+ setRowHeight(height);+ args.onRowHeightChange(height);+ }}+ />+ );+ },+});++export const Loading = meta.story({+ args: {+ ...Default.input.args,+ data: { status: "loading" },+ },+});diff --git a/web/src/ee/features/audit-log-viewer/AuditLogsTable/AuditLogsTable.tsx b/web/src/ee/features/audit-log-viewer/AuditLogsTable/AuditLogsTable.tsxnew file mode 100644index 0000000000..2094d46a4a--- /dev/null+++ b/web/src/ee/features/audit-log-viewer/AuditLogsTable/AuditLogsTable.tsx@@ -0,0 +1,138 @@+import DiffViewer from "@/src/components/DiffViewer";+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";+import { type PaginationBarProps } from "@/src/components/design-system/PaginationBar/PaginationBar";+import { type TableProps } from "@/src/components/design-system/table/Table";+import { createActorTableColumn } from "@/src/components/design-system/table/columns/createActorTableColumn";+import { createBadgeTableColumn } from "@/src/components/design-system/table/columns/createBadgeTableColumn";+import { createButtonTableColumn } from "@/src/components/design-system/table/columns/createButtonTableColumn";+import { createDateTableColumn } from "@/src/components/design-system/table/columns/createDateTableColumn";+import { createIdTableColumn } from "@/src/components/design-system/table/columns/createIdTableColumn";+import { createIOTableColumn } from "@/src/components/design-system/table/columns/createIOTableColumn";+import {+ SettingsTable,+ type SettingsTableToolbarAction,+} from "@/src/components/SettingsTable/SettingsTable";+import { type RowHeight } from "@/src/components/table/data-table-row-height-switch";+import { type LangfuseColumnDef } from "@/src/components/table/types";+import { type RouterOutputs } from "@/src/utils/api";++export type AuditLogRow = RouterOutputs["auditLogs"]["all"]["data"][number];++function formatAuditLogValue(value: string | null) {+ if (value === null) return "(none)";++ try {+ return JSON.stringify(JSON.parse(value), null, 2);+ } catch {+ return value;+ }+}++export function AuditLogsTable({+ tableName,+ data,+ pagination,+ rowHeight,+ onRowHeightChange,+ toolbarActions,+}: {+ tableName: string;+ data: TableProps<AuditLogRow>["data"];+ pagination: PaginationBarProps;+ rowHeight: RowHeight;+ onRowHeightChange: (height: RowHeight) => void;+ toolbarActions?: SettingsTableToolbarAction[];+}) {+ return (+ <DialogController<AuditLogRow>+ renderDialog={({ state }) => (+ <Dialog title="Audit log changes" size="xxl">+ <Dialog.Body>+ <p>+ {state.action} · {state.resourceType} · {state.resourceId}+ </p>+ <DiffViewer+ oldString={formatAuditLogValue(state.before)}+ newString={formatAuditLogValue(state.after)}+ oldLabel="Before"+ newLabel="After"+ />+ </Dialog.Body>+ </Dialog>+ )}+ >+ {({ openDialog }) => {+ const columns: LangfuseColumnDef<AuditLogRow>[] = [+ createDateTableColumn<AuditLogRow>({+ accessorKey: "createdAt",+ header: "Time",+ }),+ createActorTableColumn<AuditLogRow>({+ accessorKey: "actor",+ header: "Actor",+ variant: "avatar",+ emptyValue: "",+ headerTooltip: {+ description:+ "The actor within Langfuse who performed the action.",+ },+ }),+ createBadgeTableColumn<AuditLogRow>({+ accessorKey: "resourceType",+ header: "Resource Type",+ }),+ createIdTableColumn<AuditLogRow>({+ accessorKey: "resourceId",+ header: "Resource ID",+ }),+ createBadgeTableColumn<AuditLogRow>({+ accessorKey: "action",+ header: "Action",+ }),+ createIOTableColumn<AuditLogRow>({+ accessorKey: "before",+ header: "Before",+ size: 300,+ getCell: (value) => value || undefined,+ singleLine: rowHeight === "s",+ }),+ createIOTableColumn<AuditLogRow>({+ accessorKey: "after",+ header: "After",+ size: 300,+ getCell: (value) => value || undefined,+ singleLine: rowHeight === "s",+ }),+ createButtonTableColumn<AuditLogRow, AuditLogRow["id"]>({+ accessorFn: (row) => row.id,+ id: "compare",+ header: "Compare",+ size: 96,+ enableHiding: false,+ getButton: ({ row }) => ({+ text: "Compare",+ disabled: !row.original.before && !row.original.after,+ onClick: () => openDialog(row.original),+ }),+ }),+ ];++ return (+ <SettingsTable+ tableName={tableName}+ columns={columns}+ columnVisibilityKey={`${tableName}ColumnVisibility`}+ columnOrderKey={`${tableName}ColumnOrder`}+ data={data}+ loadingRowCount={Math.min(pagination.state.pageSize, 8)}+ rowHeight={rowHeight}+ pagination={pagination}+ rowHeightControl={{ rowHeight, onRowHeightChange }}+ toolbarActions={toolbarActions}+ />+ );+ }}+ </DialogController>+ );+}diff --git a/web/src/ee/features/audit-log-viewer/AuditLogsTable/ConnectedAuditLogsTable.tsx b/web/src/ee/features/audit-log-viewer/AuditLogsTable/ConnectedAuditLogsTable.tsxnew file mode 100644index 0000000000..4cf24f3e48--- /dev/null+++ b/web/src/ee/features/audit-log-viewer/AuditLogsTable/ConnectedAuditLogsTable.tsx@@ -0,0 +1,128 @@+import { useMemo } from "react";+import { Download } from "lucide-react";+import { NumberParam, useQueryParams, withDefault } from "use-query-params";+import {+ BatchExportTableName,+ exportOptions,+ type BatchExportFileFormat,+} from "@langfuse/shared";++import { type AsyncTableData } from "@/src/components/design-system/table/Table";+import { useRowHeightLocalStorage } from "@/src/components/table/data-table-row-height-switch";+import { showSuccessToast } from "@/src/features/notifications";+import { useHasProjectAccess } from "@/src/features/rbac";+import { api } from "@/src/utils/api";+import { safeExtract } from "@/src/utils/map-utils";+import { AuditLogsTable, type AuditLogRow } from "./AuditLogsTable";++type AuditLogsTableProps =+ | { scope: "project"; projectId: string }+ | { scope: "organization"; orgId: string };++export function ConnectedAuditLogsTable(props: AuditLogsTableProps) {+ const hasBatchExportAccess = useHasProjectAccess({+ projectId: props.scope === "project" ? props.projectId : undefined,+ scope: "batchExports:create",+ });+ const [paginationState, setPaginationState] = useQueryParams({+ pageIndex: withDefault(NumberParam, 0),+ pageSize: withDefault(NumberParam, 50),+ });++ const projectAuditLogs = api.auditLogs.all.useQuery(+ {+ projectId: props.scope === "project" ? props.projectId : "",+ page: paginationState.pageIndex,+ limit: paginationState.pageSize,+ },+ { enabled: props.scope === "project" },+ );+ const orgAuditLogs = api.auditLogs.allByOrg.useQuery(+ {+ orgId: props.scope === "organization" ? props.orgId : "",+ page: paginationState.pageIndex,+ limit: paginationState.pageSize,+ },+ { enabled: props.scope === "organization" },+ );++ const auditLogs = props.scope === "project" ? projectAuditLogs : orgAuditLogs;+ const tableId = props.scope === "project" ? "auditLogs" : "orgAuditLogs";+ const [rowHeight, setRowHeight] = useRowHeightLocalStorage(tableId, "s");+ const createExport = api.batchExport.create.useMutation({+ onSuccess: (_data, variables) => {+ showSuccessToast({+ title: "Export queued",+ description: "You will receive an email when the export is ready.",+ duration: 10000,+ link: {+ href: `/project/${variables.projectId}/settings/exports`,+ text: "View exports",+ },+ });+ },+ });++ const toolbarActions =+ props.scope === "project" && hasBatchExportAccess+ ? [+ {+ id: "export",+ label: "Export",+ icon: <Download className="size-4" />,+ variant: "outline" as const,+ loading: createExport.isPending,+ dropdown: {+ title: "Export",+ description:+ "Note: Filters are not applied to audit log exports. All audit logs for this project will be exported.",+ disabled: createExport.isPending,+ items: (+ Object.keys(exportOptions) as BatchExportFileFormat[]+ ).map((format) => ({+ type: "item" as const,+ id: `export-${format}`,+ title: `as ${exportOptions[format].label}`,+ onClick: () =>+ createExport.mutate({+ projectId: props.projectId,+ name: `${new Date().toISOString()} - ${BatchExportTableName.AuditLogs} as ${format}`,+ format,+ query: {+ tableName: BatchExportTableName.AuditLogs,+ filter: [],+ orderBy: { column: "createdAt", order: "DESC" },+ },+ }),+ })),+ },+ },+ ]+ : undefined;++ const data = useMemo<AsyncTableData<AuditLogRow[]>>(() => {+ if (auditLogs.isPending) return { status: "loading" };+ if (auditLogs.isError) {+ return { status: "error", error: auditLogs.error.message };+ }+ return {+ status: "success",+ data: safeExtract(auditLogs.data, "data", []),+ };+ }, [auditLogs.data, auditLogs.error, auditLogs.isError, auditLogs.isPending]);++ return (+ <AuditLogsTable+ tableName={tableId}+ data={data}+ rowHeight={rowHeight}+ onRowHeightChange={setRowHeight}+ toolbarActions={toolbarActions}+ pagination={{+ totalCount: auditLogs.data?.totalCount ?? 0,+ onChange: setPaginationState,+ state: paginationState,+ }}+ />+ );+}diff --git a/web/src/ee/features/audit-log-viewer/OrgAuditLogsSettingsPage.tsx b/web/src/ee/features/audit-log-viewer/OrgAuditLogsSettingsPage.tsxindex d7adc5475a..105a0d0465 100644--- a/web/src/ee/features/audit-log-viewer/OrgAuditLogsSettingsPage.tsx+++ b/web/src/ee/features/audit-log-viewer/OrgAuditLogsSettingsPage.tsx@@ -1,7 +1,7 @@/* eslint-disable no-nested-ternary */import Header from "@/src/components/layouts/header";import { Alert } from "@/src/components/design-system/Alert/Alert";-import { AuditLogsTable } from "@/src/ee/features/audit-log-viewer/AuditLogsTable";+import { ConnectedAuditLogsTable } from "@/src/ee/features/audit-log-viewer/AuditLogsTable/ConnectedAuditLogsTable";import { useHasEntitlement } from "@/src/features/entitlements";import { useHasOrganizationAccess } from "@/src/features/rbac";@@ -25,7 +25,7 @@ export function OrgAuditLogsSettingsPage(props: { orgId: string }) {</Alert.Description></Alert>) : (- <AuditLogsTable scope="organization" orgId={props.orgId} />+ <ConnectedAuditLogsTable scope="organization" orgId={props.orgId} />);return (