- }
- onClick={() => onEditClick(record)}
- />
+ );
+ },
+ },
+ {
+ header: "Description",
+ accessorKey: "description",
+ cell: ({ row }) => {
+ const policy = row.original;
+ return (
+
+
+ {policy.description || "-"}
+
+
+ );
+ },
+ },
+ {
+ header: "Inherits From",
+ accessorKey: "inherit",
+ cell: ({ row }) => {
+ const policy = row.original;
+ return policy.inherit ? (
+
+ {policy.inherit}
+
+ ) : (
+ -
+ );
+ },
+ },
+ {
+ header: "Guardrails (Add)",
+ accessorKey: "guardrails_add",
+ cell: ({ row }) => {
+ const policy = row.original;
+ const guardrails = policy.guardrails_add || [];
+ if (guardrails.length === 0) {
+ return -;
+ }
+ return (
+
+ {guardrails.slice(0, 2).map((g, i) => (
+
+ {g}
+
+ ))}
+ {guardrails.length > 2 && (
+
+ +{guardrails.length - 2}
-
- }
- onClick={() =>
- onDeleteClick(record.policy_id, record.policy_name)
- }
- />
+ )}
+
+ );
+ },
+ },
+ {
+ header: "Guardrails (Remove)",
+ accessorKey: "guardrails_remove",
+ cell: ({ row }) => {
+ const policy = row.original;
+ const guardrails = policy.guardrails_remove || [];
+ if (guardrails.length === 0) {
+ return -;
+ }
+ return (
+
+ {guardrails.slice(0, 2).map((g, i) => (
+
+ {g}
+
+ ))}
+ {guardrails.length > 2 && (
+
+ +{guardrails.length - 2}
- >
- )}
-
- ),
+ )}
+
+ );
+ },
+ },
+ {
+ header: "Model Condition",
+ accessorKey: "condition",
+ cell: ({ row }) => {
+ const policy = row.original;
+ const modelCondition = policy.condition?.model;
+ if (!modelCondition) {
+ return -;
+ }
+ return (
+
+
+ {typeof modelCondition === "string"
+ ? modelCondition.length > 20
+ ? modelCondition.slice(0, 20) + "..."
+ : modelCondition
+ : "Multiple"}
+
+
+ );
+ },
+ },
+ {
+ header: "Created At",
+ accessorKey: "created_at",
+ cell: ({ row }) => {
+ const policy = row.original;
+ return (
+
+ {formatDate(policy.created_at)}
+
+ );
+ },
+ },
+ {
+ id: "actions",
+ header: "Actions",
+ cell: ({ row }) => {
+ const policy = row.original;
+ return (
+
+ {isAdmin && (
+ <>
+
+ onEditClick(policy)}
+ className="cursor-pointer hover:text-blue-500"
+ />
+
+
+
+ policy.policy_id &&
+ onDeleteClick(policy.policy_id, policy.policy_name || "Unnamed Policy")
+ }
+ className="cursor-pointer hover:text-red-500"
+ />
+
+ >
+ )}
+
+ );
+ },
},
];
+ const table = useReactTable({
+ data: policies,
+ columns,
+ state: {
+ sorting,
+ },
+ onSortingChange: setSorting,
+ getCoreRowModel: getCoreRowModel(),
+ getSortedRowModel: getSortedRowModel(),
+ enableSorting: true,
+ });
+
return (
-
- `${range[0]}-${range[1]} of ${total} policies`,
- }}
- />
+
+
+
+
+ {table.getHeaderGroups().map((headerGroup) => (
+
+ {headerGroup.headers.map((header) => (
+
+
+
+ {header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
+
+ {header.id !== "actions" && (
+
+ {header.column.getIsSorted() ? (
+ {
+ asc: ,
+ desc: ,
+ }[header.column.getIsSorted() as string]
+ ) : (
+
+ )}
+
+ )}
+
+
+ ))}
+
+ ))}
+
+
+ {isLoading ? (
+
+
+
+
+
+ ) : policies.length > 0 ? (
+ table.getRowModel().rows.map((row) => (
+
+ {row.getVisibleCells().map((cell) => (
+
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
+
+ ))}
+
+ ))
+ ) : (
+
+
+
+
+
+ )}
+
+
+
+
);
};