fix(mining-admin-web): fix audit logs page crash

- Use 'all' instead of empty string for SelectItem value (Radix requirement)
- Add null safety for items array with fallback to empty array
- Fix potential undefined access on data.items

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-14 02:30:07 -08:00
parent a2adddbf3d
commit bd0f98cfb3
1 changed files with 8 additions and 6 deletions

View File

@ -36,20 +36,22 @@ const actionLabels: Record<string, { label: string; className: string }> = {
export default function AuditLogsPage() {
const [page, setPage] = useState(1);
const [action, setAction] = useState<string>('');
const [action, setAction] = useState<string>('all');
const [keyword, setKeyword] = useState('');
const pageSize = 20;
const { data, isLoading } = useQuery({
const { data, isLoading, error } = useQuery({
queryKey: ['audit-logs', page, action, keyword],
queryFn: async () => {
const response = await apiClient.get('/audit', {
params: { page, pageSize, action: action || undefined, keyword: keyword || undefined },
params: { page, pageSize, action: action === 'all' ? undefined : action, keyword: keyword || undefined },
});
return response.data.data as PaginatedResponse<AuditLog>;
},
});
const items = data?.items ?? [];
return (
<div className="space-y-6">
<PageHeader title="审计日志" description="查看系统操作日志" />
@ -71,7 +73,7 @@ export default function AuditLogsPage() {
<SelectValue placeholder="操作类型" />
</SelectTrigger>
<SelectContent>
<SelectItem value=""></SelectItem>
<SelectItem value="all"></SelectItem>
<SelectItem value="CREATE"></SelectItem>
<SelectItem value="UPDATE"></SelectItem>
<SelectItem value="DELETE"></SelectItem>
@ -108,14 +110,14 @@ export default function AuditLogsPage() {
))}
</TableRow>
))
) : data?.items.length === 0 ? (
) : items.length === 0 ? (
<TableRow>
<TableCell colSpan={7} className="text-center py-8 text-muted-foreground">
</TableCell>
</TableRow>
) : (
data?.items.map((log) => {
items.map((log) => {
const actionInfo = actionLabels[log.action] || { label: log.action, className: '' };
return (
<TableRow key={log.id}>