Spaces:
Running
Running
File size: 7,006 Bytes
518343a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | import { X } from 'lucide-react';
import { useMemo, useState } from 'react';
import { getDomainColor, getSeverityColor } from '../../lib/command/utils';
import type { DomainId, SeverityLevel, TimelineEvent } from '../types';
interface TimelineProps {
events: TimelineEvent[];
}
const SEVERITY_OPTIONS: SeverityLevel[] = ['critical', 'high', 'medium', 'low', 'info'];
const DOMAIN_OPTIONS: DomainId[] = [
'aegis',
'vessels',
'szl',
'lyte',
'prism',
'terra',
'carlota',
'stephen',
];
const PAGE_SIZE = 8;
export function Timeline({ events }: TimelineProps) {
const [domainFilter, setDomainFilter] = useState<DomainId | null>(null);
const [severityFilter, setSeverityFilter] = useState<SeverityLevel | null>(null);
const [page, setPage] = useState(1);
const filtered = useMemo(() => {
return events.filter((e) => {
if (domainFilter && e.domain !== domainFilter) return false;
if (severityFilter && e.severity !== severityFilter) return false;
return true;
});
}, [events, domainFilter, severityFilter]);
const visible = filtered.slice(0, page * PAGE_SIZE);
const hasMore = visible.length < filtered.length;
const domainsPresent = useMemo(() => {
const s = new Set(events.map((e) => e.domain as DomainId));
return DOMAIN_OPTIONS.filter((d) => s.has(d));
}, [events]);
const clearFilters = () => {
setDomainFilter(null);
setSeverityFilter(null);
setPage(1);
};
const hasFilters = domainFilter !== null || severityFilter !== null;
return (
<div
className="rounded-xl overflow-hidden flex flex-col h-full"
style={{
backgroundColor: 'var(--color-surface-base)',
border: '1px solid var(--color-surface-border)',
}}
>
<div
className="p-4 flex flex-col gap-3"
style={{
borderBottom: '1px solid var(--color-surface-border)',
backgroundColor: 'var(--color-bg-primary)',
}}
>
<div className="flex items-center justify-between">
<h2
className="text-xs font-bold tracking-widest uppercase"
style={{ color: 'var(--color-fg-muted)' }}
>
Cross-Domain Feed
</h2>
{hasFilters && (
<button
onClick={clearFilters}
className="flex items-center gap-1 text-[10px] font-mono uppercase tracking-wider"
style={{ color: 'var(--color-fg-muted)' }}
>
<X className="w-3 h-3" />
Clear
</button>
)}
</div>
<div className="flex flex-wrap gap-1.5">
{domainsPresent.map((d) => {
const active = domainFilter === d;
const color = getDomainColor(d);
return (
<button
key={d}
onClick={() => {
setDomainFilter(active ? null : d);
setPage(1);
}}
className="text-[10px] font-mono uppercase tracking-wider px-2 py-0.5 rounded transition-colors"
style={{
color: active ? 'var(--color-bg-primary)' : color,
backgroundColor: active ? color : `color-mix(in srgb, ${color} 12%, transparent)`,
border: `1px solid ${color}`,
}}
>
{d}
</button>
);
})}
</div>
<div className="flex flex-wrap gap-1.5">
{SEVERITY_OPTIONS.map((s) => {
const active = severityFilter === s;
const color = getSeverityColor(s);
return (
<button
key={s}
onClick={() => {
setSeverityFilter(active ? null : s);
setPage(1);
}}
className="text-[10px] font-mono uppercase tracking-wider px-2 py-0.5 rounded transition-colors"
style={{
color: active ? 'var(--color-bg-primary)' : color,
backgroundColor: active ? color : `color-mix(in srgb, ${color} 12%, transparent)`,
border: `1px solid ${color}`,
}}
>
{s}
</button>
);
})}
</div>
</div>
<div className="overflow-y-auto p-4 flex-1 flex flex-col gap-4 max-h-[600px]">
{visible.length === 0 ? (
<div
className="flex-1 flex items-center justify-center text-xs"
style={{ color: 'var(--color-fg-muted)' }}
>
No events match the current filters.
</div>
) : (
<>
{visible.map((event) => (
<div
key={event.id}
className="relative pl-4 pb-4 last:pb-0"
style={{ borderLeft: '1px solid var(--color-surface-border)' }}
data-testid={`timeline-event-${event.id}`}
>
<div
className="absolute w-2 h-2 rounded-full top-1.5"
style={{
backgroundColor: getDomainColor(event.domain),
left: '-4.5px',
}}
/>
<div className="flex flex-col gap-1">
<div
className="flex items-center gap-2 text-[10px] font-mono uppercase tracking-wider"
style={{ color: 'var(--color-fg-muted)' }}
>
<span>{event.time}</span>
<span style={{ opacity: 0.5 }}>/</span>
<span style={{ color: getDomainColor(event.domain) }}>{event.domain}</span>
<span style={{ opacity: 0.5 }}>/</span>
<span style={{ color: getSeverityColor(event.severity) }}>
{event.severity}
</span>
</div>
<h4
className="text-sm font-semibold"
style={{ color: 'var(--color-fg-primary)' }}
>
{event.title}
</h4>
<p className="text-xs leading-relaxed" style={{ color: 'var(--color-fg-muted)' }}>
{event.detail}
</p>
</div>
</div>
))}
{hasMore && (
<button
onClick={() => setPage((p) => p + 1)}
className="w-full py-2 text-xs font-mono uppercase tracking-wider rounded-lg transition-colors"
style={{
color: 'var(--color-fg-muted)',
backgroundColor: 'var(--color-bg-elevated)',
border: '1px solid var(--color-surface-border)',
}}
>
Load more ({filtered.length - visible.length} remaining)
</button>
)}
</>
)}
</div>
</div>
);
}
|