Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor(frontend): migrate Audit Log page from Vue to React (#19810)

Danny Xud2e9b201cf36
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 84877f52ad..0a3c13aff1 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -128,6 +128,8 @@
"ok": "OK",
"share": "Share",
"or": "or",
+ "from": "From",
+ "to": "To",
"export": "Export",
"tips": "Tips",
"delete": "Delete",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index a41891f2f7..df8469bbac 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -128,6 +128,8 @@
"ok": "OK",
"share": "Compartir",
"or": "o",
+ "from": "Desde",
+ "to": "Hasta",
"export": "Exportar",
"tips": "Consejos",
"delete": "Eliminar",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index b45e49ecdd..b7beaf6b31 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -128,6 +128,8 @@
"ok": "わかりました",
"share": "共有",
"or": "または",
+ "from": "開始",
+ "to": "終了",
"export": "出力",
"tips": "プロンプトメッセージ",
"delete": "消去",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 42ab1dce2a..5c5b2b7300 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -128,6 +128,8 @@
"ok": "OK",
"share": "Chia sẻ",
"or": "hoặc",
+ "from": "Từ",
+ "to": "Đến",
"export": "Xuất",
"tips": "Mẹo",
"delete": "Xóa",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 2d2a05c3ea..ba0ac92c01 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -128,6 +128,8 @@
"ok": "OK",
"share": "分享",
"or": "或者",
+ "from": "从",
+ "to": "到",
"export": "导出",
"tips": "提示信息",
"delete": "删除",
diff --git a/frontend/src/react/locales/en-US.json b/frontend/src/react/locales/en-US.json
index da0a808b52..1e00232609 100644
--- a/frontend/src/react/locales/en-US.json
+++ b/frontend/src/react/locales/en-US.json
@@ -70,7 +70,42 @@
"failed": "Failed",
"project": "Project",
"instance": "Instance",
- "select": "Please Select"
+ "select": "Please Select",
+ "export": "Export",
+ "view": "View",
+ "view-details": "View Details",
+ "from": "From",
+ "to": "To"
+ },
+ "audit-log": {
+ "export-tooltip": "Must select start time and end time within 30 days",
+ "table": {
+ "created-ts": "Time",
+ "actor": "Actor",
+ "level": "Level",
+ "method": "Method",
+ "request": "Request",
+ "response": "Response",
+ "status": "Status",
+ "latency": "Latency",
+ "service-data": "Service Data"
+ },
+ "advanced-search": {
+ "scope": {
+ "actor": {
+ "title": "Actor",
+ "description": "Search by the audit log actor"
+ },
+ "method": {
+ "title": "Method",
+ "description": "Search by the method of audit log"
+ },
+ "level": {
+ "title": "Level",
+ "description": "Search by the level of audit log"
+ }
+ }
+ }
},
"cel": {
"condition": {
diff --git a/frontend/src/react/locales/es-ES.json b/frontend/src/react/locales/es-ES.json
index aaca4f2913..e42eaa7c46 100644
--- a/frontend/src/react/locales/es-ES.json
+++ b/frontend/src/react/locales/es-ES.json
@@ -70,7 +70,42 @@
"failed": "Error",
"instance": "Instancia",
"project": "Proyecto",
- "select": "Seleccionar"
+ "select": "Seleccionar",
+ "export": "Exportar",
+ "view": "Ver",
+ "view-details": "Ver Detalles",
+ "from": "Desde",
+ "to": "Hasta"
+ },
+ "audit-log": {
+ "export-tooltip": "Debe seleccionar hora de inicio y fin dentro de 30 días",
+ "table": {
+ "created-ts": "Hora",
+ "actor": "Actor",
+ "level": "Nivel",
+ "method": "Método",
+ "request": "Solicitud",
+ "response": "Respuesta",
+ "status": "Estado",
+ "latency": "Latencia",
+ "service-data": "Datos de Servicio"
+ },
+ "advanced-search": {
+ "scope": {
+ "actor": {
+ "title": "Actor",
+ "description": "Buscar por el actor del registro de auditoría"
+ },
+ "method": {
+ "title": "Método",
+ "description": "Buscar por el método del registro de auditoría"
+ },
+ "level": {
+ "title": "Nivel",
+ "description": "Buscar por el nivel del registro de auditoría"
+ }
+ }
+ }
},
"cel": {
"condition": {
diff --git a/frontend/src/react/locales/ja-JP.json b/frontend/src/react/locales/ja-JP.json
index 6289a66d04..9ba7bfc264 100644
--- a/frontend/src/react/locales/ja-JP.json
+++ b/frontend/src/react/locales/ja-JP.json
@@ -70,7 +70,42 @@
"failed": "失敗",
"instance": "インスタンス",
"project": "プロジェクト",
- "select": "選択してください"
+ "select": "選択してください",
+ "export": "エクスポート",
+ "view": "表示",
+ "view-details": "詳細を表示",
+ "from": "開始",
+ "to": "終了"
+ },
+ "audit-log": {
+ "export-tooltip": "30日以内の開始時間と終了時間を選択する必要があります",
+ "table": {
+ "created-ts": "時間",
+ "actor": "操作者",
+ "level": "レベル",
+ "method": "メソッド",
+ "request": "リクエスト",
+ "response": "レスポンス",
+ "status": "ステータス",
+ "latency": "レイテンシー",
+ "service-data": "サービスデータ"
+ },
+ "advanced-search": {
+ "scope": {
+ "actor": {
+ "title": "操作者",
+ "description": "監査ログの操作者で検索"
+ },
+ "method": {
+ "title": "メソッド",
+ "description": "監査ログのメソッドで検索"
+ },
+ "level": {
+ "title": "レベル",
+ "description": "監査ログのレベルで検索"
+ }
+ }
+ }
},
"cel": {
"condition": {
diff --git a/frontend/src/react/locales/vi-VN.json b/frontend/src/react/locales/vi-VN.json
index 6cc099c6f6..3d8d6bac47 100644
--- a/frontend/src/react/locales/vi-VN.json
+++ b/frontend/src/react/locales/vi-VN.json
@@ -70,7 +70,42 @@
"failed": "Thất bại",
"instance": "Phiên bản",
"project": "Dự án",
- "select": "Vui lòng chọn"
+ "select": "Vui lòng chọn",
+ "export": "Xuất",
+ "view": "Xem",
+ "view-details": "Xem Chi tiết",
+ "from": "Từ",
+ "to": "Đến"
+ },
+ "audit-log": {
+ "export-tooltip": "Phải chọn thời gian bắt đầu và kết thúc trong vòng 30 ngày",
+ "table": {
+ "created-ts": "Thời gian",
+ "actor": "Người thực hiện",
+ "level": "Mức độ",
+ "method": "Phương thức",
+ "request": "Yêu cầu",
+ "response": "Phản hồi",
+ "status": "Trạng thái",
+ "latency": "Độ trễ",
+ "service-data": "Dữ liệu Dịch vụ"
+ },
+ "advanced-search": {
+ "scope": {
+ "actor": {
+ "title": "Người thực hiện",
+ "description": "Tìm kiếm theo người thực hiện"
+ },
+ "method": {
+ "title": "Phương thức",
+ "description": "Tìm kiếm theo phương thức"
+ },
+ "level": {
+ "title": "Mức độ",
+ "description": "Tìm kiếm theo mức độ"
+ }
+ }
+ }
},
"cel": {
"condition": {
diff --git a/frontend/src/react/locales/zh-CN.json b/frontend/src/react/locales/zh-CN.json
index f3ad2fe684..2421eb243a 100644
--- a/frontend/src/react/locales/zh-CN.json
+++ b/frontend/src/react/locales/zh-CN.json
@@ -70,7 +70,42 @@
"failed": "失败",
"instance": "实例",
"project": "项目",
- "select": "请选择"
+ "select": "请选择",
+ "export": "导出",
+ "view": "查看",
+ "view-details": "查看详情",
+ "from": "从",
+ "to": "到"
+ },
+ "audit-log": {
+ "export-tooltip": "必须选择 30 天范围内的开始和结束日期",
+ "table": {
+ "created-ts": "时间",
+ "actor": "操作者",
+ "level": "事件等级",
+ "method": "操作",
+ "request": "请求信息",
+ "response": "响应信息",
+ "status": "状态",
+ "latency": "延迟",
+ "service-data": "服务数据"
+ },
+ "advanced-search": {
+ "scope": {
+ "actor": {
+ "title": "操作者",
+ "description": "按审计日志操作者搜索"
+ },
+ "method": {
+ "title": "操作",
+ "description": "按审计日志操作搜索"
+ },
+ "level": {
+ "title": "事件等级",
+ "description": "按审计日志事件等级搜索"
+ }
+ }
+ }
},
"cel": {
"condition": {
diff --git a/frontend/src/react/pages/settings/AuditLogPage.tsx b/frontend/src/react/pages/settings/AuditLogPage.tsx
new file mode 100644
index 0000000000..30197e5ea1
--- /dev/null
+++ b/frontend/src/react/pages/settings/AuditLogPage.tsx
@@ -0,0 +1,998 @@
+import { file_google_rpc_error_details } from "@buf/googleapis_googleapis.bufbuild_es/google/rpc/error_details_pb";
+import { create, createRegistry, toJsonString } from "@bufbuild/protobuf";
+import { AnySchema } from "@bufbuild/protobuf/wkt";
+import dayjs from "dayjs";
+import utc from "dayjs/plugin/utc";
+import {
+ ArrowRight,
+ Calendar,
+ ChevronDown,
+ Download,
+ ExternalLink,
+ Maximize2,
+ X,
+} from "lucide-react";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { useTranslation } from "react-i18next";
+import { auditLogServiceClientConnect } from "@/connect";
+import { ALL_METHODS_WITH_AUDIT } from "@/connect/methods";
+import {
+ AdvancedSearch,
+ type ScopeOption,
+ type SearchParams,
+} from "@/react/components/AdvancedSearch";
+import { FeatureAttention } from "@/react/components/FeatureAttention";
+import { Button } from "@/react/components/ui/button";
+import {
+ getPageSizeOptions,
+ useSessionPageSize,
+} from "@/react/hooks/useSessionPageSize";
+import { useVueState } from "@/react/hooks/useVueState";
+import { cn } from "@/react/lib/utils";
+import { pushNotification, useSubscriptionV1Store } from "@/store";
+import {
+ extractUserEmail,
+ getProjectIdPlanUidStageUidFromRolloutName,
+ planNamePrefix,
+ projectNamePrefix,
+ userNamePrefix,
+} from "@/store/modules/v1/common";
+import { getDateForPbTimestampProtoEs } from "@/types";
+import { StatusSchema } from "@/types/proto-es/google/rpc/status_pb";
+import type { AuditLog } from "@/types/proto-es/v1/audit_log_service_pb";
+import {
+ AuditDataSchema,
+ AuditLog_Severity,
+ ExportAuditLogsRequestSchema,
+ SearchAuditLogsRequestSchema,
+} from "@/types/proto-es/v1/audit_log_service_pb";
+import { ExportFormat } from "@/types/proto-es/v1/common_pb";
+import { IssueService } from "@/types/proto-es/v1/issue_service_pb";
+import {
+ file_v1_plan_service,
+ PlanService,
+} from "@/types/proto-es/v1/plan_service_pb";
+import { RolloutService } from "@/types/proto-es/v1/rollout_service_pb";
+import { SettingSchema } from "@/types/proto-es/v1/setting_service_pb";
+import { SQLService } from "@/types/proto-es/v1/sql_service_pb";
+import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
+import {
+ formatAbsoluteDateTime,
+ hasWorkspacePermissionV2,
+ humanizeDurationV1,
+} from "@/utils";
+
+// dayjs UTC plugin is needed by buildFilterString for create_time filters.
+dayjs.extend(utc);
+
+const registry = createRegistry(
+ file_google_rpc_error_details,
+ file_v1_plan_service,
+ AuditDataSchema,
+ SettingSchema
+);
+
+// ============================================================
+// Filter helpers
+// ============================================================
+
+interface AuditLogFilter {
+ method?: string;
+ level?: AuditLog_Severity;
+ userEmail?: string;
+ createdTsAfter?: number;
+ createdTsBefore?: number;
+}
+
+function buildFilterString(filter: AuditLogFilter): string {
+ const parts: string[] = [];
+ if (filter.method) parts.push(`method == "${filter.method}"`);
+ if (filter.level !== undefined)
+ parts.push(`severity == "${AuditLog_Severity[filter.level]}"`);
+ if (filter.userEmail)
+ parts.push(`user == "${userNamePrefix}${filter.userEmail}"`);
+ if (filter.createdTsAfter)
+ parts.push(
+ `create_time >= "${dayjs(filter.createdTsAfter).utc().format()}"`
+ );
+ if (filter.createdTsBefore)
+ parts.push(
+ `create_time <= "${dayjs(filter.createdTsBefore).utc().format()}"`
+ );
+ return parts.join(" && ");
+}
+
+function buildAuditLogFilter(params: SearchParams): AuditLogFilter {
+ const filter: AuditLogFilter = {};
+ const method = params.scopes.find((s) => s.id === "method")?.value;
+ if (method) filter.method = method;
+ const actor = params.scopes.find((s) => s.id === "actor")?.value;
+ if (actor) filter.userEmail = actor;
+ const level = params.scopes.find((s) => s.id === "level")?.value;
+ if (level)
+ filter.level = AuditLog_Severity[level as keyof typeof AuditLog_Severity];
+ const created = params.scopes.find((s) => s.id === "created")?.value;
+ if (created) {
+ const parts = created.split(",");
+ if (parts.length === 2) {
+ filter.createdTsAfter = parseInt(parts[0], 10);
+ filter.createdTsBefore = parseInt(parts[1], 10);
+ }
+ }
+ return filter;
+}
+
+// ============================================================
+// View link helper
+// ============================================================
+
+function getViewLink(auditLog: AuditLog): string | null {
+ let parsedRequest: Record<string, unknown>;
+ let parsedResponse: Record<string, unknown>;
+ try {
+ parsedRequest = JSON.parse(auditLog.request || "{}") as Record<
+ string,
+ unknown
+ >;
+ parsedResponse = JSON.parse(auditLog.response || "{}") as Record<
+ string,
+ unknown
+ >;
+ } catch {
+ return null;
+ }
+ if (Boolean(parsedRequest["validateOnly"])) return null;
+ const sections = auditLog.method.split("/").filter((i) => i);
+ switch (sections[0]) {
+ case RolloutService.typeName:
+ case PlanService.typeName:
+ case IssueService.typeName:
+ return (parsedResponse["name"] as string) || null;
+ case SQLService.typeName: {
+ if (sections[1] !== "Export") return null;
+ const name = parsedRequest["name"] as string | undefined;
+ if (!name) return null;
+ const [projectId, planId] =
+ getProjectIdPlanUidStageUidFromRolloutName(name);
+ if (!projectId || !planId) return null;
+ return `${projectNamePrefix}${projectId}/${planNamePrefix}${planId}/rollout`;
+ }
+ }
+ return null;
+}
+
+// ============================================================
+// JSONStringView
+// ============================================================
+
+function JSONStringView({ jsonString }: { jsonString: string }) {
+ const { t } = useTranslation();
+ const [showModal, setShowModal] = useState(false);
+
+ const formatted = useMemo(() => {
+ try {
+ return JSON.stringify(JSON.parse(jsonString), null, 2);
+ } catch {
+ return "-";
+ }
+ }, [jsonString]);
+
+ // Dismiss modal on Escape key
+ useEffect(() => {
+ if (!showModal) return;
+ const handler = (e: KeyboardEvent) => {
+ if (e.key === "Escape") setShowModal(false);
+ };
+ document.addEventListener("keydown", handler);
+ return () => document.removeEventListener("keydown", handler);
+ }, [showModal]);
+
+ return (
+ <>
+ <div className="group grow-0 w-full flex flex-row justify-start items-center gap-2">
+ <p className="line-clamp-2">
+ <code className="text-sm break-all">{jsonString}</code>
+ </p>
+ <div className="hidden group-hover:block shrink-0 h-[22px]">
+ <button
+ className="p-0.5 border border-control-border rounded-xs hover:bg-control-bg"
+ onClick={() => setShowModal(true)}
+ >
+ <Maximize2 className="w-3 h-3" />
+ </button>
+ </div>
+ </div>
+ {showModal && (
+ <div
+ className="fixed inset-0 z-50 flex items-center justify-center bg-black/50"
+ onClick={() => setShowModal(false)}
+ >
+ <div
+ className="bg-white rounded-md shadow-lg flex flex-col"
+ style={{
+ width: "calc(100vw - 12rem)",
+ height: "calc(100vh - 12rem)",
+ }}
+ onClick={(e) => e.stopPropagation()}
+ >
+ <div className="flex items-center justify-between px-4 py-3 border-b">
+ <h3 className="text-base font-medium">
+ {t("common.view-details")}
+ </h3>
+ <button
+ className="p-1 hover:bg-control-bg rounded-full"
+ onClick={() => setShowModal(false)}
+ >
+ <X className="w-4 h-4" />
+ </button>
+ </div>
+ <div className="flex-1 overflow-auto p-4">
+ <pre className="text-sm font-mono whitespace-pre-wrap break-all">
+ {formatted}
+ </pre>
+ </div>
+ </div>
+ </div>
+ )}
+ </>
+ );
+}
+
+// ============================================================
+// TimeRangePicker — shows full datetime, updates the "created" scope
+// ============================================================
+
+function TimeRangePicker({
+ params,
+ onParamsChange,
+}: {
+ params: SearchParams;
+ onParamsChange: (params: SearchParams) => void;
+}) {
+ const { t } = useTranslation();
+ const [showPicker, setShowPicker] = useState(false);
+ const containerRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ const handler = (e: MouseEvent) => {
+ if (
+ containerRef.current &&
+ !containerRef.current.contains(e.target as Node)
+ ) {
+ setShowPicker(false);
+ }
+ };
+ document.addEventListener("mousedown", handler);
+ return () => document.removeEventListener("mousedown", handler);
+ }, []);
+
+ const createdScope = params.scopes.find((s) => s.id === "created");
+ const [fromTs, toTs] = useMemo(() => {
+ if (!createdScope) return [undefined, undefined];
+ const parts = createdScope.value.split(",");
+ if (parts.length !== 2) return [undefined, undefined];
+ return [parseInt(parts[0], 10), parseInt(parts[1], 10)];
+ }, [createdScope]);
+
+ const fromDatetime = fromTs
+ ? dayjs(fromTs).format("YYYY-MM-DDTHH:mm:ss")
+ : "";
+ const toDatetime = toTs ? dayjs(toTs).format("YYYY-MM-DDTHH:mm:ss") : "";
+
+ const displayFrom = fromTs ? dayjs(fromTs).format("YYYY-MM-DD HH:mm:ss") : "";
+ const displayTo = toTs ? dayjs(toTs).format("YYYY-MM-DD HH:mm:ss") : "";
+
+ const updateRange = useCallback(
+ (from: string, to: string) => {
+ const fromVal = from ? dayjs(from).valueOf() : undefined;
+ const toVal = to ? dayjs(to).valueOf() : undefined;
+ const scopes = params.scopes.filter((s) => s.id !== "created");
+ if (fromVal !== undefined && toVal !== undefined) {
+ scopes.push({
+ id: "created",
+ value: `${fromVal},${toVal}`,
+ readonly: true,
+ });
+ }
+ onParamsChange({ ...params, scopes });
+ },
+ [params, onParamsChange]
+ );
+
+ return (
+ <div ref={containerRef} className="relative shrink-0">
+ <button
+ className="h-9 flex items-center gap-x-2 border border-control-border rounded-xs px-3 text-sm hover:bg-control-bg whitespace-nowrap"
+ onClick={() => setShowPicker(!showPicker)}
+ >
+ {displayFrom && displayTo ? (
+ <>
+ <span>{displayFrom}</span>
+ <ArrowRight className="w-3.5 h-3.5 text-control-light shrink-0" />
+ <span>{displayTo}</span>
+ </>
+ ) : (
+ <span className="text-control-placeholder">{t("common.select")}</span>
+ )}
+ <Calendar className="w-4 h-4 text-control-light ml-1 shrink-0" />
+ </button>
+ {showPicker && (
+ <div className="absolute right-0 top-[42px] bg-white border border-control-border rounded-sm shadow-lg z-50 p-3 flex flex-col gap-y-2 min-w-[300px]">
+ <div className="flex items-center gap-x-2">
+ <label className="text-sm text-control-light whitespace-nowrap w-10">
+ {t("common.from")}
+ </label>
+ <input
+ type="datetime-local"
+ step="1"
+ className="flex-1 border border-control-border rounded-xs px-2 py-1 text-sm"
+ value={fromDatetime}
+ onChange={(e) => updateRange(e.target.value, toDatetime)}
+ />
+ </div>
+ <div className="flex items-center gap-x-2">
+ <label className="text-sm text-control-light whitespace-nowrap w-10">
+ {t("common.to")}
+ </label>
+ <input
+ type="datetime-local"
+ step="1"
+ className="flex-1 border border-control-border rounded-xs px-2 py-1 text-sm"
+ value={toDatetime}
+ onChange={(e) => updateRange(fromDatetime, e.target.value)}
+ />
+ </div>
+ </div>
+ )}
+ </div>
+ );
+}
+
+// ============================================================
+// ExportDropdown — filled accent button like the old design
+// ============================================================
+
+function ExportDropdown({
+ disabled,
+ tooltip,
+ onExport,
+}: {
+ disabled: boolean;
+ tooltip: string;
+ onExport: (format: ExportFormat) => void;
+}) {
+ const { t } = useTranslation();
+ const [open, setOpen] = useState(false);
+ const containerRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ const handler = (e: MouseEvent) => {
+ if (
+ containerRef.current &&
+ !containerRef.current.contains(e.target as Node)
+ ) {
+ setOpen(false);
+ }
+ };
+ document.addEventListener("mousedown", handler);
+ return () => document.removeEventListener("mousedown", handler);
+ }, []);
+
+ const formats = [
+ { format: ExportFormat.CSV, label: "CSV" },
+ { format: ExportFormat.JSON, label: "JSON" },
+ { format: ExportFormat.XLSX, label: "XLSX" },
+ ];
+
+ return (
+ <div ref={containerRef} className="relative shrink-0">
+ <Button
+ disabled={disabled}
+ title={tooltip}
+ onClick={() => setOpen(!open)}
+ >
+ <Download className="w-4 h-4 mr-1" />
+ {t("common.export")}
+ </Button>
+ {open && !disabled && (
+ <div className="absolute right-0 top-[42px] bg-white border border-control-border rounded-sm shadow-lg z-50 py-1 min-w-[100px]">
+ {formats.map(({ format, label }) => (
+ <button
+ key={label}
+ className="block w-full text-left px-3 py-1.5 text-sm hover:bg-control-bg"
+ onClick={() => {
+ onExport(format);
+ setOpen(false);
+ }}
+ >
+ {label}
+ </button>
+ ))}
+ </div>
+ )}
+ </div>
+ );
+}
+
+// ============================================================
+// Column definitions
+// ============================================================
+
+interface ColumnDef {
+ key: string;
+ title: string;
+ defaultWidth: number;
+ minWidth?: number;
+ resizable?: boolean;
+ sortable?: boolean;
+ render: (auditLog: AuditLog) => React.ReactNode;
+}
+
+function useColumnDefs(): ColumnDef[] {
+ const { t } = useTranslation();
+ return useMemo(
+ () => [
+ {
+ key: "create_time",
+ title: t("audit-log.table.created-ts"),
+ defaultWidth: 220,
+ minWidth: 160,
+ resizable: true,
+ sortable: true,
+ render: (log: AuditLog) =>
+ formatAbsoluteDateTime(
+ getDateForPbTimestampProtoEs(log.createTime)?.getTime() ?? 0
+ ),
+ },
+ {
+ key: "severity",
+ title: t("audit-log.table.level"),
+ defaultWidth: 60,
+ minWidth: 50,
+ resizable: true,
+ render: (log: AuditLog) => AuditLog_Severity[log.severity],
+ },
+ {
+ key: "method",
+ title: t("audit-log.table.method"),
+ defaultWidth: 280,
+ minWidth: 150,
+ resizable: true,
+ render: (log: AuditLog) => log.method,
+ },
+ {
+ key: "actor",
+ title: t("audit-log.table.actor"),
+ defaultWidth: 200,
+ minWidth: 120,
+ resizable: true,
+ render: (log: AuditLog) => {
+ if (!log.user) return <span>-</span>;
+ const email = extractUserEmail(log.user);
+ return (
+ <a href={`mailto:${email}`} className="text-accent hover:underline">
+ {email}
+ </a>
+ );
+ },
+ },
+ {
+ key: "request",
+ title: t("audit-log.table.request"),
+ defaultWidth: 300,
+ minWidth: 180,
+ resizable: true,
+ render: (log: AuditLog) =>
+ log.request.length > 0 ? (
+ <JSONStringView jsonString={log.request} />
+ ) : (
+ "-"
+ ),
+ },
+ {
+ key: "response",
+ title: t("audit-log.table.response"),
+ defaultWidth: 300,
+ minWidth: 180,
+ resizable: true,
+ render: (log: AuditLog) =>
+ log.response.length > 0 ? (
+ <JSONStringView jsonString={log.response} />
+ ) : (
+ "-"
+ ),
+ },
+ {
+ key: "status",
+ title: t("audit-log.table.status"),
+ defaultWidth: 80,
+ minWidth: 60,
+ resizable: true,
+ render: (log: AuditLog) =>
+ log.status ? (
+ <JSONStringView
+ jsonString={toJsonString(StatusSchema, log.status, {
+ registry,
+ })}
+ />
+ ) : (
+ "-"
+ ),
+ },
+ {
+ key: "latency",
+ title: t("audit-log.table.latency"),
+ defaultWidth: 90,
+ minWidth: 60,
+ resizable: true,
+ render: (log: AuditLog) => (
+ <span className="whitespace-nowrap">
+ {humanizeDurationV1(log.latency)}
+ </span>
+ ),
+ },
+ {
+ key: "service-data",
+ title: t("audit-log.table.service-data"),
+ defaultWidth: 240,
+ minWidth: 120,
+ resizable: true,
+ render: (log: AuditLog) =>
+ log.serviceData ? (
+ <JSONStringView
+ jsonString={toJsonString(AnySchema, log.serviceData, {
+ registry,
+ })}
+ />
+ ) : (
+ "-"
+ ),
+ },
+ {
+ key: "view",
+ title: t("common.view"),
+ defaultWidth: 50,
+ render: (log: AuditLog) => {
+ let link = getViewLink(log);
+ if (!link) return null;
+ if (!link.startsWith("/")) link = `/${link}`;
+ return (
+ <a href={link} target="_blank" rel="noreferrer">
+ <ExternalLink className="w-4 h-4 text-accent" />
+ </a>
+ );
+ },
+ },
+ ],
+ [t]
+ );
+}
+
+// ============================================================
+// useColumnWidths — manages resizable column widths
+// ============================================================
+
+function useColumnWidths(columns: ColumnDef[]) {
+ const [widths, setWidths] = useState<number[]>(() =>
+ columns.map((c) => c.defaultWidth)
+ );
+ const dragRef = useRef<{
+ colIndex: number;
+ startX: number;
+ startWidth: number;
+ } | null>(null);
+
+ const onMouseDown = useCallback(
+ (colIndex: number, e: React.MouseEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+ dragRef.current = {
+ colIndex,
+ startX: e.clientX,
+ startWidth: widths[colIndex],
+ };
+
+ const onMouseMove = (ev: MouseEvent) => {
+ if (!dragRef.current) return;
+ const delta = ev.clientX - dragRef.current.startX;
+ const min = columns[dragRef.current.colIndex].minWidth ?? 40;
+ const newWidth = Math.max(min, dragRef.current.startWidth + delta);
+ setWidths((prev) => {
+ const next = [...prev];
+ next[dragRef.current!.colIndex] = newWidth;
+ return next;
+ });
+ };
+ const onMouseUp = () => {
+ dragRef.current = null;
+ document.removeEventListener("mousemove", onMouseMove);
+ document.removeEventListener("mouseup", onMouseUp);
+ document.body.style.cursor = "";
+ document.body.style.userSelect = "";
+ };
+ document.addEventListener("mousemove", onMouseMove);
+ document.addEventListener("mouseup", onMouseUp);
+ document.body.style.cursor = "col-resize";
+ document.body.style.userSelect = "none";
+ },
+ [widths, columns]
+ );
+
+ const totalWidth = widths.reduce((sum, w) => sum + w, 0);
+
+ return { widths, totalWidth, onResizeStart: onMouseDown };
+}
+
+// ============================================================
+// Main page
+// ============================================================
+
+export function AuditLogPage() {
+ const { t } = useTranslation();
+ const subscriptionStore = useSubscriptionV1Store();
+ const hasAuditLogFeature = useVueState(() =>
+ subscriptionStore.hasFeature(PlanFeature.FEATURE_AUDIT_LOG)
+ );
+ const canExport = hasWorkspacePermissionV2("bb.auditLogs.export");
+ const columns = useColumnDefs();
+ const { widths, totalWidth, onResizeStart } = useColumnWidths(columns);
+
+ // The "created" scope is readonly so it's hidden from the search bar.
+ // The TimeRangePicker manages it separately.
+ const [searchParams, setSearchParams] = useState<SearchParams>(() => {
+ const to = dayjs().endOf("day");
+ const from = to.add(-30, "day");
+ return {
+ query: "",
+ scopes: [
+ {
+ id: "created",
+ value: `${from.valueOf()},${to.valueOf()}`,
+ readonly: true,
+ },
+ ],
+ };
+ });
+
+ const filter = useMemo(
+ () => buildAuditLogFilter(searchParams),
+ [searchParams]
+ );
+ const parent = `${projectNamePrefix}-`;
+
+ // Data fetching
+ const [auditLogs, setAuditLogs] = useState<AuditLog[]>([]);
+ const [loading, setLoading] = useState(true);
+ const nextPageTokenRef = useRef("");
+ const [hasMore, setHasMore] = useState(false);
+ const [isFetchingMore, setIsFetchingMore] = useState(false);
+ const [pageSize, setPageSize] = useSessionPageSize("bb.audit-log-table");
+ const fetchIdRef = useRef(0);
+
+ // Sort state
+ const [sortKey, setSortKey] = useState<string | null>(null);
+ const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc");
+ const orderBy = sortKey ? `${sortKey} ${sortOrder}` : "";
+
+ const toggleSort = useCallback(
+ (key: string) => {
+ if (sortKey === key) {
+ if (sortOrder === "asc") setSortOrder("desc");
+ else {
+ setSortKey(null);
+ setSortOrder("asc");
+ }
+ } else {
+ setSortKey(key);
+ setSortOrder("asc");
+ }
+ },
+ [sortKey, sortOrder]
+ );
+
+ const fetchAuditLogs = useCallback(
+ async (isRefresh: boolean) => {
+ if (!hasAuditLogFeature) return;
+ const currentFetchId = ++fetchIdRef.current;
+ if (isRefresh) setLoading(true);
+ else setIsFetchingMore(true);
+ try {
+ const token = isRefresh ? "" : nextPageTokenRef.current;
+ const request = create(SearchAuditLogsRequestSchema, {
+ parent,
+ filter: buildFilterString(filter),
+ orderBy,
+ pageSize,
+ pageToken: token,
+ });
+ const resp =
+ await auditLogServiceClientConnect.searchAuditLogs(request);
+ if (currentFetchId !== fetchIdRef.current) return;
+ if (isRefresh) setAuditLogs(resp.auditLogs);
+ else setAuditLogs((prev) => [...prev, ...resp.auditLogs]);
+ nextPageTokenRef.current = resp.nextPageToken ?? "";
+ setHasMore(Boolean(resp.nextPageToken));
+ } catch (e) {
+ if (e instanceof Error && e.name === "AbortError") return;
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("common.failed"),
+ description: (e as { message?: string }).message,
+ });
+ } finally {
+ if (currentFetchId === fetchIdRef.current) {
+ setLoading(false);
+ setIsFetchingMore(false);
+ }
+ }
+ },
+ [hasAuditLogFeature, parent, filter, orderBy, pageSize, t]
+ );
+
+ const isFirstLoad = useRef(true);
+ useEffect(() => {
+ if (isFirstLoad.current) {
+ isFirstLoad.current = false;
+ fetchAuditLogs(true);
+ return;
+ }
+ const timer = setTimeout(() => fetchAuditLogs(true), 300);
+ return () => clearTimeout(timer);
+ }, [fetchAuditLogs]);
+
+ const loadMore = useCallback(() => {
+ if (nextPageTokenRef.current && !isFetchingMore) fetchAuditLogs(false);
+ }, [isFetchingMore, fetchAuditLogs]);
+
+ // Export
+ const [exporting, setExporting] = useState(false);
+ const handleExport = useCallback(
+ async (format: ExportFormat) => {
+ setExporting(true);
+ try {
+ let pageToken = "";
+ const blobs: Uint8Array[] = [];
+ do {
+ const request = create(ExportAuditLogsRequestSchema, {
+ parent,
+ filter: buildFilterString(filter),
+ orderBy,
+ format,
+ pageSize: 5000,
+ pageToken,
+ });
+ const resp =
+ await auditLogServiceClientConnect.exportAuditLogs(request);
+ blobs.push(resp.content);
+ pageToken = resp.nextPageToken;
+ } while (pageToken);
+
+ for (let j = 0; j < blobs.length; j++) {
+ const blob = new Blob([new Uint8Array(blobs[j]).buffer]);
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = `audit-log.file${j + 1}.${dayjs().format("YYYY-MM-DDTHH-mm-ss")}.${ExportFormat[format].toLowerCase()}`;
+ a.click();
+ URL.revokeObjectURL(url);
+ }
+ } catch (e) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("common.failed"),
+ description: (e as { message?: string }).message,
+ });
+ } finally {
+ setExporting(false);
+ }
+ },
+ [parent, filter, orderBy, t]
+ );
+
+ const disableExportTip = useMemo(() => {
+ if (!filter.createdTsAfter || !filter.createdTsBefore)
+ return t("audit-log.export-tooltip");
+ if (
+ filter.createdTsBefore - filter.createdTsAfter >
+ 30 * 24 * 60 * 60 * 1000
+ )
+ return t("audit-log.export-tooltip");
+ return "";
+ }, [filter, t]);
+
+ // Scope options: method, level, and actor (free-text input)
+ const scopeOptions = useMemo((): ScopeOption[] => {
+ return [
+ {
+ id: "actor",
+ title: t("audit-log.advanced-search.scope.actor.title"),
+ description: t("audit-log.advanced-search.scope.actor.description"),
+ },
+ {
+ id: "method",
+ title: t("audit-log.advanced-search.scope.method.title"),
+ description: t("audit-log.advanced-search.scope.method.description"),
+ options: ALL_METHODS_WITH_AUDIT.map((method) => ({
+ value: method,
+ keywords: [method],
+ })),
+ },
+ {
+ id: "level",
+ title: t("audit-log.advanced-search.scope.level.title"),
+ description: t("audit-log.advanced-search.scope.level.description"),
+ options: Object.keys(AuditLog_Severity)
+ .filter((v) => Number.isNaN(Number(v)))
+ .map((severity) => ({
+ value: severity,
+ keywords: [severity],
+ })),
+ },
+ ];
+ }, [t]);
+
+ const renderSortIndicator = (columnKey: string) => {
+ if (sortKey !== columnKey)
+ return <ChevronDown className="h-4 w-4 text-control-light" />;
+ return (
+ <ChevronDown
+ className={cn(
+ "h-4 w-4 text-accent transition-transform",
+ sortOrder === "asc" && "rotate-180"
+ )}
+ />
+ );
+ };
+
+ const pageSizeOptions = getPageSizeOptions();
+
+ return (
+ <div className="flex flex-col">
+ {/* Header */}
+ <div className="px-4 py-4 flex flex-col gap-y-2">
+ <FeatureAttention feature={PlanFeature.FEATURE_AUDIT_LOG} />
+ <div className="flex items-center gap-x-2">
+ <AdvancedSearch
+ params={searchParams}
+ scopeOptions={scopeOptions}
+ onParamsChange={setSearchParams}
+ />
+ <TimeRangePicker
+ params={searchParams}
+ onParamsChange={setSearchParams}
+ />
+ {canExport && (
+ <ExportDropdown
+ disabled={!hasAuditLogFeature || !!disableExportTip || exporting}
+ tooltip={disableExportTip}
+ onExport={handleExport}
+ />
+ )}
+ </div>
+ </div>
+
+ {/* Table */}
+ {hasAuditLogFeature ? (
+ <div>
+ <div className="overflow-x-auto">
+ <table
+ className="text-sm border-t border-block-border table-fixed"
+ style={{ width: `${totalWidth}px` }}
+ >
+ <colgroup>
+ {widths.map((w, i) => (
+ <col key={columns[i].key} style={{ width: `${w}px` }} />
+ ))}
+ </colgroup>
+ <thead>
+ <tr className="border-b border-block-border">
+ {columns.map((col, colIdx) => (
+ <th
+ key={col.key}
+ className={cn(
+ "relative px-4 py-3 text-left text-sm font-medium text-main whitespace-nowrap",
+ col.sortable && "cursor-pointer select-none"
+ )}
+ onClick={
+ col.sortable ? () => toggleSort(col.key) : undefined
+ }
+ >
+ <div className="flex items-center gap-x-1">
+ {col.title}
+ {col.sortable && renderSortIndicator(col.key)}
+ </div>
+ {col.resizable && (
+ <div
+ className="absolute right-0 top-1/4 h-1/2 w-[3px] cursor-col-resize rounded-full bg-gray-200 hover:bg-accent/60 active:bg-accent transition-colors"
+ onMouseDown={(e) => onResizeStart(colIdx, e)}
+ />
+ )}
+ </th>
+ ))}
+ </tr>
+ </thead>
+ <tbody>
+ {loading && auditLogs.length === 0 ? (
+ <tr>
+ <td
+ colSpan={columns.length}
+ className="text-center py-8 text-control-placeholder"
+ >
+ {t("common.loading")}
+ </td>
+ </tr>
+ ) : auditLogs.length === 0 ? (
+ <tr>
+ <td
+ colSpan={columns.length}
+ className="text-center py-8 text-control-placeholder"
+ >
+ {t("common.no-data")}
+ </td>
+ </tr>
+ ) : (
+ auditLogs.map((log, idx) => (
+ <tr
+ key={log.name || idx}
+ className={cn(
+ "border-b border-block-border",
+ idx % 2 === 1 && "bg-gray-50/50"
+ )}
+ >
+ {columns.map((col) => (
+ <td
+ key={col.key}
+ className="px-4 py-3 text-sm align-top overflow-hidden"
+ >
+ {col.render(log)}
+ </td>
+ ))}
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+
+ {/* Pagination footer */}
+ <div className="flex items-center justify-end gap-x-2 mx-4 py-2">
+ <div className="flex items-center gap-x-2">
+ <span className="text-sm text-control-light">
+ {t("common.rows-per-page")}
+ </span>
+ <select
+ className="border border-control-border rounded-sm text-sm pl-2 pr-6 py-1 min-w-[5rem]"
+ value={pageSize}
+ onChange={(e) => setPageSize(Number(e.target.value))}
+ >
+ {pageSizeOptions.map((size) => (
+ <option key={size} value={size}>
+ {size}
+ </option>
+ ))}
+ </select>
+ </div>
+ {hasMore && (
+ <Button
+ variant="ghost"
+ size="sm"
+ disabled={isFetchingMore}
+ onClick={loadMore}
+ >
+ <span className="text-sm text-control-light">
+ {isFetchingMore ? t("common.loading") : t("common.load-more")}
+ </span>
+ </Button>
+ )}
+ </div>
+ </div>
+ ) : (
+ <div className="mx-4 py-12 border rounded-sm flex items-center justify-center text-control-placeholder">
+ {t("common.no-data")}
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/frontend/src/router/dashboard/workspace.ts b/frontend/src/router/dashboard/workspace.ts
index 7c6575bdb1..8567e0ff40 100644
--- a/frontend/src/router/dashboard/workspace.ts
+++ b/frontend/src/router/dashboard/workspace.ts
@@ -304,8 +304,8 @@ const workspaceRoutes: RouteRecordRaw[] = [
title: () => t("settings.sidebar.audit-log"),
requiredPermissionList: () => ["bb.auditLogs.search"],
},
- component: () => import("@/views/SettingWorkspaceAuditLog.vue"),
- props: true,
+ component: () => import("@/react/ReactPageMount.vue"),
+ props: () => ({ page: "AuditLogPage" }),
},
{
path: "users",
diff --git a/frontend/src/views/SettingWorkspaceAuditLog.vue b/frontend/src/views/SettingWorkspaceAuditLog.vue
deleted file mode 100644
index 1484a3de83..0000000000
--- a/frontend/src/views/SettingWorkspaceAuditLog.vue
+++ /dev/null
@@ -1,97 +0,0 @@
-<template>
- <div class="px-4 py-4">
- <FeatureAttention :feature="PlanFeature.FEATURE_AUDIT_LOG" />
- <AuditLogSearch v-model:params="state.params">
- <template #searchbox-suffix>
- <DataExportButton
- v-if="hasWorkspacePermissionV2('bb.auditLogs.export')"
- size="medium"
- :support-formats="[
- ExportFormat.CSV,
- ExportFormat.JSON,
- ExportFormat.XLSX,
- ]"
- :tooltip="disableExportTip"
- :view-mode="'DROPDOWN'"
- :disabled="!hasAuditLogFeature || !!disableExportTip"
- @export="(params) => pagedAuditLogDataTableRef?.handleExport(params)"
- />
- </template>
- </AuditLogSearch>
- </div>
- <PagedAuditLogDataTable
- v-if="hasAuditLogFeature"
- ref="pagedAuditLogDataTableRef"
- :parent="parent"
- :filter="searchAuditLogs"
- />
- <NEmpty class="mx-4 py-12 border rounded-sm" v-else />
-</template>
-
-<script lang="ts" setup>
-import dayjs from "dayjs";
-import { NEmpty } from "naive-ui";
-import { computed, reactive, ref } from "vue";
-import { useI18n } from "vue-i18n";
-import AuditLogSearch from "@/components/AuditLog/AuditLogSearch";
-import { buildAuditLogFilter } from "@/components/AuditLog/AuditLogSearch/utils";
-import PagedAuditLogDataTable from "@/components/AuditLog/PagedAuditLogDataTable.vue";
-import DataExportButton from "@/components/DataExportButton.vue";
-import { FeatureAttention } from "@/components/FeatureGuard";
-import { featureToRef } from "@/store";
-import { projectNamePrefix } from "@/store/modules/v1/common";
-import { type AuditLogFilter } from "@/types";
-import { ExportFormat } from "@/types/proto-es/v1/common_pb";
-import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
-import { hasWorkspacePermissionV2, type SearchParams } from "@/utils";
-
-interface LocalState {
- params: SearchParams;
-}
-
-const defaultSearchParams = () => {
- const to = dayjs().endOf("day");
- const from = to.add(-30, "day");
- const params: SearchParams = {
- query: "",
- scopes: [
- {
- id: "created",
- value: `${from.valueOf()},${to.valueOf()}`,
- },
- ],
- };
- return params;
-};
-
-const state = reactive<LocalState>({
- params: defaultSearchParams(),
-});
-const { t } = useI18n();
-const hasAuditLogFeature = featureToRef(PlanFeature.FEATURE_AUDIT_LOG);
-const pagedAuditLogDataTableRef =
- ref<InstanceType<typeof PagedAuditLogDataTable>>();
-
-const parent = computed(() => `${projectNamePrefix}-`);
-
-const searchAuditLogs = computed((): AuditLogFilter => {
- return buildAuditLogFilter(state.params);
-});
-
-const disableExportTip = computed(() => {
- if (
- !searchAuditLogs.value.createdTsAfter ||
- !searchAuditLogs.value.createdTsBefore
- ) {
- return t("audit-log.export-tooltip");
- }
- if (
- searchAuditLogs.value.createdTsBefore -
- searchAuditLogs.value.createdTsAfter >
- 30 * 24 * 60 * 60 * 1000
- ) {
- return t("audit-log.export-tooltip");
- }
- return "";
-});
-</script>