File size: 1,228 Bytes
3201ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useState } from "react";
import type { GitChangeStatus } from "#/api/open-hands.types";
import { FileDiffViewer } from "./file-diff-viewer";

export interface DiffChangeListItem {
  path: string;
  status: GitChangeStatus;
}

export interface DiffChangeListProps {
  changes: DiffChangeListItem[];
  /**
   * When set, each row shows that commit's version of the file instead of
   * the working-tree diff.
   */
  commit?: string;
}

/**
 * Single-open accordion of file diffs. Expanding one path collapses the
 * previously open one (same behavior as the Commits list).
 */
export function DiffChangeList({ changes, commit }: DiffChangeListProps) {
  const [expandedPath, setExpandedPath] = useState<string | null>(null);

  return (
    <div data-testid="diff-change-list" className="w-full flex flex-col">
      {changes.map((change) => (
        <FileDiffViewer
          key={change.path}
          path={change.path}
          type={change.status}
          commit={commit}
          isExpanded={expandedPath === change.path}
          onToggle={() =>
            setExpandedPath((prev) =>
              prev === change.path ? null : change.path,
            )
          }
        />
      ))}
    </div>
  );
}