All files / src/components/lists StatusGroupAccordion.tsx

76.92% Statements 10/13
68.42% Branches 13/19
80% Functions 4/5
76.92% Lines 10/13

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                        12x                                                           90x                 12x 12x 12x                                                             85x 85x   85x     85x     7x                                                                                        
import { type CSSProperties, type JSX } from "react";
import { ChevronRight } from "lucide-react";
import { AnimatePresence, motion } from "motion/react";
import type { MatchIndex } from "@grackle-ai/common";
import { ICON_SM } from "../../utils/iconSize.js";
import { taskUrl } from "../../utils/navigation.js";
import type { useAppNavigate } from "../../utils/navigation.js";
import { getStatusStyle, resolveStatus } from "../../utils/taskStatus.js";
import { HighlightedText, type StatusGroup } from "./listHelpers.js";
import styles from "./TaskList.module.scss";
 
/** Base left-padding for task rows. */
const TASK_BASE_INDENT_PX: number = 16;
 
/** Props for the StatusGroupAccordion component. */
export interface StatusGroupAccordionProps {
  /** The status group to render. */
  group: StatusGroup;
  /** Whether the accordion is currently expanded. */
  isExpanded: boolean;
  /** Called when the user toggles the accordion. */
  onToggle: () => void;
  /** ID of the currently selected task, if any. */
  selectedTaskId: string | undefined;
  /** Navigate function from useAppNavigate. */
  navigate: ReturnType<typeof useAppNavigate>;
  /** Per-task title highlight indices for matched search queries. */
  titleHighlights: Map<string, readonly MatchIndex[]>;
  /** Workspace name lookup by workspace ID. */
  workspaceNames: Map<string, string>;
}
 
/** Collapsible accordion for a single task status group. */
export function StatusGroupAccordion({
  group,
  isExpanded,
  onToggle,
  selectedTaskId,
  navigate,
  titleHighlights,
  workspaceNames,
}: StatusGroupAccordionProps): JSX.Element {
  return (
    <div data-testid={`status-group-${group.status}`}>
      <div
        className={styles.statusGroupHeader}
        role="button"
        tabIndex={0}
        aria-expanded={isExpanded}
        onClick={onToggle}
        onKeyDown={(e) => {
          if (e.key === "Enter" || e.key === " ") {
            e.preventDefault();
            onToggle();
          }
        }}
      >
        <span
          className={`${styles.expandArrow} ${isExpanded ? styles.expanded : ""}`}
          aria-hidden="true"
        >
          <ChevronRight size={ICON_SM} />
        </span>
        <span
          className={styles.statusGroupIcon}
          style={{ color: group.style.color }}
          aria-hidden="true"
        >
          {group.style.icon}
        </span>
        <span className={styles.statusGroupLabel}>{group.label}</span>
        <span className={styles.statusGroupCount}>{group.tasks.length}</span>
      </div>
 
      <AnimatePresence>
        {isExpanded && (
          <motion.div
            initial={{ height: 0, opacity: 0 }}
            animate={{ height: "auto", opacity: 1 }}
            exit={{ height: 0, opacity: 0 }}
            transition={{ duration: 0.2 }}
            style={{ overflow: "hidden" }}
          >
            {group.tasks.map((task) => {
              const statusStyle = getStatusStyle(task.status);
              const isSelected = selectedTaskId === task.id;
              const wsName =
                task.parentTaskId || !task.workspaceId
                  ? undefined
                  : workspaceNames.get(task.workspaceId);
              return (
                <div
                  key={task.id}
                  onClick={() => navigate(taskUrl(task.id))}
                  role="button"
                  tabIndex={0}
                  aria-label={task.title}
                  onKeyDown={(e) => {
                    Iif (e.currentTarget === e.target && (e.key === "Enter" || e.key === " ")) {
                      e.preventDefault();
                      navigate(taskUrl(task.id));
                    }
                  }}
                  className={`${styles.taskRow} ${isSelected ? styles.selected : ""}`}
                  style={{ "--task-indent": `${TASK_BASE_INDENT_PX}px` } as CSSProperties}
                  data-task-id={task.id}
                >
                  <span className={styles.leafSpacer} />
                  <span
                    className={styles.taskStatusIcon}
                    style={{ color: statusStyle.color }}
                    aria-hidden="true"
                    data-testid={`task-status-${resolveStatus(task.status)}`}
                  >
                    {statusStyle.icon}
                  </span>
                  <span className={styles.taskTitle} title={task.title}>
                    <HighlightedText
                      text={task.title}
                      indices={titleHighlights.get(task.id)}
                      highlightClass={styles.searchHighlight}
                    />
                  </span>
                  {wsName && (
                    <span className={styles.workspaceBadge} title={wsName}>
                      {wsName}
                    </span>
                  )}
                </div>
              );
            })}
          </motion.div>
        )}
      </AnimatePresence>
    </div>
  );
}