mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-12-01 09:07:27 +08:00
feat(admin): refine operation log experience
This commit is contained in:
1 parent
5495768c3a
commit
0a4debd28a
19 files changed
+684
-454
No files matched your search
@@ -0,0 +1,104 @@
|
||||
import { useMemo, useState, type ComponentProps } from "react"
|
||||
import {
|
||||
ar,
|
||||
de,
|
||||
enUS,
|
||||
es,
|
||||
fr,
|
||||
ja,
|
||||
ko,
|
||||
ru,
|
||||
zhCN,
|
||||
zhTW,
|
||||
type Locale,
|
||||
} from "date-fns/locale"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Calendar } from "@/components/ui/calendar"
|
||||
import { Field, FieldLabel } from "@/components/ui/field"
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover"
|
||||
|
||||
const DATE_LOCALES: Record<string, Locale> = {
|
||||
ar,
|
||||
de,
|
||||
en: enUS,
|
||||
es,
|
||||
fr,
|
||||
ja,
|
||||
ko,
|
||||
ru,
|
||||
zh: zhCN,
|
||||
"zh-CN": zhCN,
|
||||
"zh-TW": zhTW,
|
||||
}
|
||||
|
||||
export function DatePickerField({
|
||||
id,
|
||||
className,
|
||||
label,
|
||||
placeholder,
|
||||
locale,
|
||||
value,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
id: string
|
||||
className?: string
|
||||
label: string
|
||||
placeholder: string
|
||||
locale: string
|
||||
value: Date | undefined
|
||||
onChange: (value: Date | undefined) => void
|
||||
disabled?: ComponentProps<typeof Calendar>["disabled"]
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const language = locale.split("-")[0]
|
||||
const calendarLocale = DATE_LOCALES[locale] ?? DATE_LOCALES[language] ?? enUS
|
||||
const formatter = useMemo(
|
||||
() => new Intl.DateTimeFormat(locale, { dateStyle: "medium" }),
|
||||
[locale]
|
||||
)
|
||||
|
||||
return (
|
||||
<Field className={cn("sm:w-48", className)}>
|
||||
<FieldLabel htmlFor={id} className="sr-only">
|
||||
{label}
|
||||
</FieldLabel>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger
|
||||
render={
|
||||
<Button
|
||||
id={id}
|
||||
type="button"
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"w-full justify-start px-2.5 font-normal",
|
||||
!value && "text-muted-foreground"
|
||||
)}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{value ? formatter.format(value) : placeholder}
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-auto p-0" align="start">
|
||||
<Calendar
|
||||
mode="single"
|
||||
selected={value}
|
||||
defaultMonth={value}
|
||||
onSelect={(date) => {
|
||||
onChange(date)
|
||||
if (date) setOpen(false)
|
||||
}}
|
||||
disabled={disabled}
|
||||
locale={calendarLocale}
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
@@ -6,8 +6,9 @@ import { cn } from "cn"
|
||||
function ScrollArea({
|
||||
className,
|
||||
children,
|
||||
horizontal = false,
|
||||
...props
|
||||
}: ScrollAreaPrimitive.Root.Props) {
|
||||
}: ScrollAreaPrimitive.Root.Props & { horizontal?: boolean }) {
|
||||
return (
|
||||
<ScrollAreaPrimitive.Root
|
||||
data-slot="scroll-area"
|
||||
@@ -21,6 +22,7 @@ function ScrollArea({
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar />
|
||||
{horizontal && <ScrollBar orientation="horizontal" />}
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
)
|
||||
@@ -37,7 +39,7 @@ function ScrollBar({
|
||||
data-orientation={orientation}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"flex touch-none p-px transition-colors select-none data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent",
|
||||
"z-20 flex touch-none p-px transition-colors select-none data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -3,9 +3,9 @@ import { enUS } from "./en-US.ts"
|
||||
export const ar = {
|
||||
audit: {
|
||||
...enUS.audit,
|
||||
since: "من",
|
||||
until: "حتى (غير شامل)",
|
||||
invalidRange: "يجب أن يسبق وقت البدء وقت الانتهاء",
|
||||
since: "تاريخ البدء",
|
||||
until: "تاريخ الانتهاء",
|
||||
invalidRange: "لا يمكن أن يكون تاريخ البدء بعد تاريخ الانتهاء",
|
||||
details: "تفاصيل التدقيق",
|
||||
target: "معرّف الهدف",
|
||||
userAgent: "وكيل المستخدم",
|
||||
@@ -735,14 +735,11 @@ export const ar = {
|
||||
description: "راجع إجراءات الإدارة والأنشطة المهمة.",
|
||||
tableTitle: "سجل التدقيق",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "البحث عن المشغّل",
|
||||
ipSearchPlaceholder: "البحث عن عنوان IP المصدر",
|
||||
requestParamsSearchPlaceholder: "البحث في معلمات الطلب",
|
||||
operatorSearchPlaceholder: "المشغّل",
|
||||
ipSearchPlaceholder: "عنوان IP المصدر",
|
||||
search: "بحث",
|
||||
actionType: "نوع الإجراء",
|
||||
result: "النتيجة",
|
||||
allActions: "كل الإجراءات",
|
||||
allResults: "كل النتائج",
|
||||
},
|
||||
columns: {
|
||||
time: "الوقت",
|
||||
@@ -751,7 +748,9 @@ export const ar = {
|
||||
requestParams: "معلمات الطلب",
|
||||
ipAddress: "عنوان IP المصدر",
|
||||
result: "النتيجة",
|
||||
operations: "الإجراءات",
|
||||
},
|
||||
details: "التفاصيل",
|
||||
categories: {
|
||||
model: "النماذج",
|
||||
member: "الأعضاء",
|
||||
|
||||
@@ -3,9 +3,9 @@ import { enUS } from "./en-US.ts"
|
||||
export const deDE = {
|
||||
audit: {
|
||||
...enUS.audit,
|
||||
since: "Von",
|
||||
until: "Bis (exklusiv)",
|
||||
invalidRange: "Der Beginn muss vor dem Ende liegen",
|
||||
since: "Startdatum",
|
||||
until: "Enddatum",
|
||||
invalidRange: "Das Startdatum darf nicht nach dem Enddatum liegen",
|
||||
details: "Audit-Details",
|
||||
target: "Ziel-ID",
|
||||
userAgent: "User-Agent",
|
||||
@@ -774,14 +774,11 @@ export const deDE = {
|
||||
"Prüfen Sie administrative Aktionen und wichtige Aktivitäten.",
|
||||
tableTitle: "Audit-Protokoll",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "Bediener suchen",
|
||||
ipSearchPlaceholder: "Quell-IP suchen",
|
||||
requestParamsSearchPlaceholder: "Anfrageparameter suchen",
|
||||
operatorSearchPlaceholder: "Bediener",
|
||||
ipSearchPlaceholder: "Quell-IP",
|
||||
search: "Suchen",
|
||||
actionType: "Aktionstyp",
|
||||
result: "Ergebnis",
|
||||
allActions: "Alle Aktionen",
|
||||
allResults: "Alle Ergebnisse",
|
||||
},
|
||||
columns: {
|
||||
time: "Zeitpunkt",
|
||||
@@ -790,7 +787,9 @@ export const deDE = {
|
||||
requestParams: "Anfrageparameter",
|
||||
ipAddress: "Quell-IP",
|
||||
result: "Ergebnis",
|
||||
operations: "Aktionen",
|
||||
},
|
||||
details: "Details",
|
||||
categories: {
|
||||
model: "Modelle",
|
||||
member: "Mitglieder",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export const enUS = {
|
||||
audit: {
|
||||
since: "From",
|
||||
until: "Until (exclusive)",
|
||||
invalidRange: "Start time must be before end time",
|
||||
since: "Start date",
|
||||
until: "End date",
|
||||
invalidRange: "Start date cannot be after end date",
|
||||
details: "Audit details",
|
||||
target: "Target ID",
|
||||
userAgent: "User agent",
|
||||
@@ -1001,14 +1001,11 @@ export const enUS = {
|
||||
description: "Review administrative actions and important activity.",
|
||||
tableTitle: "Audit log",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "Search operator",
|
||||
ipSearchPlaceholder: "Search source IP",
|
||||
requestParamsSearchPlaceholder: "Search request parameters",
|
||||
operatorSearchPlaceholder: "Operator",
|
||||
ipSearchPlaceholder: "Source IP",
|
||||
search: "Search",
|
||||
actionType: "Action type",
|
||||
result: "Result",
|
||||
allActions: "All actions",
|
||||
allResults: "All results",
|
||||
},
|
||||
columns: {
|
||||
time: "Time",
|
||||
@@ -1017,7 +1014,9 @@ export const enUS = {
|
||||
requestParams: "Request parameters",
|
||||
ipAddress: "Source IP",
|
||||
result: "Result",
|
||||
operations: "Actions",
|
||||
},
|
||||
details: "Details",
|
||||
categories: {
|
||||
model: "Models",
|
||||
member: "Members",
|
||||
|
||||
@@ -3,9 +3,9 @@ import { enUS } from "./en-US.ts"
|
||||
export const es419 = {
|
||||
audit: {
|
||||
...enUS.audit,
|
||||
since: "Desde",
|
||||
until: "Hasta (exclusivo)",
|
||||
invalidRange: "El inicio debe ser anterior al final",
|
||||
since: "Fecha de inicio",
|
||||
until: "Fecha de fin",
|
||||
invalidRange: "La fecha de inicio no puede ser posterior a la fecha de fin",
|
||||
details: "Detalles de auditoría",
|
||||
target: "ID del destino",
|
||||
userAgent: "Agente de usuario",
|
||||
@@ -763,14 +763,11 @@ export const es419 = {
|
||||
"Consulta las acciones administrativas y la actividad importante.",
|
||||
tableTitle: "Registro de auditoría",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "Buscar operador",
|
||||
ipSearchPlaceholder: "Buscar IP de origen",
|
||||
requestParamsSearchPlaceholder: "Buscar parámetros de solicitud",
|
||||
operatorSearchPlaceholder: "Operador",
|
||||
ipSearchPlaceholder: "IP de origen",
|
||||
search: "Buscar",
|
||||
actionType: "Tipo de acción",
|
||||
result: "Resultado",
|
||||
allActions: "Todas las acciones",
|
||||
allResults: "Todos los resultados",
|
||||
},
|
||||
columns: {
|
||||
time: "Fecha y hora",
|
||||
@@ -779,7 +776,9 @@ export const es419 = {
|
||||
requestParams: "Parámetros de solicitud",
|
||||
ipAddress: "IP de origen",
|
||||
result: "Resultado",
|
||||
operations: "Acciones",
|
||||
},
|
||||
details: "Detalles",
|
||||
categories: {
|
||||
model: "Modelos",
|
||||
member: "Miembros",
|
||||
|
||||
@@ -3,9 +3,10 @@ import { enUS } from "./en-US.ts"
|
||||
export const frFR = {
|
||||
audit: {
|
||||
...enUS.audit,
|
||||
since: "Début",
|
||||
until: "Fin (exclue)",
|
||||
invalidRange: "Le début doit précéder la fin",
|
||||
since: "Date de début",
|
||||
until: "Date de fin",
|
||||
invalidRange:
|
||||
"La date de début ne peut pas être postérieure à la date de fin",
|
||||
details: "Détails de l’audit",
|
||||
target: "ID de la cible",
|
||||
userAgent: "Agent utilisateur",
|
||||
@@ -765,14 +766,11 @@ export const frFR = {
|
||||
"Consultez les actions administratives et les activités importantes.",
|
||||
tableTitle: "Journal d’audit",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "Rechercher un opérateur",
|
||||
ipSearchPlaceholder: "Rechercher une IP source",
|
||||
requestParamsSearchPlaceholder: "Rechercher des paramètres de requête",
|
||||
operatorSearchPlaceholder: "Opérateur",
|
||||
ipSearchPlaceholder: "IP source",
|
||||
search: "Rechercher",
|
||||
actionType: "Type d’action",
|
||||
result: "Résultat",
|
||||
allActions: "Toutes les actions",
|
||||
allResults: "Tous les résultats",
|
||||
},
|
||||
columns: {
|
||||
time: "Date et heure",
|
||||
@@ -781,7 +779,9 @@ export const frFR = {
|
||||
requestParams: "Paramètres de la requête",
|
||||
ipAddress: "IP source",
|
||||
result: "Résultat",
|
||||
operations: "Actions",
|
||||
},
|
||||
details: "Détails",
|
||||
categories: {
|
||||
model: "Modèles",
|
||||
member: "Membres",
|
||||
|
||||
@@ -3,9 +3,9 @@ import { enUS } from "./en-US.ts"
|
||||
export const jaJP = {
|
||||
audit: {
|
||||
...enUS.audit,
|
||||
since: "開始日時",
|
||||
until: "終了日時(含まない)",
|
||||
invalidRange: "開始日時は終了日時より前にしてください",
|
||||
since: "開始日",
|
||||
until: "終了日",
|
||||
invalidRange: "開始日は終了日より後にできません",
|
||||
details: "監査の詳細",
|
||||
target: "対象 ID",
|
||||
userAgent: "ユーザーエージェント",
|
||||
@@ -747,14 +747,11 @@ export const jaJP = {
|
||||
description: "管理操作と重要なアクティビティを確認します。",
|
||||
tableTitle: "監査ログ",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "操作者を検索",
|
||||
ipSearchPlaceholder: "送信元 IP を検索",
|
||||
requestParamsSearchPlaceholder: "リクエストパラメータを検索",
|
||||
operatorSearchPlaceholder: "操作者",
|
||||
ipSearchPlaceholder: "送信元 IP",
|
||||
search: "検索",
|
||||
actionType: "操作タイプ",
|
||||
result: "実行結果",
|
||||
allActions: "すべての操作",
|
||||
allResults: "すべての結果",
|
||||
},
|
||||
columns: {
|
||||
time: "日時",
|
||||
@@ -763,7 +760,9 @@ export const jaJP = {
|
||||
requestParams: "リクエストパラメータ",
|
||||
ipAddress: "送信元 IP",
|
||||
result: "結果",
|
||||
operations: "操作",
|
||||
},
|
||||
details: "詳細",
|
||||
categories: {
|
||||
model: "モデル",
|
||||
member: "メンバー",
|
||||
|
||||
@@ -3,9 +3,9 @@ import { enUS } from "./en-US.ts"
|
||||
export const koKR = {
|
||||
audit: {
|
||||
...enUS.audit,
|
||||
since: "시작 시간",
|
||||
until: "종료 시간 (미포함)",
|
||||
invalidRange: "시작 시간은 종료 시간보다 빨라야 합니다",
|
||||
since: "시작 날짜",
|
||||
until: "종료 날짜",
|
||||
invalidRange: "시작 날짜는 종료 날짜보다 늦을 수 없습니다",
|
||||
details: "감사 상세 정보",
|
||||
target: "대상 ID",
|
||||
userAgent: "사용자 에이전트",
|
||||
@@ -737,14 +737,11 @@ export const koKR = {
|
||||
description: "관리자 작업과 주요 활동 기록을 확인합니다.",
|
||||
tableTitle: "감사 로그",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "작업자 검색",
|
||||
ipSearchPlaceholder: "소스 IP 검색",
|
||||
requestParamsSearchPlaceholder: "요청 매개변수 검색",
|
||||
operatorSearchPlaceholder: "작업자",
|
||||
ipSearchPlaceholder: "소스 IP",
|
||||
search: "검색",
|
||||
actionType: "작업 유형",
|
||||
result: "실행 결과",
|
||||
allActions: "모든 작업",
|
||||
allResults: "모든 결과",
|
||||
},
|
||||
columns: {
|
||||
time: "시간",
|
||||
@@ -753,7 +750,9 @@ export const koKR = {
|
||||
requestParams: "요청 매개변수",
|
||||
ipAddress: "소스 IP",
|
||||
result: "결과",
|
||||
operations: "작업",
|
||||
},
|
||||
details: "상세",
|
||||
categories: {
|
||||
model: "모델",
|
||||
member: "멤버",
|
||||
|
||||
@@ -3,9 +3,9 @@ import { enUS } from "./en-US.ts"
|
||||
export const ruRU = {
|
||||
audit: {
|
||||
...enUS.audit,
|
||||
since: "Начало",
|
||||
until: "Конец (не включительно)",
|
||||
invalidRange: "Начало должно предшествовать концу",
|
||||
since: "Дата начала",
|
||||
until: "Дата окончания",
|
||||
invalidRange: "Дата начала не может быть позже даты окончания",
|
||||
details: "Подробности аудита",
|
||||
target: "ID объекта",
|
||||
userAgent: "User-Agent",
|
||||
@@ -761,14 +761,11 @@ export const ruRU = {
|
||||
description: "Просматривайте действия администраторов и важные события.",
|
||||
tableTitle: "Журнал аудита",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "Поиск оператора",
|
||||
ipSearchPlaceholder: "Поиск исходного IP",
|
||||
requestParamsSearchPlaceholder: "Поиск параметров запроса",
|
||||
operatorSearchPlaceholder: "Оператор",
|
||||
ipSearchPlaceholder: "Исходный IP",
|
||||
search: "Найти",
|
||||
actionType: "Тип действия",
|
||||
result: "Результат",
|
||||
allActions: "Все действия",
|
||||
allResults: "Все результаты",
|
||||
},
|
||||
columns: {
|
||||
time: "Время",
|
||||
@@ -777,7 +774,9 @@ export const ruRU = {
|
||||
requestParams: "Параметры запроса",
|
||||
ipAddress: "Исходный IP",
|
||||
result: "Результат",
|
||||
operations: "Действия",
|
||||
},
|
||||
details: "Подробнее",
|
||||
categories: {
|
||||
model: "Модели",
|
||||
member: "Участники",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export const zhCN = {
|
||||
audit: {
|
||||
since: "开始时间",
|
||||
until: "结束时间(不含)",
|
||||
invalidRange: "开始时间必须早于结束时间",
|
||||
since: "开始日期",
|
||||
until: "结束日期",
|
||||
invalidRange: "开始日期不能晚于结束日期",
|
||||
details: "审计详情",
|
||||
target: "目标 ID",
|
||||
userAgent: "客户端",
|
||||
@@ -940,14 +940,11 @@ export const zhCN = {
|
||||
description: "查看后台管理操作和关键行为记录。",
|
||||
tableTitle: "审计日志",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "搜索操作者",
|
||||
ipSearchPlaceholder: "搜索来源 IP",
|
||||
requestParamsSearchPlaceholder: "搜索请求参数",
|
||||
operatorSearchPlaceholder: "操作者",
|
||||
ipSearchPlaceholder: "来源 IP",
|
||||
search: "搜索",
|
||||
actionType: "操作类型",
|
||||
result: "执行结果",
|
||||
allActions: "全部操作",
|
||||
allResults: "全部结果",
|
||||
result: "结果",
|
||||
},
|
||||
columns: {
|
||||
time: "时间",
|
||||
@@ -956,7 +953,9 @@ export const zhCN = {
|
||||
requestParams: "请求参数",
|
||||
ipAddress: "来源 IP",
|
||||
result: "结果",
|
||||
operations: "操作",
|
||||
},
|
||||
details: "详情",
|
||||
categories: {
|
||||
model: "模型",
|
||||
member: "成员",
|
||||
|
||||
@@ -3,9 +3,9 @@ import { enUS } from "./en-US.ts"
|
||||
export const zhTW = {
|
||||
audit: {
|
||||
...enUS.audit,
|
||||
since: "開始時間",
|
||||
until: "結束時間(不含)",
|
||||
invalidRange: "開始時間必須早於結束時間",
|
||||
since: "開始日期",
|
||||
until: "結束日期",
|
||||
invalidRange: "開始日期不能晚於結束日期",
|
||||
details: "稽核詳情",
|
||||
target: "目標 ID",
|
||||
userAgent: "用戶端",
|
||||
@@ -703,14 +703,11 @@ export const zhTW = {
|
||||
description: "查看後台管理操作和重要行為記錄。",
|
||||
tableTitle: "稽核日誌",
|
||||
filters: {
|
||||
operatorSearchPlaceholder: "搜尋操作者",
|
||||
ipSearchPlaceholder: "搜尋來源 IP",
|
||||
requestParamsSearchPlaceholder: "搜尋請求參數",
|
||||
operatorSearchPlaceholder: "操作者",
|
||||
ipSearchPlaceholder: "來源 IP",
|
||||
search: "搜尋",
|
||||
actionType: "操作類型",
|
||||
result: "執行結果",
|
||||
allActions: "全部操作",
|
||||
allResults: "全部結果",
|
||||
result: "結果",
|
||||
},
|
||||
columns: {
|
||||
time: "時間",
|
||||
@@ -719,7 +716,9 @@ export const zhTW = {
|
||||
requestParams: "請求參數",
|
||||
ipAddress: "來源 IP",
|
||||
result: "結果",
|
||||
operations: "操作",
|
||||
},
|
||||
details: "詳情",
|
||||
categories: {
|
||||
model: "模型",
|
||||
member: "成員",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
export function startOfLocalDay(value: Date): Date {
|
||||
const date = new Date(value)
|
||||
date.setHours(0, 0, 0, 0)
|
||||
return date
|
||||
}
|
||||
|
||||
export function endOfLocalDay(value: Date): Date {
|
||||
const date = new Date(value)
|
||||
date.setHours(23, 59, 59, 999)
|
||||
return date
|
||||
}
|
||||
@@ -263,7 +263,7 @@ export function MembersAndGroupsPage() {
|
||||
]
|
||||
|
||||
return (
|
||||
<section className="flex flex-1 flex-col p-4 pt-px md:h-[calc(100svh-4rem)] md:min-h-0 md:flex-none md:overflow-hidden">
|
||||
<section className="flex flex-1 flex-col p-4 pt-px md:h-[calc(100svh-5rem)] md:min-h-0 md:flex-none md:overflow-hidden">
|
||||
{error && (
|
||||
<p
|
||||
className="mb-3 rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-sm text-destructive"
|
||||
|
||||
@@ -1,36 +1,38 @@
|
||||
import { useEffect, useMemo, useState, type KeyboardEvent } from "react"
|
||||
import {
|
||||
ArrowLeft02Icon,
|
||||
ArrowLeft01Icon,
|
||||
ArrowRight01Icon,
|
||||
Search02Icon,
|
||||
User02Icon,
|
||||
} from "@hugeicons/core-free-icons"
|
||||
import { HugeiconsIcon } from "@hugeicons/react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { DatePickerField } from "@/components/date-picker-field"
|
||||
import { api } from "@/lib/api"
|
||||
import { endOfLocalDay, startOfLocalDay } from "@/lib/date-range"
|
||||
import { cn } from "@/lib/utils"
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog"
|
||||
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent } from "@/components/ui/card"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -73,12 +75,11 @@ type AuditPage = {
|
||||
page: number
|
||||
page_size: number
|
||||
}
|
||||
type CategoryFilter = "all" | LogCategory
|
||||
type ResultFilter = "all" | LogResult
|
||||
const DEFAULT_PAGE_SIZE = 20
|
||||
type CategoryFilter = LogCategory | null
|
||||
type ResultFilter = LogResult | null
|
||||
const DEFAULT_PAGE_SIZE = 50
|
||||
const PAGE_SIZE_OPTIONS = ["20", "50", "100", "200", "500"]
|
||||
const CATEGORY_FILTERS: CategoryFilter[] = [
|
||||
"all",
|
||||
const CATEGORY_FILTERS: LogCategory[] = [
|
||||
"model",
|
||||
"identity",
|
||||
"resource",
|
||||
@@ -86,23 +87,21 @@ const CATEGORY_FILTERS: CategoryFilter[] = [
|
||||
"security",
|
||||
"settings",
|
||||
]
|
||||
const RESULT_FILTERS: ResultFilter[] = ["all", "success", "failed"]
|
||||
const RESULT_FILTERS: LogResult[] = ["success", "failed"]
|
||||
|
||||
export function OperationLogsPage() {
|
||||
const { i18n, t } = useTranslation()
|
||||
const [operatorInput, setOperatorInput] = useState("")
|
||||
const [ipInput, setIpInput] = useState("")
|
||||
const [requestParamsInput, setRequestParamsInput] = useState("")
|
||||
const [categoryInput, setCategoryInput] = useState<CategoryFilter>("all")
|
||||
const [resultInput, setResultInput] = useState<ResultFilter>("all")
|
||||
const [categoryInput, setCategoryInput] = useState<CategoryFilter>(null)
|
||||
const [resultInput, setResultInput] = useState<ResultFilter>(null)
|
||||
const [operatorQuery, setOperatorQuery] = useState("")
|
||||
const [ipQuery, setIpQuery] = useState("")
|
||||
const [requestParamsQuery, setRequestParamsQuery] = useState("")
|
||||
const [category, setCategory] = useState<CategoryFilter>("all")
|
||||
const [result, setResult] = useState<ResultFilter>("all")
|
||||
const [category, setCategory] = useState<CategoryFilter>(null)
|
||||
const [result, setResult] = useState<ResultFilter>(null)
|
||||
const [revision, setRevision] = useState(0)
|
||||
const [sinceInput, setSinceInput] = useState("")
|
||||
const [untilInput, setUntilInput] = useState("")
|
||||
const [sinceInput, setSinceInput] = useState<Date>()
|
||||
const [untilInput, setUntilInput] = useState<Date>()
|
||||
const [since, setSince] = useState("")
|
||||
const [until, setUntil] = useState("")
|
||||
const [invalidRange, setInvalidRange] = useState(false)
|
||||
@@ -115,14 +114,9 @@ export function OperationLogsPage() {
|
||||
const [page, setPage] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(DEFAULT_PAGE_SIZE)
|
||||
|
||||
const categoryLabel = (value: CategoryFilter) =>
|
||||
value === "all"
|
||||
? t("pages.operationLogs.filters.allActions")
|
||||
: t(`audit.categories.${value}`)
|
||||
const resultLabel = (value: ResultFilter) =>
|
||||
value === "all"
|
||||
? t("pages.operationLogs.filters.allResults")
|
||||
: t(`pages.operationLogs.results.${value}`)
|
||||
const categoryLabel = (value: LogCategory) => t(`audit.categories.${value}`)
|
||||
const resultLabel = (value: LogResult) =>
|
||||
t(`pages.operationLogs.results.${value}`)
|
||||
|
||||
const query = new URLSearchParams({
|
||||
page: String(page),
|
||||
@@ -131,9 +125,8 @@ export function OperationLogsPage() {
|
||||
for (const [key, value] of Object.entries({
|
||||
actor: operatorQuery,
|
||||
ip: ipQuery,
|
||||
params: requestParamsQuery,
|
||||
category: category === "all" ? "" : category,
|
||||
result: result === "all" ? "" : result,
|
||||
category: category ?? "",
|
||||
result: result ?? "",
|
||||
since,
|
||||
until,
|
||||
})) {
|
||||
@@ -169,14 +162,15 @@ export function OperationLogsPage() {
|
||||
const lastVisible =
|
||||
visibleLogs.length === 0 ? 0 : pageStart + visibleLogs.length
|
||||
const actionLabel = (log: AuditLog) =>
|
||||
`${t(`audit.actions.${log.action}`, { defaultValue: log.action })} · ${t(`audit.targets.${log.target_type}`, { defaultValue: log.target_type ?? categoryLabel(log.category) })}`
|
||||
`${t(`audit.targets.${log.target_type}`, { defaultValue: log.target_type ?? categoryLabel(log.category) })} - ${t(`audit.actions.${log.action}`, { defaultValue: log.action })}`
|
||||
const pageSizeItems = PAGE_SIZE_OPTIONS.map((value) => ({
|
||||
value,
|
||||
label: t("pages.operationLogs.pagination.perPage", { count: value }),
|
||||
}))
|
||||
const locale = i18n.resolvedLanguage ?? i18n.language
|
||||
const dateFormatter = useMemo(
|
||||
() =>
|
||||
new Intl.DateTimeFormat(i18n.language, {
|
||||
new Intl.DateTimeFormat(locale, {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
@@ -185,25 +179,13 @@ export function OperationLogsPage() {
|
||||
second: "2-digit",
|
||||
hour12: false,
|
||||
}),
|
||||
[i18n.language]
|
||||
[locale]
|
||||
)
|
||||
|
||||
const updateCategory = (value: string) => {
|
||||
setCategoryInput(value as CategoryFilter)
|
||||
}
|
||||
|
||||
const updateResult = (value: string) => {
|
||||
setResultInput(value as ResultFilter)
|
||||
}
|
||||
|
||||
const applySearch = () => {
|
||||
const start = sinceInput ? new Date(sinceInput) : undefined
|
||||
const end = untilInput ? new Date(untilInput) : undefined
|
||||
if (
|
||||
(start && !Number.isFinite(start.getTime())) ||
|
||||
(end && !Number.isFinite(end.getTime())) ||
|
||||
(start && end && start >= end)
|
||||
) {
|
||||
const start = sinceInput ? startOfLocalDay(sinceInput) : undefined
|
||||
const end = untilInput ? endOfLocalDay(untilInput) : undefined
|
||||
if (start && end && start > end) {
|
||||
setInvalidRange(true)
|
||||
return
|
||||
}
|
||||
@@ -213,7 +195,6 @@ export function OperationLogsPage() {
|
||||
setRevision((value) => value + 1)
|
||||
setOperatorQuery(operatorInput)
|
||||
setIpQuery(ipInput)
|
||||
setRequestParamsQuery(requestParamsInput)
|
||||
setCategory(categoryInput)
|
||||
setResult(resultInput)
|
||||
setPage(1)
|
||||
@@ -227,12 +208,12 @@ export function OperationLogsPage() {
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="flex min-h-0 flex-1 flex-col p-4 pt-0">
|
||||
<Card>
|
||||
<CardContent className="gap-4 px-0">
|
||||
<section className="flex min-h-0 flex-1 flex-col p-4 pt-px md:h-[calc(100svh-5rem)] md:flex-none md:overflow-hidden">
|
||||
<Card className="min-h-0 flex-1">
|
||||
<CardContent className="min-h-0 flex-1 gap-4 px-0">
|
||||
<div className="flex flex-wrap items-center gap-2 px-(--card-spacing)">
|
||||
<Input
|
||||
className="w-48"
|
||||
className="w-32"
|
||||
value={operatorInput}
|
||||
onChange={(event) => setOperatorInput(event.target.value)}
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
@@ -244,66 +225,94 @@ export function OperationLogsPage() {
|
||||
)}
|
||||
/>
|
||||
<Input
|
||||
className="w-48"
|
||||
className="w-32"
|
||||
value={ipInput}
|
||||
onChange={(event) => setIpInput(event.target.value)}
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
placeholder={t("pages.operationLogs.filters.ipSearchPlaceholder")}
|
||||
aria-label={t("pages.operationLogs.filters.ipSearchPlaceholder")}
|
||||
/>
|
||||
<Input
|
||||
className="w-48"
|
||||
value={requestParamsInput}
|
||||
onChange={(event) => setRequestParamsInput(event.target.value)}
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
placeholder={t(
|
||||
"pages.operationLogs.filters.requestParamsSearchPlaceholder"
|
||||
)}
|
||||
aria-label={t(
|
||||
"pages.operationLogs.filters.requestParamsSearchPlaceholder"
|
||||
)}
|
||||
<DatePickerField
|
||||
id="audit-start-date"
|
||||
className="w-32 sm:w-32"
|
||||
label={t("audit.since")}
|
||||
placeholder={t("audit.since")}
|
||||
locale={locale}
|
||||
value={sinceInput}
|
||||
onChange={setSinceInput}
|
||||
disabled={untilInput ? { after: untilInput } : undefined}
|
||||
/>
|
||||
<DatePickerField
|
||||
id="audit-end-date"
|
||||
className="w-32 sm:w-32"
|
||||
label={t("audit.until")}
|
||||
placeholder={t("audit.until")}
|
||||
locale={locale}
|
||||
value={untilInput}
|
||||
onChange={setUntilInput}
|
||||
disabled={sinceInput ? { before: sinceInput } : undefined}
|
||||
/>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger render={<Button variant="outline" />}>
|
||||
{categoryLabel(categoryInput)}
|
||||
<DropdownMenuTrigger
|
||||
render={
|
||||
<Button
|
||||
variant="outline"
|
||||
className={cn(!categoryInput && "text-muted-foreground")}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{categoryInput
|
||||
? categoryLabel(categoryInput)
|
||||
: t("pages.operationLogs.filters.actionType")}
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuLabel>
|
||||
{t("pages.operationLogs.filters.actionType")}
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuRadioGroup
|
||||
value={categoryInput}
|
||||
onValueChange={updateCategory}
|
||||
>
|
||||
{CATEGORY_FILTERS.map((value) => (
|
||||
<DropdownMenuRadioItem key={value} value={value}>
|
||||
{categoryLabel(value)}
|
||||
</DropdownMenuRadioItem>
|
||||
))}
|
||||
</DropdownMenuRadioGroup>
|
||||
{CATEGORY_FILTERS.map((value) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={value}
|
||||
checked={categoryInput === value}
|
||||
onCheckedChange={(checked) =>
|
||||
setCategoryInput(checked ? value : null)
|
||||
}
|
||||
>
|
||||
{categoryLabel(value)}
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger render={<Button variant="outline" />}>
|
||||
{resultLabel(resultInput)}
|
||||
<DropdownMenuTrigger
|
||||
render={
|
||||
<Button
|
||||
variant="outline"
|
||||
className={cn(!resultInput && "text-muted-foreground")}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{resultInput
|
||||
? resultLabel(resultInput)
|
||||
: t("pages.operationLogs.filters.result")}
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuLabel>
|
||||
{t("pages.operationLogs.filters.result")}
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuRadioGroup
|
||||
value={resultInput}
|
||||
onValueChange={updateResult}
|
||||
>
|
||||
{RESULT_FILTERS.map((value) => (
|
||||
<DropdownMenuRadioItem key={value} value={value}>
|
||||
{resultLabel(value)}
|
||||
</DropdownMenuRadioItem>
|
||||
))}
|
||||
</DropdownMenuRadioGroup>
|
||||
{RESULT_FILTERS.map((value) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={value}
|
||||
checked={resultInput === value}
|
||||
onCheckedChange={(checked) =>
|
||||
setResultInput(checked ? value : null)
|
||||
}
|
||||
>
|
||||
{resultLabel(value)}
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
@@ -311,36 +320,6 @@ export function OperationLogsPage() {
|
||||
<HugeiconsIcon icon={Search02Icon} data-icon="inline-start" />
|
||||
{t("pages.operationLogs.filters.search")}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 px-(--card-spacing)">
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
{t("audit.since")}
|
||||
<Input
|
||||
type="datetime-local"
|
||||
className="w-auto"
|
||||
value={sinceInput}
|
||||
onChange={(event) => setSinceInput(event.target.value)}
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
aria-invalid={invalidRange}
|
||||
aria-describedby={
|
||||
invalidRange ? "audit-range-error" : undefined
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
{t("audit.until")}
|
||||
<Input
|
||||
type="datetime-local"
|
||||
className="w-auto"
|
||||
value={untilInput}
|
||||
onChange={(event) => setUntilInput(event.target.value)}
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
aria-invalid={invalidRange}
|
||||
aria-describedby={
|
||||
invalidRange ? "audit-range-error" : undefined
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
{invalidRange && (
|
||||
<p
|
||||
id="audit-range-error"
|
||||
@@ -365,158 +344,165 @@ export function OperationLogsPage() {
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<Table
|
||||
className="min-w-4xl"
|
||||
aria-label={t("pages.operationLogs.tableTitle")}
|
||||
aria-busy={loading}
|
||||
<ScrollArea
|
||||
horizontal
|
||||
className="min-h-0 flex-1 [&_[data-slot=table-container]]:overflow-visible"
|
||||
>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="ps-(--card-spacing)">
|
||||
{t("pages.operationLogs.columns.time")}
|
||||
</TableHead>
|
||||
<TableHead>
|
||||
{t("pages.operationLogs.columns.operator")}
|
||||
</TableHead>
|
||||
<TableHead>{t("pages.operationLogs.columns.action")}</TableHead>
|
||||
<TableHead>
|
||||
{t("pages.operationLogs.columns.requestParams")}
|
||||
</TableHead>
|
||||
<TableHead>
|
||||
{t("pages.operationLogs.columns.ipAddress")}
|
||||
</TableHead>
|
||||
<TableHead className="pe-(--card-spacing)">
|
||||
{t("pages.operationLogs.columns.result")}
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{visibleLogs.length > 0 ? (
|
||||
visibleLogs.map((log) => (
|
||||
<TableRow key={log.id}>
|
||||
<TableCell className="ps-(--card-spacing) text-muted-foreground">
|
||||
{dateFormatter.format(new Date(log.occurred_at))}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div
|
||||
className="flex max-w-52 items-center gap-3"
|
||||
title={log.actor_email ?? undefined}
|
||||
>
|
||||
<Avatar className="size-6">
|
||||
<AvatarFallback>
|
||||
{log.actor_name.slice(0, 2)}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<span className="truncate font-medium">
|
||||
{log.actor_name}
|
||||
</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span>{actionLabel(log)}</span>
|
||||
{log.target_id && (
|
||||
<div
|
||||
className="max-w-52 truncate font-mono text-xs text-muted-foreground"
|
||||
title={log.target_id}
|
||||
<Table
|
||||
className="min-w-4xl"
|
||||
aria-label={t("pages.operationLogs.tableTitle")}
|
||||
aria-busy={loading}
|
||||
>
|
||||
<TableHeader className="sticky top-0 z-10 bg-card [&_th]:shadow-[inset_0_-1px_0_var(--border)] [&_tr]:border-b-0">
|
||||
<TableRow>
|
||||
<TableHead className="ps-(--card-spacing)">
|
||||
{t("pages.operationLogs.columns.time")}
|
||||
</TableHead>
|
||||
<TableHead>
|
||||
{t("pages.operationLogs.columns.result")}
|
||||
</TableHead>
|
||||
<TableHead>
|
||||
{t("pages.operationLogs.columns.operator")}
|
||||
</TableHead>
|
||||
<TableHead>
|
||||
{t("pages.operationLogs.columns.action")}
|
||||
</TableHead>
|
||||
<TableHead>
|
||||
{t("pages.operationLogs.columns.ipAddress")}
|
||||
</TableHead>
|
||||
<TableHead className="pe-(--card-spacing)">
|
||||
{t("pages.operationLogs.columns.operations")}
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{visibleLogs.length > 0 ? (
|
||||
visibleLogs.map((log) => (
|
||||
<TableRow key={log.id}>
|
||||
<TableCell className="ps-(--card-spacing) text-muted-foreground">
|
||||
{dateFormatter.format(new Date(log.occurred_at))}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge
|
||||
variant={
|
||||
log.result === "success"
|
||||
? "secondary"
|
||||
: "destructive"
|
||||
}
|
||||
>
|
||||
{log.target_id}
|
||||
{resultLabel(log.result)}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div
|
||||
className="flex max-w-52 items-center gap-3"
|
||||
title={log.actor_email ?? undefined}
|
||||
>
|
||||
<HugeiconsIcon
|
||||
icon={User02Icon}
|
||||
className="size-4 shrink-0 text-blue-600 dark:text-blue-400"
|
||||
strokeWidth={2}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="truncate font-medium">
|
||||
{log.actor_name}
|
||||
</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>{actionLabel(log)}</TableCell>
|
||||
<TableCell className="font-mono text-muted-foreground">
|
||||
{log.source_ip || "—"}
|
||||
</TableCell>
|
||||
<TableCell className="pe-(--card-spacing)">
|
||||
<Dialog>
|
||||
<DialogTrigger
|
||||
render={
|
||||
<Button
|
||||
variant="outline"
|
||||
size="xs"
|
||||
type="button"
|
||||
/>
|
||||
}
|
||||
>
|
||||
{t("pages.operationLogs.details")}
|
||||
</DialogTrigger>
|
||||
<DialogContent
|
||||
className="sm:max-w-2xl"
|
||||
closeLabel={t("common.close")}
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("audit.details")}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="max-h-[65vh] space-y-3 overflow-auto">
|
||||
<dl className="grid grid-cols-[9rem_minmax(0,1fr)] gap-x-4 gap-y-2 text-sm">
|
||||
{[
|
||||
[
|
||||
t("pages.operationLogs.columns.time"),
|
||||
dateFormatter.format(
|
||||
new Date(log.occurred_at)
|
||||
),
|
||||
],
|
||||
[
|
||||
t("pages.operationLogs.columns.operator"),
|
||||
log.actor_email
|
||||
? `${log.actor_name} (${log.actor_email})`
|
||||
: log.actor_name,
|
||||
],
|
||||
[
|
||||
t("pages.operationLogs.columns.action"),
|
||||
actionLabel(log),
|
||||
],
|
||||
[t("audit.target"), log.target_id],
|
||||
[
|
||||
t("pages.operationLogs.columns.ipAddress"),
|
||||
log.source_ip,
|
||||
],
|
||||
[t("audit.userAgent"), log.user_agent],
|
||||
[t("audit.requestId"), log.request_id],
|
||||
[
|
||||
t("pages.operationLogs.columns.result"),
|
||||
resultLabel(log.result),
|
||||
],
|
||||
[t("audit.error"), log.error_message],
|
||||
].map(([label, value]) => (
|
||||
<div key={label} className="contents">
|
||||
<dt className="text-muted-foreground">
|
||||
{label}
|
||||
</dt>
|
||||
<dd className="break-all">
|
||||
{value || "—"}
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
<pre className="rounded-md bg-muted p-3 text-xs break-all whitespace-pre-wrap">
|
||||
{JSON.stringify(log.request_params, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={6}
|
||||
className="h-40 text-center text-muted-foreground"
|
||||
>
|
||||
{loading ? (
|
||||
<span role="status">{t("resources.loading")}</span>
|
||||
) : error ? (
|
||||
"—"
|
||||
) : (
|
||||
t("pages.operationLogs.empty")
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Dialog>
|
||||
<DialogTrigger
|
||||
render={
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="max-w-80 justify-start font-mono text-xs"
|
||||
/>
|
||||
}
|
||||
aria-label={t("audit.details")}
|
||||
>
|
||||
<span className="truncate">
|
||||
{JSON.stringify(log.request_params)}
|
||||
</span>
|
||||
</DialogTrigger>
|
||||
<DialogContent
|
||||
className="sm:max-w-2xl"
|
||||
closeLabel={t("common.close")}
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("audit.details")}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{dateFormatter.format(new Date(log.occurred_at))}{" "}
|
||||
· {log.actor_name} · {actionLabel(log)}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="max-h-[65vh] space-y-3 overflow-auto">
|
||||
<dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-sm">
|
||||
{[
|
||||
[t("audit.target"), log.target_id],
|
||||
[
|
||||
t("pages.operationLogs.columns.operator"),
|
||||
log.actor_email,
|
||||
],
|
||||
[
|
||||
t("pages.operationLogs.columns.ipAddress"),
|
||||
log.source_ip,
|
||||
],
|
||||
[t("audit.userAgent"), log.user_agent],
|
||||
[t("audit.requestId"), log.request_id],
|
||||
[
|
||||
t("pages.operationLogs.columns.result"),
|
||||
resultLabel(log.result),
|
||||
],
|
||||
[t("audit.error"), log.error_message],
|
||||
].map(([label, value]) => (
|
||||
<div key={label} className="contents">
|
||||
<dt className="text-muted-foreground">
|
||||
{label}
|
||||
</dt>
|
||||
<dd className="break-all">{value || "—"}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
<pre className="rounded-md bg-muted p-3 text-xs break-all whitespace-pre-wrap">
|
||||
{JSON.stringify(log.request_params, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-muted-foreground">
|
||||
{log.source_ip || "—"}
|
||||
</TableCell>
|
||||
<TableCell className="pe-(--card-spacing)">
|
||||
<Badge
|
||||
variant={
|
||||
log.result === "success" ? "secondary" : "destructive"
|
||||
}
|
||||
>
|
||||
{resultLabel(log.result)}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={6}
|
||||
className="h-40 text-center text-muted-foreground"
|
||||
>
|
||||
{loading ? (
|
||||
<span role="status">{t("resources.loading")}</span>
|
||||
) : error ? (
|
||||
"—"
|
||||
) : (
|
||||
t("pages.operationLogs.empty")
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</ScrollArea>
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 px-(--card-spacing)">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<Select
|
||||
@@ -569,7 +555,7 @@ export function OperationLogsPage() {
|
||||
aria-label={t("pages.operationLogs.pagination.previous")}
|
||||
>
|
||||
<HugeiconsIcon
|
||||
icon={ArrowLeft02Icon}
|
||||
icon={ArrowLeft01Icon}
|
||||
className="rtl:rotate-180"
|
||||
/>
|
||||
</Button>
|
||||
|
||||
@@ -2,39 +2,20 @@ import { useMemo, useState, type FormEvent } from "react"
|
||||
import {
|
||||
ArrowLeft02Icon,
|
||||
ArrowRight01Icon,
|
||||
Calendar03Icon,
|
||||
Search02Icon,
|
||||
} from "@hugeicons/core-free-icons"
|
||||
import { HugeiconsIcon } from "@hugeicons/react"
|
||||
import { addDays, startOfDay } from "date-fns"
|
||||
import {
|
||||
ar,
|
||||
de,
|
||||
enUS,
|
||||
es,
|
||||
fr,
|
||||
ja,
|
||||
ko,
|
||||
ru,
|
||||
zhCN,
|
||||
zhTW,
|
||||
type Locale,
|
||||
} from "date-fns/locale"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useStatistics } from "@/hooks/use-statistics"
|
||||
import { StatisticsFeedback } from "@/components/statistics-feedback"
|
||||
import { DatePickerField } from "@/components/date-picker-field"
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Calendar } from "@/components/ui/calendar"
|
||||
import { Card, CardContent } from "@/components/ui/card"
|
||||
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover"
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -85,85 +66,6 @@ const EMPTY_FILTERS: TaskHistoryFilters = {
|
||||
endTime: undefined,
|
||||
}
|
||||
|
||||
const DATE_LOCALES: Record<string, Locale> = {
|
||||
ar,
|
||||
de,
|
||||
en: enUS,
|
||||
es,
|
||||
fr,
|
||||
ja,
|
||||
ko,
|
||||
ru,
|
||||
zh: zhCN,
|
||||
"zh-CN": zhCN,
|
||||
"zh-TW": zhTW,
|
||||
}
|
||||
|
||||
type DatePickerFieldProps = {
|
||||
id: string
|
||||
label: string
|
||||
placeholder: string
|
||||
locale: string
|
||||
calendarLocale: Locale
|
||||
value: Date | undefined
|
||||
onChange: (value: Date | undefined) => void
|
||||
disabled?: React.ComponentProps<typeof Calendar>["disabled"]
|
||||
}
|
||||
|
||||
function DatePickerField({
|
||||
id,
|
||||
label,
|
||||
placeholder,
|
||||
locale,
|
||||
calendarLocale,
|
||||
value,
|
||||
onChange,
|
||||
disabled,
|
||||
}: DatePickerFieldProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const formatter = useMemo(
|
||||
() => new Intl.DateTimeFormat(locale, { dateStyle: "medium" }),
|
||||
[locale]
|
||||
)
|
||||
|
||||
return (
|
||||
<Field className="sm:w-48">
|
||||
<FieldLabel htmlFor={id} className="sr-only">
|
||||
{label}
|
||||
</FieldLabel>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger
|
||||
render={
|
||||
<Button
|
||||
id={id}
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="w-full justify-start px-2.5 font-normal"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<HugeiconsIcon icon={Calendar03Icon} data-icon="inline-start" />
|
||||
{value ? formatter.format(value) : placeholder}
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-auto p-0" align="start">
|
||||
<Calendar
|
||||
mode="single"
|
||||
selected={value}
|
||||
defaultMonth={value}
|
||||
onSelect={(date) => {
|
||||
onChange(date)
|
||||
if (date) setOpen(false)
|
||||
}}
|
||||
disabled={disabled}
|
||||
locale={calendarLocale}
|
||||
captionLayout="dropdown"
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
export function TaskHistoryPage() {
|
||||
const { i18n, t } = useTranslation()
|
||||
const [filterInput, setFilterInput] =
|
||||
@@ -172,8 +74,6 @@ export function TaskHistoryPage() {
|
||||
const [page, setPage] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(DEFAULT_PAGE_SIZE)
|
||||
const locale = i18n.resolvedLanguage ?? i18n.language
|
||||
const language = locale.split("-")[0]
|
||||
const calendarLocale = DATE_LOCALES[locale] ?? DATE_LOCALES[language] ?? enUS
|
||||
|
||||
const query = new URLSearchParams({
|
||||
task: filters.taskName,
|
||||
@@ -275,7 +175,6 @@ export function TaskHistoryPage() {
|
||||
label={t("pages.taskHistory.filters.startTime")}
|
||||
placeholder={t("pages.taskHistory.filters.startTime")}
|
||||
locale={locale}
|
||||
calendarLocale={calendarLocale}
|
||||
value={filterInput.startTime}
|
||||
onChange={(value) =>
|
||||
setFilterInput((current) => ({
|
||||
@@ -294,7 +193,6 @@ export function TaskHistoryPage() {
|
||||
label={t("pages.taskHistory.filters.endTime")}
|
||||
placeholder={t("pages.taskHistory.filters.endTime")}
|
||||
locale={locale}
|
||||
calendarLocale={calendarLocale}
|
||||
value={filterInput.endTime}
|
||||
onChange={(value) =>
|
||||
setFilterInput((current) => ({
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import assert from "node:assert/strict"
|
||||
import test from "node:test"
|
||||
|
||||
import { endOfLocalDay, startOfLocalDay } from "../src/lib/date-range.ts"
|
||||
|
||||
test("audit date filters use fixed local day boundaries", () => {
|
||||
const selected = new Date(2026, 4, 17, 12, 34, 56, 789)
|
||||
const start = startOfLocalDay(selected)
|
||||
const end = endOfLocalDay(selected)
|
||||
|
||||
assert.deepEqual(
|
||||
[
|
||||
start.getHours(),
|
||||
start.getMinutes(),
|
||||
start.getSeconds(),
|
||||
start.getMilliseconds(),
|
||||
],
|
||||
[0, 0, 0, 0]
|
||||
)
|
||||
assert.deepEqual(
|
||||
[end.getHours(), end.getMinutes(), end.getSeconds(), end.getMilliseconds()],
|
||||
[23, 59, 59, 999]
|
||||
)
|
||||
assert.equal(selected.getHours(), 12)
|
||||
})
|
||||
@@ -31,6 +31,8 @@ test("members page keeps the original split cards and compact member list", asyn
|
||||
"utf8"
|
||||
)
|
||||
|
||||
assert.match(source, /md:h-\[calc\(100svh-5rem\)\]/)
|
||||
assert.doesNotMatch(source, /md:h-\[calc\(100svh-4rem\)\]/)
|
||||
assert.match(
|
||||
source,
|
||||
/md:grid-cols-\[minmax\(14rem,1fr\)_minmax\(0,1\.5fr\)\]/
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { readFile } from "node:fs/promises"
|
||||
import test from "node:test"
|
||||
|
||||
test("operation log card keeps its top ring inside the clipped viewport", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../src/pages/operation-logs-page.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
assert.match(source, /flex-col p-4 pt-px md:h-\[calc\(100svh-5rem\)\]/)
|
||||
assert.doesNotMatch(source, /flex-col p-4 pt-0/)
|
||||
})
|
||||
|
||||
test("operation logs show 50 rows per page by default", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../src/pages/operation-logs-page.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
assert.match(source, /const DEFAULT_PAGE_SIZE = 50/)
|
||||
})
|
||||
|
||||
test("operation log filters use shared date pickers and local day boundaries", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../src/pages/operation-logs-page.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
assert.equal((source.match(/<DatePickerField/g) ?? []).length, 2)
|
||||
assert.match(source, /startOfLocalDay\(sinceInput\)/)
|
||||
assert.match(source, /endOfLocalDay\(untilInput\)/)
|
||||
assert.match(
|
||||
source,
|
||||
/disabled=\{untilInput \? \{ after: untilInput \} : undefined\}/
|
||||
)
|
||||
assert.match(
|
||||
source,
|
||||
/disabled=\{sinceInput \? \{ before: sinceInput \} : undefined\}/
|
||||
)
|
||||
assert.doesNotMatch(source, /type="datetime-local"/)
|
||||
assert.doesNotMatch(source, /requestParamsInput|requestParamsQuery/)
|
||||
assert.doesNotMatch(source, /filters\.requestParamsSearchPlaceholder/)
|
||||
assert.doesNotMatch(source, /params: requestParamsQuery/)
|
||||
assert.equal((source.match(/className="w-32"/g) ?? []).length, 2)
|
||||
assert.equal((source.match(/className="w-32 sm:w-32"/g) ?? []).length, 2)
|
||||
|
||||
const filterRow = source
|
||||
.split(
|
||||
'className="flex flex-wrap items-center gap-2 px-(--card-spacing)"'
|
||||
)[1]
|
||||
.split("</div>")[0]
|
||||
assert.ok(
|
||||
filterRow.lastIndexOf("<DatePickerField") <
|
||||
filterRow.indexOf("<DropdownMenu>")
|
||||
)
|
||||
assert.ok(
|
||||
filterRow.lastIndexOf("<DropdownMenu>") <
|
||||
filterRow.indexOf('<Button type="button" onClick={applySearch}>')
|
||||
)
|
||||
assert.match(source, /useState<CategoryFilter>\(null\)/)
|
||||
assert.match(source, /useState<ResultFilter>\(null\)/)
|
||||
assert.match(source, /<DropdownMenuCheckboxItem/)
|
||||
assert.match(source, /setCategoryInput\(checked \? value : null\)/)
|
||||
assert.match(source, /setResultInput\(checked \? value : null\)/)
|
||||
assert.doesNotMatch(source, /filters\.allActions|filters\.allResults/)
|
||||
assert.doesNotMatch(source, /DropdownMenuRadioItem|DropdownMenuRadioGroup/)
|
||||
|
||||
const picker = await readFile(
|
||||
new URL("../src/components/date-picker-field.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
assert.match(picker, /<Calendar/)
|
||||
assert.match(picker, /mode="single"/)
|
||||
assert.match(picker, /<Popover/)
|
||||
assert.match(picker, /!value && "text-muted-foreground"/)
|
||||
assert.doesNotMatch(picker, /Calendar03Icon|HugeiconsIcon/)
|
||||
assert.doesNotMatch(picker, /captionLayout="dropdown"/)
|
||||
})
|
||||
|
||||
test("operation log pagination uses matching arrow icons", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../src/pages/operation-logs-page.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
assert.match(source, /icon=\{ArrowLeft01Icon\}/)
|
||||
assert.match(source, /icon=\{ArrowRight01Icon\}/)
|
||||
assert.doesNotMatch(source, /ArrowLeft02Icon/)
|
||||
})
|
||||
|
||||
test("operation log actors use the same blue user icon as tree members", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../src/pages/operation-logs-page.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
assert.match(source, /User02Icon/)
|
||||
assert.match(
|
||||
source,
|
||||
/icon=\{User02Icon\}\s+className="size-4 shrink-0 text-blue-600 dark:text-blue-400"/
|
||||
)
|
||||
assert.doesNotMatch(source, /<Avatar|AvatarFallback|actor_name\.slice/)
|
||||
assert.match(source, /title=\{log\.actor_email \?\? undefined\}/)
|
||||
assert.match(source, /\{log\.actor_name\}/)
|
||||
})
|
||||
|
||||
test("operation log action uses target-action order without a second ID line", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../src/pages/operation-logs-page.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
assert.match(
|
||||
source,
|
||||
/`\$\{t\(`audit\.targets\.\$\{log\.target_type\}`[\s\S]*?\}\)\} - \$\{t\(`audit\.actions\.\$\{log\.action\}`/
|
||||
)
|
||||
const row = source
|
||||
.split("visibleLogs.map((log) => (")[1]
|
||||
.split("</TableRow>")[0]
|
||||
assert.match(row, /<TableCell>\{actionLabel\(log\)\}<\/TableCell>/)
|
||||
assert.doesNotMatch(source, /\{log\.target_id && \(/)
|
||||
assert.match(source, /\[t\("audit\.target"\), log\.target_id\]/)
|
||||
})
|
||||
|
||||
test("operation log result appears before the operator", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../src/pages/operation-logs-page.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
const header = source.split("<TableHeader")[1].split("</TableHeader>")[0]
|
||||
assert.ok(
|
||||
header.indexOf('columns.result")') < header.indexOf('columns.operator")')
|
||||
)
|
||||
|
||||
const row = source
|
||||
.split("visibleLogs.map((log) => (")[1]
|
||||
.split("</TableRow>")[0]
|
||||
assert.ok(row.indexOf("log.result ===") < row.indexOf("log.actor_name"))
|
||||
assert.match(
|
||||
row,
|
||||
/<TableCell className="font-mono text-muted-foreground">\s*\{log\.source_ip \|\| "—"\}/
|
||||
)
|
||||
})
|
||||
|
||||
test("operation log details are opened from the last actions column", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../src/pages/operation-logs-page.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
const header = source.split("<TableHeader")[1].split("</TableHeader>")[0]
|
||||
assert.doesNotMatch(header, /columns\.requestParams/)
|
||||
assert.ok(
|
||||
header.indexOf('columns.ipAddress")') <
|
||||
header.indexOf('columns.operations")')
|
||||
)
|
||||
assert.match(
|
||||
header,
|
||||
/<TableHead className="pe-\(--card-spacing\)">\s*\{t\("pages\.operationLogs\.columns\.operations"\)\}/
|
||||
)
|
||||
|
||||
const row = source
|
||||
.split("visibleLogs.map((log) => (")[1]
|
||||
.split("</TableRow>")[0]
|
||||
assert.match(row, /<TableCell className="pe-\(--card-spacing\)">\s*<Dialog>/)
|
||||
assert.match(
|
||||
row,
|
||||
/<Button\s+variant="outline"\s+size="xs"\s+type="button"\s*\/>/
|
||||
)
|
||||
assert.match(row, /\{t\("pages\.operationLogs\.details"\)\}/)
|
||||
assert.match(row, /JSON\.stringify\(log\.request_params, null, 2\)/)
|
||||
assert.doesNotMatch(row, /JSON\.stringify\(log\.request_params\)\s*<\/span>/)
|
||||
assert.doesNotMatch(row, /<DialogDescription>/)
|
||||
assert.match(row, /grid-cols-\[9rem_minmax\(0,1fr\)\]/)
|
||||
assert.match(row, /columns\.time"\),\s*dateFormatter\.format/)
|
||||
assert.match(
|
||||
row,
|
||||
/columns\.operator"\),\s*log\.actor_email\s*\? `\$\{log\.actor_name\} \(\$\{log\.actor_email\}\)`/
|
||||
)
|
||||
assert.match(row, /columns\.action"\),\s*actionLabel\(log\)/)
|
||||
})
|
||||
|
||||
test("only the operation log table scrolls and its header stays visible", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../src/pages/operation-logs-page.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
assert.match(
|
||||
source,
|
||||
/<section className="flex min-h-0 flex-1 flex-col p-4 pt-px md:h-\[calc\(100svh-5rem\)\] md:flex-none md:overflow-hidden">/
|
||||
)
|
||||
assert.match(source, /<Card className="min-h-0 flex-1">/)
|
||||
assert.match(source, /<CardContent className="min-h-0 flex-1 gap-4 px-0">/)
|
||||
assert.match(
|
||||
source,
|
||||
/<ScrollArea\s+horizontal\s+className="min-h-0 flex-1 \[&_\[data-slot=table-container\]\]:overflow-visible"/
|
||||
)
|
||||
assert.match(
|
||||
source,
|
||||
/<TableHeader className="sticky top-0 z-10 bg-card \[&_th\]:shadow-\[inset_0_-1px_0_var\(--border\)\] \[&_tr\]:border-b-0">/
|
||||
)
|
||||
assert.ok(
|
||||
source.indexOf("</ScrollArea>") <
|
||||
source.indexOf('pagination.pageSizeLabel")')
|
||||
)
|
||||
|
||||
const scrollArea = await readFile(
|
||||
new URL("../src/components/ui/scroll-area.tsx", import.meta.url),
|
||||
"utf8"
|
||||
)
|
||||
assert.match(scrollArea, /horizontal = false/)
|
||||
assert.match(scrollArea, /"z-20 flex touch-none/)
|
||||
assert.match(
|
||||
scrollArea,
|
||||
/horizontal && <ScrollBar orientation="horizontal" \/>/
|
||||
)
|
||||
})
|
||||
Reference in new issue
Block a user