({
parent,
canExport,
readonlyScopes,
}: AuditLogTableProps)
| 516 | } |
| 517 | |
| 518 | export 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( |
nothing calls this directly
no test coverage detected