# All files / src/components/workspace WorkspaceBoard.tsx

72% Statements 36/50
63.63% Branches 21/33
83.33% Functions 15/18
71.42% Lines 30/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
    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
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229

    47x

    47x
    38x

    47x

    47x

    47x
    36x
    36x
    36x
    36x
    36x
    36x

    36x
    38x

    36x

    47x

    36x

    47x
    8x

    39x

    195x

    49x

    11x

    49x
    49x
    49x

    49x

    6x
    6x
    6x

     import { useMemo, type JSX } from "react";
    import type { TaskData, Session, PersonaData, Environment } from "../../hooks/types.js";
    import { buildBoardColumns, type BoardTask } from "../../utils/boardColumns.js";
    import { getStatusStyle } from "../../utils/taskStatus.js";
    import { taskUrl, newTaskUrl, useAppNavigate } from "../../utils/navigation.js";
    import { AnimatePresence, motion } from "motion/react";
    import styles from "./WorkspaceBoard.module.scss";

    /** Props for the WorkspaceBoard component. */
    interface WorkspaceBoardProps {
      workspaceId: string;
      environmentId: string;
      /** All tasks — filtered internally by workspaceId. */
      tasks: TaskData[];
      /** All sessions (used for metadata lookup). */
      sessions: Session[];
      /** All personas (used for metadata lookup). */
      personas: PersonaData[];
      /** All environments (used for metadata lookup). */
      environments: Environment[];
    }

    /** Kanban-style board view with fixed columns for each task status. */
    export function WorkspaceBoard({
      workspaceId,
      environmentId,
      tasks,
      sessions,
      personas,
      environments,
    }: WorkspaceBoardProps): JSX.Element {
      const navigate = useAppNavigate();

      const workspaceTasks = useMemo(
        () => tasks.filter((t) => t.workspaceId === workspaceId),
        [tasks, workspaceId],
      );

      const taskStatusById = useMemo(() => new Map(tasks.map((t) => [t.id, t.status])), [tasks]);

      const tasksById = useMemo(() => new Map(workspaceTasks.map((t) => [t.id, t])), [workspaceTasks]);

      const boardMetadataByTaskId = useMemo(() => {
        const sessionById = new Map(sessions.map((s) => [s.id, s]));
        const personaById = new Map(personas.map((p) => [p.id, p]));
        const environmentById = new Map(environments.map((e) => [e.id, e]));
        const sessionStatusByTaskId = new Map<string, string>();
        const personaNameByTaskId = new Map<string, string>();
        const environmentNameByTaskId = new Map<string, string>();

        for (const task of workspaceTasks) {
          Iif (task.latestSessionId) {
            const session = sessionById.get(task.latestSessionId);
            Iif (session) {
              sessionStatusByTaskId.set(task.id, session.endReason || session.status);

              Iif (session.personaId) {
                const persona = personaById.get(session.personaId);
                Iif (persona) {
                  personaNameByTaskId.set(task.id, persona.name);
                }
              }

              Iif (session.environmentId) {
                const environment = environmentById.get(session.environmentId);
                Iif (environment) {
                  environmentNameByTaskId.set(task.id, environment.displayName);
                }
              }
            }
          }
        }

        return {
          sessionStatusByTaskId,
          personaNameByTaskId,
          environmentNameByTaskId,
        };
      }, [workspaceTasks, sessions, personas, environments]);

      const columns = useMemo(
        () =>
          buildBoardColumns({
            tasks: workspaceTasks,
            taskStatusById,
            sessionStatusByTaskId: boardMetadataByTaskId.sessionStatusByTaskId,
          }),
        [workspaceTasks, taskStatusById, boardMetadataByTaskId],
      );

      if (workspaceTasks.length === 0) {
        return (
          <div className={styles.emptyCta} data-testid="board-empty-cta">
            <button
              className={styles.ctaButton}
              onClick={() => navigate(newTaskUrl(workspaceId, undefined, environmentId))}
            >
              Create Task
            </button>
            <div className={styles.ctaDescription}>
              Break your work into tasks and let agents tackle them
            </div>
          </div>
        );
      }

      return (
        <div className={styles.boardContainer} data-testid="board-container">
          {columns.map((col) => (
            <section
              key={col.status}
              className={styles.column}
              data-testid={`board-column-${col.status}`}
              aria-label={`${col.label}, ${col.tasks.length} ${col.tasks.length === 1 ? "task" : "tasks"}`}
            >
              <div className={styles.columnHeader}>
                <span className={styles.columnIcon} style={{ color: col.style.color }}>
                  {col.style.icon}
                </span>
                <span className={styles.columnLabel}>{col.label}</span>
                <span className={styles.columnCount} data-testid={`board-count-${col.status}`}>
                  {col.tasks.length}
                </span>
              </div>
              <div className={styles.cardList}>
                {col.tasks.length === 0 ? (
                  <div className={styles.emptyPlaceholder}>No tasks</div>
                ) : (
                  <AnimatePresence mode="popLayout">
                    {col.tasks.map((bt) => (
                      <motion.div
                        key={bt.task.id}
                        layout
                        initial={{ opacity: 0, y: 4 }}
                        animate={{ opacity: 1, y: 0 }}
                        exit={{ opacity: 0, y: -4 }}
                        transition={{ duration: 0.15 }}
                      >
                        <BoardCard
                          boardTask={bt}
                          tasksById={tasksById}
                          personaName={boardMetadataByTaskId.personaNameByTaskId.get(bt.task.id)}
                          envName={boardMetadataByTaskId.environmentNameByTaskId.get(bt.task.id)}
                          onClick={() =>
                            navigate(taskUrl(bt.task.id, undefined, workspaceId, environmentId))
                          }
                        />
                      </motion.div>
                    ))}
                  </AnimatePresence>
                )}
              </div>
            </section>
          ))}
        </div>
      );
    }

    // ---------------------------------------------------------------------------
    // BoardCard
    // ---------------------------------------------------------------------------

    interface BoardCardProps {
      boardTask: BoardTask;
      tasksById: Map<string, TaskData>;
      personaName?: string;
      envName?: string;
      onClick: () => void;
    }

    /** Individual card rendered inside a board column. */
    function BoardCard({
      boardTask,
      tasksById,
      personaName,
      envName,
      onClick,
    }: BoardCardProps): JSX.Element {
      const { task, isBlocked, childCount, doneChildCount, pausedSubBadge } = boardTask;
      const statusStyle = getStatusStyle(task.status);
      const parentTask = task.parentTaskId ? tasksById.get(task.parentTaskId) : undefined;

      return (
        <div
          className={styles.card}
          tabIndex={0}
          role="button"
          data-testid={`board-card-${task.id}`}
          onClick={onClick}
          onKeyDown={(e) => {
            if (e.key === "Enter" || e.key === " ") {
              e.preventDefault();
              onClick();
            }
          }}
        >
          <div className={styles.cardHeader}>
            <span className={styles.cardStatusIcon} style={{ color: statusStyle.color }}>
              {statusStyle.icon}
            </span>
            <span className={styles.cardTitle}>{task.title}</span>
          </div>
          <div className={styles.cardBadges}>
            {parentTask && (
              <span className={`${styles.badge} ${styles.parentBadge}`} title={parentTask.title}>
                {parentTask.title}
              </span>
            )}
            {childCount > 0 && (
              <span className={`${styles.badge} ${styles.childBadge}`}>
                {doneChildCount}/{childCount}
              </span>
            )}
            {isBlocked && <span className={`${styles.badge} ${styles.blockedBadge}`}>blocked</span>}
            {task.dependsOn.length > 0 && !isBlocked && (
              <span className={`${styles.badge} ${styles.depBadge}`}>dep</span>
            )}
            {pausedSubBadge && (
              <span className={`${styles.badge} ${styles.pausedSubBadge}`}>{pausedSubBadge}</span>
            )}
            {personaName && (
              <span className={`${styles.badge} ${styles.personaBadge}`}>{personaName}</span>
            )}
            {envName && <span className={`${styles.badge} ${styles.envBadge}`}>{envName}</span>}
          </div>
        </div>
      );
    }