import React from "react"; import { useTranslation } from "react-i18next"; import { GitCommit } from "#/api/open-hands.types"; import { I18nKey } from "#/i18n/declaration"; import { CommitRow } from "./commit-row"; import { UncommittedChangesRow } from "./uncommitted-changes-row"; import type { DiffChangeListItem } from "./diff-change-list"; const UNCOMMITTED_KEY = "uncommitted"; export interface CommitListProps { commits: GitCommit[]; /** True when the server capped the page — surfaces the cap notice. */ hasMore: boolean; uncommittedChanges: DiffChangeListItem[]; autoExpandUncommitted?: boolean; onAutoExpandHandled?: () => void; } /** * The workspace's recent commit history (newest first). Single-open * accordion: expanding a commit collapses the previously expanded one. * Empty/loading/waiting states are the host view's job * (see routes/commits-tab.tsx). */ export function CommitList({ commits, hasMore, uncommittedChanges, autoExpandUncommitted = false, onAutoExpandHandled, }: CommitListProps) { const { t } = useTranslation("openhands"); const [expandedKey, setExpandedKey] = React.useState(null); React.useEffect(() => { if (!autoExpandUncommitted) return; setExpandedKey(UNCOMMITTED_KEY); onAutoExpandHandled?.(); }, [autoExpandUncommitted, onAutoExpandHandled]); // Author is noise when every commit has the same one (the usual // single-agent conversation); show it only when authors differ. const showAuthor = new Set(commits.map((commit) => commit.author)).size > 1; return (
setExpandedKey((prev) => prev === UNCOMMITTED_KEY ? null : UNCOMMITTED_KEY, ) } /> {commits.map((commit) => ( setExpandedKey((prev) => (prev === commit.sha ? null : commit.sha)) } /> ))} {hasMore && (
{t(I18nKey.DIFF_VIEWER$COMMITS_CAP, { count: commits.length })}
)}
); }