From e904cc10b42578995185ae466134e76a14c0dacc Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 18 Aug 2025 00:55:32 +0100 Subject: [PATCH] Removed old audit log tabel. --- .../Dashboard/common/AuditLogTable.jsx | 213 ------------------ 1 file changed, 213 deletions(-) delete mode 100644 src/components/Dashboard/common/AuditLogTable.jsx diff --git a/src/components/Dashboard/common/AuditLogTable.jsx b/src/components/Dashboard/common/AuditLogTable.jsx deleted file mode 100644 index e8e9d2d..0000000 --- a/src/components/Dashboard/common/AuditLogTable.jsx +++ /dev/null @@ -1,213 +0,0 @@ -import React, { forwardRef, useState } from 'react' -import { Typography, Space, Descriptions, Badge, Table } from 'antd' -import PropTypes from 'prop-types' -import IdDisplay from './IdDisplay' -import { AuditOutlined, LoadingOutlined } from '@ant-design/icons' -import TimeDisplay from '../common/TimeDisplay' -import BoolDisplay from './BoolDisplay' -import StateTag from './StateTag' - -const { Text } = Typography - -const formatPropertyName = (name) => { - return name - .replace(/([A-Z])/g, ' $1') - .replace(/^./, (str) => str.toUpperCase()) -} - -const isObjectId = (value) => { - return typeof value === 'string' && /^[0-9a-fA-F]{24}$/.test(value) -} - -const formatValue = (value, propertyName) => { - if (value === null || value === undefined || value === '') { - return ( -
- n/a -
- ) - } - - // Handle colors specifically - if (propertyName === 'color') { - return - } - - if (propertyName === 'state' && typeof value === 'object' && value.type) { - return - } - - // Check if the value is a timestamp (ISO date string) - if ( - typeof value === 'string' && - /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(value) - ) { - return - } - - if (typeof value === 'boolean' || value === true || value === false) { - return - } - - if (isObjectId(value)) { - return ( - - ) - } - - if (typeof value === 'object') { - return {JSON.stringify(value)} - } - - return {value} -} - -const AuditLogTable = forwardRef( - ( - { items, loading = false, showTargetColumn = true, showOwnerColumn = true }, - ref - ) => { - const [sortedInfo, setSortedInfo] = useState({ - columnKey: 'createdAt', - order: 'descend' - }) - - const handleChange = (pagination, filters, sorter) => { - setSortedInfo(sorter) - } - - const columns = [ - { - title: '', - key: 'icon', - width: 50, - render: () => - }, - { - title: 'ID', - dataIndex: '_id', - key: 'id', - width: 180, - render: (text) => ( - - ), - sorter: (a, b) => a._id.localeCompare(b._id) - } - ] - - if (showOwnerColumn) { - columns.push( - { - title: 'Owner Name', - dataIndex: ['owner', 'name'], - key: 'name', - width: 200, - sorter: (a, b) => - (a.owner?.name || '').localeCompare(b.owner?.name || '') - }, - { - title: 'Owner', - key: 'owner', - width: 180, - render: (record) => ( - - ) - } - ) - } - - if (showTargetColumn) { - columns.push({ - title: 'Target', - key: 'target', - width: 180, - render: (record) => ( - - ) - }) - } - - columns.push({ - title: 'Properties', - dataIndex: 'type', - key: 'type', - width: 550, - render: (_, record) => { - const oldValue = record.oldValue || {} - const newValue = record.newValue || {} - - return ( - - {Object.keys(newValue).map((key) => ( - - - {formatValue(oldValue[key], key)} - - {formatValue(newValue[key], key)} - - - ))} - - ) - } - }) - - columns.push({ - title: 'Timestamp', - dataIndex: 'createdAt', - key: 'createdAt', - width: 180, - defaultSortOrder: 'descend', - sorter: (a, b) => new Date(a.createdAt) - new Date(b.createdAt), - render: (createdAt) => { - if (createdAt) { - return - } else { - return 'n/a' - } - } - }) - - return ( - }} - pagination={false} - scroll={{ x: 'max-content' }} - onChange={handleChange} - sortDirections={['ascend', 'descend']} - sortOrder={ - sortedInfo.columnKey === 'createdAt' ? sortedInfo.order : null - } - /> - ) - } -) - -AuditLogTable.displayName = 'AuditLogTable' - -AuditLogTable.propTypes = { - items: PropTypes.arrayOf(PropTypes.object).isRequired, - loading: PropTypes.bool, - showTargetColumn: PropTypes.bool, - showOwnerColumn: PropTypes.bool -} - -export default AuditLogTable