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