MCPcopy Create free account
hub / github.com/bytebase/bytebase / AuditLogTable

Function AuditLogTable

frontend/src/react/components/AuditLogTable.tsx:518–864  ·  view source on GitHub ↗
({
  parent,
  canExport,
  readonlyScopes,
}: AuditLogTableProps)

Source from the content-addressed store, hash-verified

516}
517
518export function AuditLogTable({
519 parent,
520 canExport,
521 readonlyScopes,
522}: AuditLogTableProps) {
523 const { t } = useTranslation();
524 const hasAuditLogFeature = usePlanFeature(PlanFeature.FEATURE_AUDIT_LOG);
525 const columns = useColumnDefs();
526 const { widths, totalWidth, onResizeStart } = useColumnWidths(columns);
527
528 const buildDefaultParams = useCallback((): SearchParams => {
529 const to = dayjs().endOf("day");
530 const from = to.add(-30, "day");
531 return {
532 query: "",
533 scopes: [
534 ...(readonlyScopes?.map((s) => ({ ...s, readonly: true })) ?? []),
535 {
536 id: "created",
537 value: `${from.valueOf()},${to.valueOf()}`,
538 readonly: true,
539 },
540 ],
541 };
542 }, [readonlyScopes]);
543
544 const [searchParams, setSearchParams] =
545 useState<SearchParams>(buildDefaultParams);
546
547 // Reset search params when readonlyScopes change (e.g. navigating between projects).
548 const prevReadonlyScopesRef = useRef(readonlyScopes);
549 useEffect(() => {
550 if (prevReadonlyScopesRef.current !== readonlyScopes) {
551 prevReadonlyScopesRef.current = readonlyScopes;
552 setSearchParams(buildDefaultParams());
553 }
554 }, [readonlyScopes, buildDefaultParams]);
555
556 const filter = useMemo(
557 () => buildAuditLogFilter(searchParams),
558 [searchParams]
559 );
560
561 // Data fetching
562 const [auditLogs, setAuditLogs] = useState<AuditLog[]>([]);
563 const [loading, setLoading] = useState(true);
564 const nextPageTokenRef = useRef("");
565 const [hasMore, setHasMore] = useState(false);
566 const [isFetchingMore, setIsFetchingMore] = useState(false);
567 const [pageSize, setPageSize] = useSessionPageSize("bb.audit-log-table");
568 const fetchIdRef = useRef(0);
569
570 // Sort state
571 const [sortKey, setSortKey] = useState<string | null>(null);
572 const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc");
573 const orderBy = sortKey ? `${sortKey} ${sortOrder}` : "";
574
575 const toggleSort = useCallback(

Callers

nothing calls this directly

Calls 14

usePlanFeatureFunction · 0.90
useColumnWidthsFunction · 0.90
useSessionPageSizeFunction · 0.90
pushNotificationFunction · 0.90
getDefaultPaginationFunction · 0.90
getPageSizeOptionsFunction · 0.90
useColumnDefsFunction · 0.85
buildAuditLogFilterFunction · 0.85
buildFilterStringFunction · 0.85
toggleSortFunction · 0.85
addMethod · 0.80
keysMethod · 0.80

Tested by

no test coverage detected