diff --git a/frontend/src/components/config/ConfigHistorySection.tsx b/frontend/src/components/config/ConfigHistorySection.tsx new file mode 100644 index 0000000..83d64ad --- /dev/null +++ b/frontend/src/components/config/ConfigHistorySection.tsx @@ -0,0 +1,97 @@ +import { useQuery } from '@tanstack/react-query' +import { History } from 'lucide-react' +import { Badge } from '@/components/ui/badge' +import { TableSkeleton } from '@/components/ui/page-skeleton' +import { configHistoryApi } from '@/lib/api' + +interface ConfigHistorySectionProps { + tenantId: string + deviceId: string +} + +function formatRelativeTime(isoDate: string): string { + const date = new Date(isoDate) + const now = new Date() + const diffMs = now.getTime() - date.getTime() + const diffSec = Math.floor(diffMs / 1000) + const diffMin = Math.floor(diffSec / 60) + const diffHr = Math.floor(diffMin / 60) + const diffDay = Math.floor(diffHr / 24) + + if (diffSec < 60) return 'just now' + if (diffMin < 60) return `${diffMin}m ago` + if (diffHr < 24) return `${diffHr}h ago` + if (diffDay < 30) return `${diffDay}d ago` + return date.toLocaleDateString() +} + +function formatAbsoluteTime(isoDate: string): string { + return new Date(isoDate).toLocaleString() +} + +function LineDelta({ added, removed }: { added: number; removed: number }) { + return ( + + +{added} + / + -{removed} + + ) +} + +export function ConfigHistorySection({ tenantId, deviceId }: ConfigHistorySectionProps) { + const { data: changes, isLoading } = useQuery({ + queryKey: ['config-history', tenantId, deviceId], + queryFn: () => configHistoryApi.list(tenantId, deviceId), + refetchInterval: 60_000, + }) + + return ( +
{entry.summary}
+ + {formatRelativeTime(entry.created_at)} + +