| 1 | import { ApplyState } from "core"; |
| 2 | import { getUriPathBasename } from "core/util/uri"; |
| 3 | import AcceptRejectDiffButtons from "../../../AcceptRejectDiffButtons"; |
| 4 | import FileIcon from "../../../FileIcon"; |
| 5 | |
| 6 | interface PendingApplyStatesToolbarProps { |
| 7 | pendingApplyStates: ApplyState[]; |
| 8 | } |
| 9 | |
| 10 | export function PendingApplyStatesToolbar({ |
| 11 | pendingApplyStates, |
| 12 | }: PendingApplyStatesToolbarProps) { |
| 13 | // Group apply states by filepath |
| 14 | const applyStatesByFilepath = pendingApplyStates.reduce( |
| 15 | (acc, state) => { |
| 16 | const filepath = state.filepath || ""; // Use empty string as fallback |
| 17 | if (!acc[filepath]) { |
| 18 | acc[filepath] = []; |
| 19 | } |
| 20 | acc[filepath].push(state); |
| 21 | return acc; |
| 22 | }, |
| 23 | {} as Record<string, ApplyState[]>, |
| 24 | ); |
| 25 | |
| 26 | return ( |
| 27 | <div className="flex flex-col gap-2"> |
| 28 | {Object.entries(applyStatesByFilepath).map(([filepath, states]) => ( |
| 29 | <div key={filepath} className="flex justify-between gap-3"> |
| 30 | {filepath && ( |
| 31 | <span className="bg-badge flex min-w-0 max-w-[75%] items-center gap-1 truncate rounded pr-1 text-xs"> |
| 32 | <FileIcon filename={filepath} height="18px" width="18px" /> |
| 33 | <span className="truncate">{getUriPathBasename(filepath)}</span> |
| 34 | </span> |
| 35 | )} |
| 36 | <AcceptRejectDiffButtons |
| 37 | applyStates={states} |
| 38 | onAcceptOrReject={async () => {}} |
| 39 | /> |
| 40 | </div> |
| 41 | ))} |
| 42 | </div> |
| 43 | ); |
| 44 | } |