|
| 1 | +import type { ReservoirAuditLog } from '../types/reservoir'; |
| 2 | +import BAIPropertyFilter from './BAIPropertyFilter'; |
| 3 | +import BAIText from './BAIText'; |
| 4 | +import { Tag, Typography } from 'antd'; |
| 5 | +import { BAIFlex, BAITable } from 'backend.ai-ui'; |
| 6 | +import dayjs from 'dayjs'; |
| 7 | +import { Activity, CheckCircle, XCircle } from 'lucide-react'; |
| 8 | +import React from 'react'; |
| 9 | + |
| 10 | +// import { useTranslation } from 'react-i18next'; |
| 11 | + |
| 12 | +interface ReservoirAuditLogListProps { |
| 13 | + auditLogs: ReservoirAuditLog[]; |
| 14 | + loading?: boolean; |
| 15 | + filterValue?: string; |
| 16 | + onFilterChange?: (value: string) => void; |
| 17 | + pagination?: { |
| 18 | + pageSize: number; |
| 19 | + current: number; |
| 20 | + total: number; |
| 21 | + showTotal?: (total: number) => React.ReactNode; |
| 22 | + onChange?: (current: number, pageSize: number) => void; |
| 23 | + }; |
| 24 | + order?: string; |
| 25 | + onChangeOrder?: (order: string) => void; |
| 26 | +} |
| 27 | + |
| 28 | +const ReservoirAuditLogList: React.FC<ReservoirAuditLogListProps> = ({ |
| 29 | + auditLogs, |
| 30 | + loading = false, |
| 31 | + filterValue, |
| 32 | + onFilterChange, |
| 33 | + pagination, |
| 34 | + order, |
| 35 | + onChangeOrder, |
| 36 | +}) => { |
| 37 | + // const { t } = useTranslation(); |
| 38 | + |
| 39 | + return ( |
| 40 | + <BAIFlex direction="column" align="stretch" gap={'sm'}> |
| 41 | + <BAIFlex |
| 42 | + gap={'sm'} |
| 43 | + align="start" |
| 44 | + style={{ |
| 45 | + flexShrink: 1, |
| 46 | + }} |
| 47 | + wrap="wrap" |
| 48 | + > |
| 49 | + <BAIPropertyFilter |
| 50 | + filterProperties={[ |
| 51 | + { |
| 52 | + key: 'artifactName', |
| 53 | + propertyLabel: 'Artifact', |
| 54 | + type: 'string', |
| 55 | + }, |
| 56 | + { |
| 57 | + key: 'operation', |
| 58 | + propertyLabel: 'Operation', |
| 59 | + type: 'string', |
| 60 | + strictSelection: true, |
| 61 | + defaultOperator: '==', |
| 62 | + options: [ |
| 63 | + { label: 'Pull', value: 'pull' }, |
| 64 | + { label: 'Install', value: 'install' }, |
| 65 | + { label: 'Uninstall', value: 'uninstall' }, |
| 66 | + { label: 'Update', value: 'update' }, |
| 67 | + { label: 'Verify', value: 'verify' }, |
| 68 | + { label: 'Delete', value: 'delete' }, |
| 69 | + ], |
| 70 | + }, |
| 71 | + { |
| 72 | + key: 'modifier', |
| 73 | + propertyLabel: 'Modifier', |
| 74 | + type: 'string', |
| 75 | + }, |
| 76 | + { |
| 77 | + key: 'status', |
| 78 | + propertyLabel: 'Status', |
| 79 | + type: 'string', |
| 80 | + strictSelection: true, |
| 81 | + defaultOperator: '==', |
| 82 | + options: [ |
| 83 | + { label: 'Success', value: 'success' }, |
| 84 | + { label: 'Failed', value: 'failed' }, |
| 85 | + { label: 'In Progress', value: 'in_progress' }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + ]} |
| 89 | + value={filterValue} |
| 90 | + onChange={onFilterChange} |
| 91 | + /> |
| 92 | + </BAIFlex> |
| 93 | + <BAITable |
| 94 | + size="small" |
| 95 | + dataSource={auditLogs} |
| 96 | + rowKey="id" |
| 97 | + loading={loading} |
| 98 | + columns={[ |
| 99 | + { |
| 100 | + title: 'Artifact', |
| 101 | + dataIndex: 'artifactName', |
| 102 | + key: 'artifactName', |
| 103 | + render: (artifactName: string) => ( |
| 104 | + <Typography.Text strong>{artifactName}</Typography.Text> |
| 105 | + ), |
| 106 | + sorter: true, |
| 107 | + }, |
| 108 | + { |
| 109 | + title: 'Version', |
| 110 | + dataIndex: 'artifactVersion', |
| 111 | + key: 'artifactVersion', |
| 112 | + render: (version: string) => |
| 113 | + version ? <BAIText monospace>{version}</BAIText> : '-', |
| 114 | + }, |
| 115 | + { |
| 116 | + title: 'Operation', |
| 117 | + dataIndex: 'operation', |
| 118 | + key: 'operation', |
| 119 | + render: (operation: string) => <Tag>{operation.toUpperCase()}</Tag>, |
| 120 | + sorter: true, |
| 121 | + }, |
| 122 | + { |
| 123 | + title: 'Modifier', |
| 124 | + dataIndex: 'modifier', |
| 125 | + key: 'modifier', |
| 126 | + render: (modifier: string) => ( |
| 127 | + <Typography.Text>{modifier}</Typography.Text> |
| 128 | + ), |
| 129 | + sorter: true, |
| 130 | + }, |
| 131 | + { |
| 132 | + title: 'Timestamp', |
| 133 | + dataIndex: 'timestamp', |
| 134 | + key: 'timestamp', |
| 135 | + render: (timestamp: string) => ( |
| 136 | + <Typography.Text type="secondary"> |
| 137 | + {dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')} |
| 138 | + </Typography.Text> |
| 139 | + ), |
| 140 | + sorter: true, |
| 141 | + }, |
| 142 | + ]} |
| 143 | + pagination={pagination} |
| 144 | + scroll={{ x: 'max-content' }} |
| 145 | + // order={order} |
| 146 | + expandable={{ |
| 147 | + expandedRowRender: (record) => ( |
| 148 | + <BAIFlex direction="column" gap="xs" style={{ padding: '8px 0' }}> |
| 149 | + <BAIFlex align="center" gap="xs"> |
| 150 | + <Typography.Text strong>Status:</Typography.Text> |
| 151 | + <Tag |
| 152 | + color={ |
| 153 | + record.status === 'success' |
| 154 | + ? 'green' |
| 155 | + : record.status === 'failed' |
| 156 | + ? 'red' |
| 157 | + : 'blue' |
| 158 | + } |
| 159 | + icon={ |
| 160 | + record.status === 'success' ? ( |
| 161 | + <CheckCircle size={12} /> |
| 162 | + ) : record.status === 'failed' ? ( |
| 163 | + <XCircle size={12} /> |
| 164 | + ) : ( |
| 165 | + <Activity size={12} /> |
| 166 | + ) |
| 167 | + } |
| 168 | + > |
| 169 | + {record.status.toUpperCase()} |
| 170 | + </Tag> |
| 171 | + </BAIFlex> |
| 172 | + {record.details && ( |
| 173 | + <BAIFlex align="start" gap="xs"> |
| 174 | + <Typography.Text strong>Details:</Typography.Text> |
| 175 | + <Typography.Text type="secondary"> |
| 176 | + {record.details} |
| 177 | + </Typography.Text> |
| 178 | + </BAIFlex> |
| 179 | + )} |
| 180 | + </BAIFlex> |
| 181 | + ), |
| 182 | + expandRowByClick: true, |
| 183 | + }} |
| 184 | + /> |
| 185 | + </BAIFlex> |
| 186 | + ); |
| 187 | +}; |
| 188 | + |
| 189 | +export default ReservoirAuditLogList; |
0 commit comments