All files / src/components RobotGrid.tsx

100% Statements 42/42
100% Branches 9/9
100% Functions 1/1
100% Lines 42/42

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 40 41 42 43 44 45 46 47 48  1x 1x 1x 1x   1x 41x   41x 20x 20x   21x 21x 21x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 24x 24x 24x 23x 23x 23x 21x 21x   21x  
import type { Robot } from "../api/types";
import { formatRelative } from "../lib/format";
import { robotStatusLabel, robotStatusTone } from "../lib/status";
import { EmptyState } from "./EmptyState";
import { StatusBadge } from "./StatusBadge";
 
export function RobotGrid({ robots, now }: { robots: Robot[]; now?: Date }) {
  const reference = now ?? new Date();
 
  if (robots.length === 0) {
    return <EmptyState title="Парк пуст" hint="Зарегистрируйте робота через POST /api/v1/robots." />;
  }
 
  return (
    <div className="robot-grid">
      {robots.map((robot) => (
        <article key={robot.id} className="robot-card" data-testid="robot-card">
          <header className="robot-card__head">
            <strong>{robot.name}</strong>
            <StatusBadge tone={robotStatusTone(robot.status)}>{robotStatusLabel(robot.status)}</StatusBadge>
          </header>
          <dl className="robot-card__meta">
            <div>
              <dt>Namespace</dt>
              <dd className="mono">{robot.namespace}</dd>
            </div>
            <div>
              <dt>Связь</dt>
              <dd>{formatRelative(robot.last_seen_at, reference)}</dd>
            </div>
            <div>
              <dt>Задача</dt>
              <dd className="mono">{robot.current_task_id ? robot.current_task_id.slice(0, 8) : "—"}</dd>
            </div>
          </dl>
          <div className="robot-card__caps">
            {robot.capabilities.map((capability) => (
              <span key={capability} className="chip chip--static">
                {capability}
              </span>
            ))}
          </div>
        </article>
      ))}
    </div>
  );
}