import React, { useState } from 'react'; import { Box, Typography, Accordion, AccordionSummary, AccordionDetails, Chip, Grid, } from '@mui/material'; import { ExpandMore as ExpandMoreIcon, Security as PermissionsIcon, Person as OwnerIcon, Group as GroupIcon, Storage as StorageIcon, Info as InfoIcon, } from '@mui/icons-material'; interface MetadataDisplayProps { metadata: any; title?: string; compact?: boolean; } const MetadataDisplay: React.FC = ({ metadata, title = "Source Metadata", compact = false, }) => { const [expanded, setExpanded] = useState(!compact); if (!metadata || Object.keys(metadata).length === 0) { return null; } const formatValue = (key: string, value: any): React.ReactNode => { // Handle special metadata fields with better formatting if (key === 'permissions' && typeof value === 'number') { return ( {value.toString(8)} (octal) ); } if (key === 'owner' || key === 'uid') { return ( {value} ); } if (key === 'group' || key === 'gid') { return ( {value} ); } if (key === 'storage_class' || key === 'region') { return ( {value} ); } // Handle arrays if (Array.isArray(value)) { return ( {value.map((item, index) => ( ))} ); } // Handle objects if (typeof value === 'object' && value !== null) { return (
            {JSON.stringify(value, null, 2)}
          
); } // Handle boolean values if (typeof value === 'boolean') { return ( ); } // Handle dates if (typeof value === 'string' && ( key.includes('date') || key.includes('time') || key.includes('created') || key.includes('modified') )) { try { const date = new Date(value); if (!isNaN(date.getTime())) { return ( {date.toLocaleString()} ); } } catch { // Fall through to default handling } } // Default: display as string return ( {String(value)} ); }; const formatKeyName = (key: string): string => { // Convert snake_case and camelCase to Title Case return key .replace(/([a-z])([A-Z])/g, '$1 $2') // camelCase to spaces .replace(/_/g, ' ') // snake_case to spaces .replace(/\b\w/g, (letter) => letter.toUpperCase()); // Title Case }; const renderMetadata = () => { return ( {Object.entries(metadata).map(([key, value]) => ( {formatKeyName(key)} {formatValue(key, value)} ))} ); }; if (compact) { return ( setExpanded(isExpanded)}> } sx={{ backgroundColor: 'grey.50', '&:hover': { backgroundColor: 'grey.100' } }} > {title} {renderMetadata()} ); } return ( {title} {renderMetadata()} ); }; export default MetadataDisplay;