All files / src/components EventTimeline.tsx

96.96% Statements 32/33
72.72% Branches 8/11
100% Functions 1/1
96.96% Lines 32/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  1x 1x 1x 1x   1x 25x 25x   25x 1x 1x   24x 24x 24x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x   126x 126x 24x 24x   24x  
import type { TaskEvent } from "../api/types";
import { formatDateTime, formatRelative } from "../lib/format";
import { buildTimeline } from "../lib/timeline";
import { EmptyState } from "./EmptyState";
import { StatusBadge } from "./StatusBadge";
 
export function EventTimeline({ events, now }: { events: TaskEvent[]; now?: Date }) {
  const reference = now ?? new Date();
  const entries = buildTimeline(events);
 
  if (entries.length === 0) {
    return <EmptyState title="Событий пока нет" hint="События появятся после первых переходов статуса." />;
  }
 
  return (
    <ol className="timeline">
      {entries.map((entry) => (
        <li key={entry.id} className="timeline__item" data-testid="timeline-item">
          <span className={`timeline__dot timeline__dot--${entry.tone}`} aria-hidden="true" />
          <div className="timeline__body">
            <div className="timeline__head">
              <StatusBadge tone={entry.tone}>{entry.label}</StatusBadge>
              <time dateTime={entry.createdAt} title={formatDateTime(entry.createdAt)}>
                {formatRelative(entry.createdAt, reference)}
              </time>
            </div>
            {entry.message ? <p className="timeline__message">{entry.message}</p> : null}
            {entry.fromStatus || entry.toStatus ? (
              <small className="mono">
                {entry.fromStatus ?? "—"} → {entry.toStatus ?? "—"}
              </small>
            ) : null}
          </div>
        </li>
      ))}
    </ol>
  );
}