Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
import { useCallback, useMemo } from "react";
import type { ColumnDef } from "@tanstack/react-table";
import { DataGrid, useDataGrid } from "@app/components/v3/generic/DataGrid";
import { Spinner } from "@app/components/v3/generic/Spinner";
import type { FieldInfo } from "../data-explorer-types";
type QueryResult = {
rows: Record<string, unknown>[];
fields: FieldInfo[];
rowCount: number | null;
isTruncated: boolean;
command: string;
executionTimeMs: number;
};
type Props = {
result: QueryResult | null;
error: string | null;
isRunning: boolean;
};
type RowData = Record<string, unknown>;
function buildColumns(fields: FieldInfo[]): ColumnDef<RowData>[] {
return fields.map((f) => ({
id: f.name,
accessorKey: f.name,
header: f.name,
meta: {
label: f.name,
cell: { variant: "short-text" as const }
},
enableSorting: true,
enablePinning: true,
enableHiding: true
}));
}
function ResultsGrid({ result }: { result: QueryResult }) {
const { isTruncated } = result;
const columns = useMemo(() => buildColumns(result.fields), [result.fields]);
const getRowId = useCallback((_row: RowData, index: number) => String(index), []);
const gridProps = useDataGrid<RowData>({
data: result.rows,
columns,
getRowId,
readOnly: true,
rowHeight: "short",
enableSearch: true
});
return (
<div className="flex h-full flex-col overflow-hidden">
<div className="data-explorer-grid relative flex min-h-0 flex-1 flex-col overflow-hidden font-mono text-foreground [--color-gray-200:var(--color-border)] [&_[data-slot=grid-footer]]:hidden [&_[data-slot=grid-header]]:bg-container [&_[data-slot=grid]]:thin-scrollbar [&_[data-slot=grid]]:rounded-none [&_[data-slot=grid]]:border-0 [&_[data-slot=grid]]:bg-background">
<DataGrid {...gridProps} className="min-h-0 flex-1" stretchColumns />
</div>
{isTruncated && (
<div className="shrink-0 border-t border-border bg-card px-3 py-1.5 text-xs text-warning/80">
Showing first {result.rows.length.toLocaleString()} rows (results truncated)
</div>
)}
</div>
);
}
export function QueryResultsTable({ result, error, isRunning }: Props) {
if (isRunning) {
return (
<div className="flex h-full items-center justify-center">
<Spinner size="xs" />
</div>
);
}
if (error) {
return (
<div className="p-4">
<div className="rounded-md border border-danger/30 bg-danger/10 px-4 py-3 font-mono text-xs whitespace-pre-wrap text-danger">
{error}
</div>
</div>
);
}
if (!result) {
return (
<div className="flex h-full items-center justify-center">
<p className="text-sm text-muted">Run a query to see results</p>
</div>
);
}
if (result.rows.length === 0) {
const cmdUpper = result.command.toUpperCase();
const count = result.rowCount ?? 0;
const verb: Record<string, string> = {
INSERT: "inserted",
UPDATE: "updated",
DELETE: "deleted"
};
const staticMessage: Record<string, string> = {
BEGIN: "Transaction started",
COMMIT: "Transaction committed",
ROLLBACK: "Transaction rolled back"
};
const isMutation = verb[cmdUpper] !== undefined && result.fields.length === 0;
let message: string;
if (staticMessage[cmdUpper]) {
message = staticMessage[cmdUpper];
} else if (isMutation) {
message = `${count} row${count !== 1 ? "s" : ""} ${verb[cmdUpper]}`;
} else {
message = "No rows returned";
}
return (
<div className="flex h-full flex-col items-center justify-center gap-2">
<span className="rounded border-2 border-border bg-container px-3 py-1.5 font-mono text-sm text-foreground">
{message}
{isMutation && <span className="ml-2 text-muted">· No rows returned</span>}
</span>
</div>
);
}
return <ResultsGrid result={result} />;
}