Skip to content

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

refactor(web): Migrate score configs table to design-system components (#17789)

Ben Bachembfb9e0f4a62e
diff --git a/web/src/features/score-configs/ScoreConfigsTable.tsx b/web/src/features/score-configs/ScoreConfigsTable.tsx
deleted file mode 100644
index 0f18df59d9..0000000000
--- a/web/src/features/score-configs/ScoreConfigsTable.tsx
+++ /dev/null
@@ -1,343 +0,0 @@
-/* eslint-disable no-nested-ternary */
-import React from "react";
-import { useRowHeightLocalStorage } from "@/src/components/table/data-table-row-height-switch";
-import {
- useColumnVisibility,
- useColumnOrder,
-} from "@/src/features/column-visibility";
-import { api } from "@/src/utils/api";
-import { type LangfuseColumnDef } from "@/src/components/table/types";
-import { createIOTableColumn } from "@/src/components/design-system/table/columns/createIOTableColumn";
-import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
-import { DataTable } from "@/src/components/table/data-table";
-import {
- type ScoreConfigDataType,
- type Prisma,
- type ScoreConfigCategoryDomain,
-} from "@langfuse/shared";
-import { usePaginationState } from "@/src/hooks/usePaginationState";
-import {
- isBooleanDataType,
- isCategoricalDataType,
- isNumericDataType,
-} from "@/src/features/scores";
-import { Archive, Edit, MoreVertical, PlusIcon } from "lucide-react";
-import { Button } from "@/src/components/ui/button";
-import { SettingsTableCard } from "@/src/components/layouts/settings-table-card";
-import { createDateTableColumn } from "@/src/components/design-system/table/columns/createDateTableColumn";
-import { createIdTableColumn } from "@/src/components/design-system/table/columns/createIdTableColumn";
-import { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";
-import { useHasProjectAccess } from "@/src/features/rbac";
-import {
- DropdownMenu,
- DropdownMenuTrigger,
- DropdownMenuContent,
- DropdownMenuItem,
-} from "@/src/components/ui/dropdown-menu";
-import {
- ArchiveScoreConfigDialogController,
- type ArchiveScoreConfigState,
-} from "@/src/features/score-configs/components/ArchiveScoreConfigDialogController";
-import {
- CreateScoreConfigDialogController,
- EditScoreConfigDialogController,
-} from "@/src/features/score-configs/components/UpsertScoreConfigDialogController";
-import { type UpdateConfig } from "@/src/features/score-configs/lib/upsertFormTypes";
-
-type ScoreConfigTableRow = {
- id: string;
- name: string;
- dataType: ScoreConfigDataType;
- createdAt: Date;
- updatedAt: Date;
- range: {
- maxValue?: number | null;
- minValue?: number | null;
- categories?: ScoreConfigCategoryDomain[] | null;
- };
- description?: string | null;
- isArchived: boolean;
-};
-
-function getConfigRange(
- originalRow: ScoreConfigTableRow,
-): undefined | Prisma.JsonValue {
- const { range, dataType } = originalRow;
-
- if (isNumericDataType(dataType)) {
- return {
- Minimum: range.minValue ?? "-∞",
- Maximum: range.maxValue ?? "∞",
- };
- }
-
- if (isCategoricalDataType(dataType) || isBooleanDataType(dataType)) {
- const configCategories = range.categories ?? [];
-
- return configCategories.reduce(
- (acc, category) => {
- acc[category.value] = category.label;
- return acc;
- },
- {} as Record<number, string>,
- );
- }
-}
-
-export function ScoreConfigsTable({ projectId }: { projectId: string }) {
- return (
- <EditScoreConfigDialogController projectId={projectId}>
- {(editControl) => (
- <ArchiveScoreConfigDialogController projectId={projectId}>
- {(archiveControl) => (
- <ScoreConfigsTableContent
- projectId={projectId}
- editControl={editControl}
- archiveControl={archiveControl}
- />
- )}
- </ArchiveScoreConfigDialogController>
- )}
- </EditScoreConfigDialogController>
- );
-}
-
-function ScoreConfigsTableContent({
- projectId,
- editControl,
- archiveControl,
-}: {
- projectId: string;
- editControl: {
- disabled: { reason: string } | undefined;
- openDialog: (config: UpdateConfig) => void;
- };
- archiveControl: {
- disabled: { reason: string } | undefined;
- openDialog: (config: ArchiveScoreConfigState) => void;
- };
-}) {
- const [paginationState, setPaginationState] = usePaginationState(0, 50, {
- page: "pageIndex",
- limit: "pageSize",
- });
-
- const hasAccess = useHasProjectAccess({
- projectId,
- scope: "scoreConfigs:CUD",
- });
-
- const [rowHeight, setRowHeight] = useRowHeightLocalStorage(
- "scoreConfigs",
- "s",
- );
-
- const configs = api.scoreConfigs.all.useQuery(
- {
- projectId,
- page: paginationState.pageIndex,
- limit: paginationState.pageSize,
- },
- { enabled: hasAccess },
- );
-
- const totalCount = configs.data?.totalCount ?? null;
-
- const columns: LangfuseColumnDef<ScoreConfigTableRow>[] = [
- createTextTableColumn<ScoreConfigTableRow>({
- accessorKey: "name",
- header: "Name",
- enableHiding: true,
- }),
- createTextTableColumn<ScoreConfigTableRow>({
- accessorKey: "dataType",
- header: "Data Type",
- size: 80,
- enableHiding: true,
- }),
- createIOTableColumn<ScoreConfigTableRow, Prisma.JsonValue>({
- id: "range",
- accessorFn: getConfigRange,
- header: "Range",
- enableHiding: true,
- size: 300,
- getCell: (value) => value || undefined,
- singleLine: rowHeight === "s",
- }),
- createIOTableColumn<ScoreConfigTableRow>({
- accessorKey: "description",
- header: "Description",
- enableHiding: true,
- getCell: (value) => value || undefined,
- singleLine: rowHeight === "s",
- }),
- createIdTableColumn<ScoreConfigTableRow>({
- accessorKey: "id",
- header: "Config ID",
- enableHiding: true,
- defaultHidden: true,
- }),
- createDateTableColumn<ScoreConfigTableRow>({
- accessorKey: "createdAt",
- header: "Created At",
- enableHiding: true,
- defaultHidden: true,
- }),
- createTextTableColumn<ScoreConfigTableRow, boolean>({
- accessorKey: "isArchived",
- header: "Status",
- size: 80,
- enableHiding: true,
- mapValue: (isArchived) => (isArchived ? "Archived" : "Active"),
- }),
- {
- accessorKey: "action",
- header: "Action",
- size: 70,
- isFixedPosition: true,
- enableHiding: true,
- cell: ({ row }) => {
- const { id: configId, isArchived, name } = row.original;
-
- return (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost">
- <MoreVertical className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuItem
- aria-label="edit"
- disabled={editControl.disabled !== undefined}
- title={editControl.disabled?.reason}
- onSelect={() =>
- editControl.openDialog({
- id: configId,
- name,
- dataType: row.original.dataType,
- minValue: row.original.range.minValue ?? undefined,
- maxValue: row.original.range.maxValue ?? undefined,
- description: row.original.description ?? undefined,
- categories: row.original.range.categories?.length
- ? row.original.range.categories
- : undefined,
- })
- }
- >
- <Edit className="mr-2 h-4 w-4" />
- Edit
- </DropdownMenuItem>
- <DropdownMenuItem
- disabled={archiveControl.disabled !== undefined}
- title={archiveControl.disabled?.reason}
- onSelect={() =>
- archiveControl.openDialog({
- id: configId,
- isArchived,
- name,
- })
- }
- >
- <Archive className="mr-2 h-4 w-4" />
- {isArchived ? "Restore" : "Archive"}
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- );
- },
- },
- ];
-
- const [columnVisibility, setColumnVisibility] =
- useColumnVisibility<ScoreConfigTableRow>(
- "scoreConfigsColumnVisibility",
- columns,
- );
-
- const [columnOrder, setColumnOrder] = useColumnOrder<ScoreConfigTableRow>(
- "scoreConfigsColumnOrder",
- columns,
- );
-
- return (
- <>
- <DataTableToolbar
- tableName="score-configs"
- columns={columns}
- columnVisibility={columnVisibility}
- setColumnVisibility={setColumnVisibility}
- columnOrder={columnOrder}
- setColumnOrder={setColumnOrder}
- rowHeight={rowHeight}
- setRowHeight={setRowHeight}
- actionButtons={
- <CreateScoreConfigDialogController projectId={projectId}>
- {({ disabled, isSubmitting, openDialog }) => (
- <Button
- variant="secondary"
- disabled={disabled !== undefined}
- loading={isSubmitting}
- title={disabled?.reason}
- onClick={openDialog}
- >
- <PlusIcon
- className="mr-1.5 -ml-0.5 h-4 w-4"
- aria-hidden="true"
- />
- Add new score config
- </Button>
- )}
- </CreateScoreConfigDialogController>
- }
- className="px-0"
- />
- <SettingsTableCard>
- <DataTable
- tableName="scoreConfigs"
- columns={columns}
- data={
- configs.isPending
- ? { isLoading: true, isError: false }
- : configs.isError
- ? {
- isLoading: false,
- isError: true,
- error: configs.error.message,
- }
- : {
- isLoading: false,
- isError: false,
- data: configs.data?.configs.map((config) => ({
- id: config.id,
- name: config.name,
- dataType: config.dataType,
- description: config.description,
- createdAt: config.createdAt,
- updatedAt: config.updatedAt,
- range: {
- maxValue: config.maxValue,
- minValue: config.minValue,
- categories: config.categories,
- },
- isArchived: config.isArchived,
- })),
- }
- }
- pagination={{
- totalCount,
- onChange: setPaginationState,
- state: paginationState,
- }}
- columnVisibility={columnVisibility}
- onColumnVisibilityChange={setColumnVisibility}
- columnOrder={columnOrder}
- onColumnOrderChange={setColumnOrder}
- rowHeight={rowHeight}
- cellPadding="comfortable"
- className="gap-2"
- />
- </SettingsTableCard>
- </>
- );
-}
diff --git a/web/src/features/score-configs/ScoreConfigsTable/ConnectedScoreConfigsTable.tsx b/web/src/features/score-configs/ScoreConfigsTable/ConnectedScoreConfigsTable.tsx
new file mode 100644
index 0000000000..f877d0b1c6
--- /dev/null
+++ b/web/src/features/score-configs/ScoreConfigsTable/ConnectedScoreConfigsTable.tsx
@@ -0,0 +1,117 @@
+import { useMemo } from "react";
+
+import { type AsyncTableData } from "@/src/components/design-system/table/Table";
+import { ArchiveScoreConfigDialogController } from "@/src/features/score-configs/components/ArchiveScoreConfigDialogController";
+import {
+ CreateScoreConfigDialogController,
+ EditScoreConfigDialogController,
+} from "@/src/features/score-configs/components/UpsertScoreConfigDialogController";
+import {
+ ScoreConfigsTable,
+ type ScoreConfigTableRow,
+} from "@/src/features/score-configs/ScoreConfigsTable/ScoreConfigsTable";
+import { useHasProjectAccess } from "@/src/features/rbac";
+import { usePaginationState } from "@/src/hooks/usePaginationState";
+import { api } from "@/src/utils/api";
+
+export function ConnectedScoreConfigsTable({
+ projectId,
+}: {
+ projectId: string;
+}) {
+ const [paginationState, setPaginationState] = usePaginationState(0, 50, {
+ page: "pageIndex",
+ limit: "pageSize",
+ });
+
+ const hasAccess = useHasProjectAccess({
+ projectId,
+ scope: "scoreConfigs:CUD",
+ });
+
+ const configs = api.scoreConfigs.all.useQuery(
+ {
+ projectId,
+ page: paginationState.pageIndex,
+ limit: paginationState.pageSize,
+ },
+ { enabled: hasAccess },
+ );
+
+ const tableData = useMemo<AsyncTableData<ScoreConfigTableRow[]>>(() => {
+ if (configs.isPending) return { status: "loading" };
+ if (configs.isError)
+ return { status: "error", error: configs.error.message };
+
+ return {
+ status: "success",
+ data:
+ configs.data?.configs.map((config) => ({
+ id: config.id,
+ name: config.name,
+ dataType: config.dataType,
+ description: config.description,
+ createdAt: config.createdAt,
+ updatedAt: config.updatedAt,
+ range: {
+ maxValue: config.maxValue,
+ minValue: config.minValue,
+ categories: config.categories,
+ },
+ isArchived: config.isArchived,
+ })) ?? [],
+ };
+ }, [
+ configs.data?.configs,
+ configs.error?.message,
+ configs.isError,
+ configs.isPending,
+ ]);
+
+ return (
+ <EditScoreConfigDialogController projectId={projectId}>
+ {(editControl) => (
+ <ArchiveScoreConfigDialogController projectId={projectId}>
+ {(archiveControl) => (
+ <CreateScoreConfigDialogController projectId={projectId}>
+ {(createControl) => (
+ <ScoreConfigsTable
+ data={tableData}
+ pagination={{
+ totalCount: configs.data?.totalCount ?? null,
+ onChange: setPaginationState,
+ state: paginationState,
+ }}
+ createAction={{
+ disabled: createControl.disabled,
+ loading: createControl.isSubmitting,
+ onClick: createControl.openDialog,
+ }}
+ editAction={{
+ disabled: editControl.disabled,
+ openDialog: (config) =>
+ editControl.openDialog({
+ id: config.id,
+ name: config.name,
+ dataType: config.dataType,
+ minValue: config.range.minValue ?? undefined,
+ maxValue: config.range.maxValue ?? undefined,
+ description: config.description ?? undefined,
+ categories: config.range.categories?.length
+ ? config.range.categories
+ : undefined,
+ }),
+ }}
+ archiveAction={{
+ disabled: archiveControl.disabled,
+ openDialog: (config) => archiveControl.openDialog(config),
+ }}
+ />
+ )}
+ </CreateScoreConfigDialogController>
+ )}
+ </ArchiveScoreConfigDialogController>
+ )}
+ </EditScoreConfigDialogController>
+ );
+}
diff --git a/web/src/features/score-configs/ScoreConfigsTable/ScoreConfigsTable.stories.tsx b/web/src/features/score-configs/ScoreConfigsTable/ScoreConfigsTable.stories.tsx
new file mode 100644
index 0000000000..928cb17ea3
--- /dev/null
+++ b/web/src/features/score-configs/ScoreConfigsTable/ScoreConfigsTable.stories.tsx
@@ -0,0 +1,87 @@
+import { fn } from "storybook/test";
+
+import preview from "../../../../.storybook/preview";
+import { ScoreConfigsTable } from "./ScoreConfigsTable";
+
+const actions = {
+ createAction: {
+ disabled: undefined,
+ loading: false,
+ onClick: fn(),
+ },
+ editAction: {
+ disabled: undefined,
+ openDialog: fn(),
+ },
+ archiveAction: {
+ disabled: undefined,
+ openDialog: fn(),
+ },
+ pagination: {
+ totalCount: 2,
+ state: { pageIndex: 0, pageSize: 50 },
+ onChange: fn(),
+ },
+};
+
+const meta = preview.meta({ component: ScoreConfigsTable });
+
+export const Default = meta.story({
+ args: {
+ ...actions,
+ data: {
+ status: "success",
+ data: [
+ {
+ id: "config-1",
+ name: "Correctness",
+ dataType: "NUMERIC",
+ createdAt: new Date("2026-09-01"),
+ updatedAt: new Date("2026-09-01"),
+ range: { minValue: 0, maxValue: 1 },
+ description: "Measures whether the response is correct",
+ isArchived: false,
+ },
+ {
+ id: "config-2",
+ name: "Sentiment",
+ dataType: "CATEGORICAL",
+ createdAt: new Date("2026-09-02"),
+ updatedAt: new Date("2026-09-02"),
+ range: {
+ categories: [
+ { value: 0, label: "Negative" },
+ { value: 1, label: "Positive" },
+ ],
+ },
+ description: null,
+ isArchived: true,
+ },
+ ],
+ },
+ },
+});
+
+export const Loading = meta.story({
+ args: {
+ ...actions,
+ data: { status: "loading" },
+ pagination: { ...actions.pagination, totalCount: null },
+ },
+});
+
+export const Empty = meta.story({
+ args: {
+ ...actions,
+ data: { status: "success", data: [] },
+ pagination: { ...actions.pagination, totalCount: 0 },
+ },
+});
+
+export const Error = meta.story({
+ args: {
+ ...actions,
+ data: { status: "error", error: "Failed to load score configs" },
+ pagination: { ...actions.pagination, totalCount: null },
+ },
+});
diff --git a/web/src/features/score-configs/ScoreConfigsTable/ScoreConfigsTable.tsx b/web/src/features/score-configs/ScoreConfigsTable/ScoreConfigsTable.tsx
new file mode 100644
index 0000000000..1897970266
--- /dev/null
+++ b/web/src/features/score-configs/ScoreConfigsTable/ScoreConfigsTable.tsx
@@ -0,0 +1,196 @@
+import { useCallback, useMemo } from "react";
+import { Archive, Edit, PlusIcon } from "lucide-react";
+import {
+ type Prisma,
+ type ScoreConfigCategoryDomain,
+ type ScoreConfigDataType,
+} from "@langfuse/shared";
+
+import { type PaginationBarProps } from "@/src/components/design-system/PaginationBar/PaginationBar";
+import {
+ type AsyncTableData,
+ type TableProps,
+} from "@/src/components/design-system/table/Table";
+import { createBadgeTableColumn } from "@/src/components/design-system/table/columns/createBadgeTableColumn";
+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 { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";
+import {
+ SettingsTable,
+ type SettingsTableProps,
+} from "@/src/components/SettingsTable/SettingsTable";
+import { type LangfuseColumnDef } from "@/src/components/table/types";
+import {
+ isBooleanDataType,
+ isCategoricalDataType,
+ isNumericDataType,
+} from "@/src/features/scores";
+
+export type ScoreConfigTableRow = {
+ id: string;
+ name: string;
+ dataType: ScoreConfigDataType;
+ createdAt: Date;
+ updatedAt: Date;
+ range: {
+ maxValue?: number | null;
+ minValue?: number | null;
+ categories?: ScoreConfigCategoryDomain[] | null;
+ };
+ description?: string | null;
+ isArchived: boolean;
+};
+
+function getConfigRange(
+ originalRow: ScoreConfigTableRow,
+): undefined | Prisma.JsonValue {
+ const { range, dataType } = originalRow;
+
+ if (isNumericDataType(dataType)) {
+ return {
+ Minimum: range.minValue ?? "-∞",
+ Maximum: range.maxValue ?? "∞",
+ };
+ }
+
+ if (isCategoricalDataType(dataType) || isBooleanDataType(dataType)) {
+ const configCategories = range.categories ?? [];
+
+ return configCategories.reduce(
+ (acc, category) => {
+ acc[category.value] = category.label;
+ return acc;
+ },
+ {} as Record<number, string>,
+ );
+ }
+}
+
+export function ScoreConfigsTable({
+ data,
+ pagination,
+ createAction,
+ editAction,
+ archiveAction,
+}: {
+ data: AsyncTableData<ScoreConfigTableRow[]>;
+ pagination: PaginationBarProps;
+ createAction: {
+ disabled: { reason: string } | undefined;
+ loading: boolean;
+ onClick: () => void;
+ };
+ editAction: {
+ disabled: { reason: string } | undefined;
+ openDialog: (config: ScoreConfigTableRow) => void;
+ };
+ archiveAction: {
+ disabled: { reason: string } | undefined;
+ openDialog: (config: ScoreConfigTableRow) => void;
+ };
+}) {
+ const columns = useMemo<LangfuseColumnDef<ScoreConfigTableRow>[]>(
+ () => [
+ createTextTableColumn<ScoreConfigTableRow>({
+ accessorKey: "name",
+ header: "Name",
+ enableHiding: true,
+ }),
+ createBadgeTableColumn<ScoreConfigTableRow>({
+ accessorKey: "dataType",
+ header: "Data Type",
+ size: 80,
+ enableHiding: true,
+ }),
+ createIOTableColumn<ScoreConfigTableRow, Prisma.JsonValue>({
+ id: "range",
+ accessorFn: getConfigRange,
+ header: "Range",
+ enableHiding: true,
+ size: 300,
+ getCell: (value) => value || undefined,
+ singleLine: true,
+ }),
+ createIOTableColumn<ScoreConfigTableRow>({
+ accessorKey: "description",
+ header: "Description",
+ enableHiding: true,
+ getCell: (value) => value || undefined,
+ singleLine: true,
+ }),
+ createIdTableColumn<ScoreConfigTableRow>({
+ accessorKey: "id",
+ header: "Config ID",
+ enableHiding: true,
+ defaultHidden: true,
+ }),
+ createDateTableColumn<ScoreConfigTableRow>({
+ accessorKey: "createdAt",
+ header: "Created At",
+ enableHiding: true,
+ defaultHidden: true,
+ }),
+ createBadgeTableColumn<ScoreConfigTableRow>({
+ id: "status",
+ accessorFn: (config) => (config.isArchived ? "Archived" : "Active"),
+ header: "Status",
+ size: 80,
+ enableHiding: true,
+ }),
+ ],
+ [],
+ );
+
+ const actions = useCallback<
+ NonNullable<TableProps<ScoreConfigTableRow>["actions"]>
+ >(
+ (config) => [
+ {
+ id: "edit",
+ type: "item",
+ title: "Edit",
+ icon: Edit,
+ disabled: editAction.disabled,
+ onClick: () => editAction.openDialog(config),
+ },
+ {
+ id: "archive",
+ type: "item",
+ title: config.isArchived ? "Restore" : "Archive",
+ icon: Archive,
+ variant: config.isArchived ? undefined : "destructive",
+ disabled: archiveAction.disabled,
+ onClick: () => archiveAction.openDialog(config),
+ },
+ ],
+ [archiveAction, editAction],
+ );
+
+ const toolbarActions: SettingsTableProps<ScoreConfigTableRow>["toolbarActions"] =
+ [
+ {
+ id: "add-score-config",
+ label: "Add new score config",
+ variant: "secondary",
+ icon: <PlusIcon className="size-4" aria-hidden="true" />,
+ disabled: createAction.disabled !== undefined,
+ loading: createAction.loading,
+ title: createAction.disabled?.reason,
+ onClick: createAction.onClick,
+ },
+ ];
+
+ return (
+ <SettingsTable
+ tableName="score configs"
+ columns={columns}
+ actions={actions}
+ data={data}
+ pagination={pagination}
+ columnVisibilityKey="scoreConfigsColumnVisibility"
+ columnOrderKey="scoreConfigsColumnOrder"
+ toolbarActions={toolbarActions}
+ />
+ );
+}
diff --git a/web/src/features/score-configs/components/ScoreConfigSettings.tsx b/web/src/features/score-configs/components/ScoreConfigSettings.tsx
index bcb9a3cb49..4c783c473b 100644
--- a/web/src/features/score-configs/components/ScoreConfigSettings.tsx
+++ b/web/src/features/score-configs/components/ScoreConfigSettings.tsx
@@ -1,5 +1,5 @@
import Header from "@/src/components/layouts/header";
-import { ScoreConfigsTable } from "@/src/features/score-configs/ScoreConfigsTable";
+import { ConnectedScoreConfigsTable } from "@/src/features/score-configs/ScoreConfigsTable/ConnectedScoreConfigsTable";
export function ScoreConfigSettings({ projectId }: { projectId: string }) {
return (
@@ -17,7 +17,7 @@ export function ScoreConfigSettings({ projectId }: { projectId: string }) {
</a>{" "}
in your project. Please note that all score configs are immutable.
</p>
- <ScoreConfigsTable projectId={projectId} />
+ <ConnectedScoreConfigsTable projectId={projectId} />
</div>
);
}