"use client"; import React, { useState } from "react"; import { ColumnDef, Row } from "@tanstack/react-table"; import { DataTable } from "./view_logs/table"; import { Select, SelectItem } from "@tremor/react" import { Button } from "@tremor/react" import KeyInfoView from "./key_info_view"; import { Tooltip } from "antd"; import { Team, KeyResponse } from "./key_team_helpers/key_list"; interface AllKeysTableProps { keys: KeyResponse[]; isLoading?: boolean; pagination: { currentPage: number; totalPages: number; totalCount: number; }; onPageChange: (page: number) => void; pageSize?: number; teams: Team[] | null; selectedTeam: Team | null; setSelectedTeam: (team: Team | null) => void; accessToken: string | null; userID: string | null; userRole: string | null; } // Define columns similar to our logs table function KeyViewer({ row }: { row: Row }) { return (

Key Details

Key Alias: {row.original.key_alias || "Not Set"}

Secret Key: {row.original.key_name}

Created:{" "} {new Date(row.original.created_at).toLocaleString()}

Expires:{" "} {row.original.expires ? new Date(row.original.expires).toLocaleString() : "Never"}

Spend: {Number(row.original.spend).toFixed(4)}

Budget:{" "} {row.original.max_budget !== null ? row.original.max_budget : "Unlimited"}

Budget Reset:{" "} {row.original.budget_reset_at ? new Date(row.original.budget_reset_at).toLocaleString() : "Never"}

Models:{" "} {row.original.models && row.original.models.length > 0 ? row.original.models.join(", ") : "-"}

Rate Limits: TPM:{" "} {row.original.tpm_limit !== null ? row.original.tpm_limit : "Unlimited"} , RPM:{" "} {row.original.rpm_limit !== null ? row.original.rpm_limit : "Unlimited"}

Metadata:

            {JSON.stringify(row.original.metadata, null, 2)}
          
); } const TeamFilter = ({ teams, selectedTeam, setSelectedTeam }: { teams: Team[] | null; selectedTeam: Team | null; setSelectedTeam: (team: Team | null) => void; }) => { const handleTeamChange = (value: string) => { const team = teams?.find(t => t.team_id === value); setSelectedTeam(team || null); }; return (
Where Team is
); }; /** * AllKeysTable – a new table for keys that mimics the table styling used in view_logs. * The team selector and filtering have been removed so that all keys are shown. */ export function AllKeysTable({ keys, isLoading = false, pagination, onPageChange, pageSize = 50, teams, selectedTeam, setSelectedTeam, accessToken, userID, userRole }: AllKeysTableProps) { const [selectedKeyId, setSelectedKeyId] = useState(null); const columns: ColumnDef[] = [ { id: "expander", header: () => null, cell: ({ row }) => row.getCanExpand() ? ( ) : null, }, { header: "Key ID", accessorKey: "token", cell: (info) => (
), }, { header: "Organization", accessorKey: "organization_id", cell: (info) => info.getValue() ? info.renderValue() : "Not Set", }, { header: "Team ID", accessorKey: "team_id", cell: (info) => info.getValue() ? info.renderValue() : "Not Set", }, { header: "Key Alias", accessorKey: "key_alias", cell: (info) => info.getValue() ? info.renderValue() : "Not Set", }, { header: "Secret Key", accessorKey: "key_name", cell: (info) => {info.getValue() as string}, }, { header: "Created", accessorKey: "created_at", cell: (info) => { const value = info.getValue(); return value ? new Date(value as string).toLocaleDateString() : "-"; }, }, { header: "Expires", accessorKey: "expires", cell: (info) => { const value = info.getValue(); return value ? new Date(value as string).toLocaleDateString() : "Never"; }, }, { header: "Spend (USD)", accessorKey: "spend", cell: (info) => Number(info.getValue()).toFixed(4), }, { header: "Budget (USD)", accessorKey: "max_budget", cell: (info) => info.getValue() !== null && info.getValue() !== undefined ? info.getValue() : "Unlimited", }, { header: "Budget Reset", accessorKey: "budget_reset_at", cell: (info) => { const value = info.getValue(); return value ? new Date(value as string).toLocaleString() : "Never"; }, }, { header: "Models", accessorKey: "models", cell: (info) => { const models = info.getValue() as string[]; return (
{models && models.length > 0 ? ( models.map((model, index) => ( {model} )) ) : ( "-" )}
); }, }, { header: "Rate Limits", cell: ({ row }) => { const key = row.original; return (
TPM: {key.tpm_limit !== null ? key.tpm_limit : "Unlimited"}
RPM: {key.rpm_limit !== null ? key.rpm_limit : "Unlimited"}
); }, }, ]; return (
{selectedKeyId ? ( setSelectedKeyId(null)} keyData={keys.find(k => k.token === selectedKeyId)} accessToken={accessToken} userID={userID} userRole={userRole} teams={teams} /> ) : (
Showing {isLoading ? "..." : `${(pagination.currentPage - 1) * pageSize + 1} - ${Math.min(pagination.currentPage * pageSize, pagination.totalCount)}`} of {isLoading ? "..." : pagination.totalCount} results
Page {isLoading ? "..." : pagination.currentPage} of {isLoading ? "..." : pagination.totalPages}
col.id !== 'expander')} data={keys} isLoading={isLoading} getRowCanExpand={() => false} renderSubComponent={() => <>} />
)}
); }