import React, { useState } from 'react'; import type { GraphData, GraphNode } from '../types'; import { escapeHtml } from '../utils/formatting'; interface TableViewProps { graphData: GraphData; } export const TableView: React.FC = ({ graphData }) => { const accessGroups = graphData.nodes.filter((n) => n.type === 'accessGroup'); const entities = graphData.nodes.filter((n) => n.type === 'entity'); const functions = graphData.nodes.filter((n) => n.type === 'function'); return (
{entities.length > 0 && ( )}
); }; interface TableSectionProps { title: string; items: GraphNode[]; type: string; edges: any[]; } const TableSection: React.FC = ({ title, items, type, edges }) => { const [collapsed, setCollapsed] = useState(false); const changedCount = items.filter((n) => n.changeStatus !== 'unchanged').length; // Sort: changed items first, then by name const sortedItems = [...items].sort((a, b) => { const aChanged = a.changeStatus !== 'unchanged' ? 0 : 1; const bChanged = b.changeStatus !== 'unchanged' ? 0 : 1; if (aChanged !== bChanged) return aChanged - bChanged; return a.label.localeCompare(b.label); }); const nodeType = type === 'accessGroup' ? 'access' : type; return (
setCollapsed(!collapsed)}>
{title} {items.length} {changedCount > 0 && {changedCount}}
{sortedItems.map((item) => ( ))}
); }; interface TableItemProps { item: GraphNode; type: string; edges: any[]; } const TableItem: React.FC = ({ item, type, edges }) => { const statusClass = item.changeStatus !== 'unchanged' ? item.changeStatus : ''; const icon = item.changeStatus === 'added' ? '+' : item.changeStatus === 'removed' ? '−' : item.changeStatus === 'modified' ? '~' : ''; // Get tags for functions const accessEdges = type === 'function' ? edges.filter((e) => e.source === item.id && e.type === 'requires-access') : []; const entityEdges = type === 'function' ? edges.filter((e) => e.source === item.id && e.type === 'operates-on') : []; return (
{icon}
{type === 'function' && (accessEdges.length > 0 || entityEdges.length > 0) && (
{accessEdges.map((edge) => { const groupName = edge.target.replace('accessGroup:', ''); return ( {groupName} ); })} {entityEdges.map((edge) => { const entityName = edge.target.replace('entity:', ''); return ( {entityName} ); })}
)} {item.changeDetails && item.changeStatus === 'modified' && (
{item.changeDetails.oldAccess && item.changeDetails.newAccess && (
Access: {item.changeDetails.oldAccess.join(', ')} {item.changeDetails.newAccess.join(', ')}
)} {item.changeDetails.inputsChanged &&
Input schema changed
} {item.changeDetails.outputsChanged &&
Output schema changed
} {item.changeDetails.entitiesChanged && (
Entities: {(item.changeDetails.oldEntities || []).join(', ')} {(item.changeDetails.newEntities || []).join(', ')}
)}
)}
); };