forked from Vero-protocol/vero-core-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseAuditLogs.ts
More file actions
41 lines (36 loc) · 1.19 KB
/
Copy pathuseAuditLogs.ts
File metadata and controls
41 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* useAuditLogs — Exposes the synthetic audit entries used by the Log Export
* panel. Kept as a tiny hook so the data source can later be swapped for a
* real fetch without touching consumers.
*/
import { useMemo, useState } from "react";
import { generateAuditLog } from "../utils/auditLog";
import type { AuditEntry, AuditEventType, AuditStatus } from "../types";
export type StatusFilter = "all" | AuditStatus;
export type TypeFilter = "all" | AuditEventType;
export function useAuditLogs(initialCount: number = 60) {
const [logs] = useState<AuditEntry[]>(() => generateAuditLog(initialCount));
const [statusFilter, setStatusFilter] = useState<StatusFilter>("all");
const [typeFilter, setTypeFilter] = useState<TypeFilter>("all");
const filtered = useMemo(
() =>
logs.filter((entry) => {
if (statusFilter !== "all" && entry.status !== statusFilter) {
return false;
}
if (typeFilter !== "all" && entry.eventType !== typeFilter) {
return false;
}
return true;
}),
[logs, statusFilter, typeFilter]
);
return {
logs,
filtered,
statusFilter,
setStatusFilter,
typeFilter,
setTypeFilter,
};
}