Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitActionsControl.tsx

745 lines27.2 KB

1import { type GitStatusResult, type GitStackedAction, type ThreadId } from "@t3tools/contracts";
2import { useIsMutating, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3import { useCallback, useEffect, useMemo, useState } from "react";
4import { ChevronDownIcon, CloudUploadIcon, GitCommitIcon, InfoIcon } from "lucide-react";
5import { GitHubIcon } from "./Icons";
6import {
7 buildGitActionProgressStages,
8 buildMenuItems,
9 type GitActionIconName,
10 type GitActionMenuItem,
11 type GitDialogAction,
12 type GitQuickAction,
13 requiresDefaultBranchConfirmation,
14 resolveQuickAction,
15 summarizeGitResult,
16} from "./GitActionsControl.logic";
17import { Button } from "~/components/ui/button";
18import {
19 Dialog,
20 DialogDescription,
21 DialogFooter,
22 DialogHeader,
23 DialogPanel,
24 DialogPopup,
25 DialogTitle,
26} from "~/components/ui/dialog";
27import { Group, GroupSeparator } from "~/components/ui/group";
28import { Menu, MenuItem, MenuPopup, MenuTrigger } from "~/components/ui/menu";
29import { Popover, PopoverPopup, PopoverTrigger } from "~/components/ui/popover";
30import { ScrollArea } from "~/components/ui/scroll-area";
31import { Textarea } from "~/components/ui/textarea";
32import { toastManager } from "~/components/ui/toast";
33import {
34 gitBranchesQueryOptions,
35 gitInitMutationOptions,
36 gitMutationKeys,
37 gitPullMutationOptions,
38 gitRunStackedActionMutationOptions,
39 gitStatusQueryOptions,
40 invalidateGitQueries,
41} from "~/lib/gitReactQuery";
42import { preferredTerminalEditor, resolvePathLinkTarget } from "~/terminal-links";
43import { readNativeApi } from "~/nativeApi";
44​
45interface GitActionsControlProps {
46 gitCwd: string | null;
47 activeThreadId: ThreadId | null;
49​
50function getMenuActionDisabledReason(
51 item: GitActionMenuItem,
52 gitStatus: GitStatusResult | null,
53 isBusy: boolean,
54): string | null {
55 if (!item.disabled) return null;
56 if (isBusy) return "Git action in progress.";
57 if (!gitStatus) return "Git status is unavailable.";
58​
59 const hasBranch = gitStatus.branch !== null;
60 const hasChanges = gitStatus.hasWorkingTreeChanges;
61 const hasOpenPr = gitStatus.pr?.state === "open";
62 const isAhead = gitStatus.aheadCount > 0;
63 const isBehind = gitStatus.behindCount > 0;
64​
65 if (item.id === "commit") {
66 if (!hasChanges) {
67 return "Worktree is clean. Make changes before committing.";
68 }
69 return "Commit is currently unavailable.";
70 }
71​
72 if (item.id === "push") {
73 if (!hasBranch) {
74 return "Detached HEAD: checkout a branch before pushing.";
75 }
76 if (hasChanges) {
77 return "Commit or stash local changes before pushing.";
78 }
79 if (isBehind) {
80 return "Branch is behind upstream. Pull/rebase before pushing.";
81 }
82 if (!isAhead) {
83 return "No local commits to push.";
84 }
85 return "Push is currently unavailable.";
86 }
87​
88 if (hasOpenPr) {
89 return "Open PR is currently unavailable.";
90 }
91 if (!hasBranch) {
92 return "Detached HEAD: checkout a branch before creating a PR.";
93 }
94 if (hasChanges) {
95 return "Commit local changes before creating a PR.";
96 }
97 if (!isAhead) {
98 return "No local commits to include in a PR.";
99 }
100 if (!gitStatus.hasUpstream) {
101 return "Set an upstream branch before creating a PR.";
102 }
103 if (isBehind) {
104 return "Branch is behind upstream. Pull/rebase before creating a PR.";
105 }
106 return "Create PR is currently unavailable.";
108​
109const DIALOG_TITLE_BY_ACTION = {
110 commit: "Commit changes",
111 push: "Push branch",
112 create_pr: "Create pull request",
113};
114​
115const DIALOG_DESCRIPTION_BY_ACTION = {
116 commit: "Review and confirm your commit. Leave the message blank to auto-generate one.",
117 push: "Push this branch now.",
118 create_pr: "Create a pull request using generated title/body content.",
119};
120​
121function GitActionItemIcon({ icon }: { icon: GitActionIconName }) {
122 if (icon === "commit") return <GitCommitIcon />;
123 if (icon === "push") return <CloudUploadIcon />;
124 return <GitHubIcon />;
126​
127function GitQuickActionIcon({ quickAction }: { quickAction: GitQuickAction }) {
128 const iconClassName = "size-3.5";
129 if (quickAction.kind === "open_pr") return <GitHubIcon className={iconClassName} />;
130 if (quickAction.kind === "run_pull") return <InfoIcon className={iconClassName} />;
131 if (quickAction.kind === "run_action") {
132 if (quickAction.action === "commit") return <GitCommitIcon className={iconClassName} />;
133 if (quickAction.action === "commit_push") return <CloudUploadIcon className={iconClassName} />;
134 return <GitHubIcon className={iconClassName} />;
135 }
136 if (quickAction.label === "Commit") return <GitCommitIcon className={iconClassName} />;
137 return <InfoIcon className={iconClassName} />;
139​
140export default function GitActionsControl({ gitCwd, activeThreadId }: GitActionsControlProps) {
141 const threadToastData = useMemo(
142 () => (activeThreadId ? { threadId: activeThreadId } : undefined),
143 [activeThreadId],
144 );
145 const queryClient = useQueryClient();
146 const [activeDialogAction, setActiveDialogAction] = useState<GitDialogAction | null>(null);
147 const [dialogCommitMessage, setDialogCommitMessage] = useState("");
148​
149 const { data: gitStatus = null, error: gitStatusError } = useQuery(gitStatusQueryOptions(gitCwd));
150​
151 const { data: branchList = null } = useQuery(gitBranchesQueryOptions(gitCwd));
152 // Default to true while loading so we don't flash init controls.
153 const isRepo = branchList?.isRepo ?? true;
154 const currentBranch = branchList?.branches.find((branch) => branch.current)?.name ?? null;
155 const isGitStatusOutOfSync =
156 !!gitStatus?.branch && !!currentBranch && gitStatus.branch !== currentBranch;
157​
158 useEffect(() => {
159 if (!isGitStatusOutOfSync) return;
160 void invalidateGitQueries(queryClient);
161 }, [isGitStatusOutOfSync, queryClient]);
162​
163 const gitStatusForActions = isGitStatusOutOfSync ? null : gitStatus;
164​
165 const initMutation = useMutation(gitInitMutationOptions({ cwd: gitCwd, queryClient }));
166​
167 const runImmediateGitActionMutation = useMutation(
168 gitRunStackedActionMutationOptions({ cwd: gitCwd, queryClient }),
169 );
170 const pullMutation = useMutation(gitPullMutationOptions({ cwd: gitCwd, queryClient }));
171​
172 const isRunStackedActionRunning =
173 useIsMutating({ mutationKey: gitMutationKeys.runStackedAction(gitCwd) }) > 0;
174 const isPullRunning = useIsMutating({ mutationKey: gitMutationKeys.pull(gitCwd) }) > 0;
175 const isGitActionRunning = isRunStackedActionRunning || isPullRunning;
176 const isDefaultBranch = useMemo(() => {
177 const branchName = gitStatusForActions?.branch;
178 if (!branchName) return false;
179 const current = branchList?.branches.find((branch) => branch.name === branchName);
180 return current?.isDefault ?? (branchName === "main" || branchName === "master");
181 }, [branchList?.branches, gitStatusForActions?.branch]);
182​
183 const gitActionMenuItems = useMemo(
184 () => buildMenuItems(gitStatusForActions, isGitActionRunning),
185 [gitStatusForActions, isGitActionRunning],
186 );
187 const quickAction = useMemo(
188 () => resolveQuickAction(gitStatusForActions, isGitActionRunning, isDefaultBranch),
189 [gitStatusForActions, isDefaultBranch, isGitActionRunning],
190 );
191 const quickActionDisabledReason = quickAction.disabled
192 ? (quickAction.hint ?? "This action is currently unavailable.")
193 : null;
194​
195 const maybeConfirmPushToDefaultBranch = useCallback(
196 async (action: GitStackedAction): Promise<boolean> => {
197 const api = readNativeApi();
198 if (!api) return false;
199 if (
200 !requiresDefaultBranchConfirmation(action, isDefaultBranch) ||
201 !gitStatusForActions?.branch
202 ) {
203 return true;
204 }
205 return api.dialogs.confirm(
206 `You're about to push to the default branch "${gitStatusForActions.branch}". Continue?`,
207 );
208 },
209 [gitStatusForActions?.branch, isDefaultBranch],
210 );
211​
212 const openExistingPr = useCallback(async () => {
213 const api = readNativeApi();
214 if (!api) {
215 toastManager.add({
216 type: "error",
217 title: "Link opening is unavailable.",
218 data: threadToastData,
219 });
220 return;
221 }
222 const prUrl = gitStatusForActions?.pr?.state === "open" ? gitStatusForActions.pr.url : null;
223 if (!prUrl) {
224 toastManager.add({
225 type: "error",
226 title: "No open PR found.",
227 data: threadToastData,
228 });
229 return;
230 }
231 void api.shell.openExternal(prUrl).catch((err) => {
232 toastManager.add({
233 type: "error",
234 title: "Unable to open PR link",
235 description: err instanceof Error ? err.message : "An error occurred.",
236 data: threadToastData,
237 });
238 });
239 }, [gitStatusForActions?.pr?.state, gitStatusForActions?.pr?.url, threadToastData]);
240 const runGitActionWithToast = useCallback(
241 async ({
242 action,
243 commitMessage,
244 forcePushOnlyProgress = false,
245 onConfirmed,
246 }: {
247 action: GitStackedAction;
248 commitMessage?: string;
249 forcePushOnlyProgress?: boolean;
250 onConfirmed?: () => void;
251 }) => {
252 const confirmed = await maybeConfirmPushToDefaultBranch(action);
253 if (!confirmed) return;
254 onConfirmed?.();
255​
256 const pushTarget = gitStatusForActions?.branch
257 ? `origin/${gitStatusForActions.branch}`
258 : undefined;
259 const progressStages = buildGitActionProgressStages({
260 action,
261 hasCustomCommitMessage: !!commitMessage?.trim(),
262 hasWorkingTreeChanges: !!gitStatusForActions?.hasWorkingTreeChanges,
263 forcePushOnly: forcePushOnlyProgress,
264 ...(pushTarget ? { pushTarget } : {}),
265 });
266 const progressToastId = toastManager.add({
267 type: "loading",
268 title: progressStages[0] ?? "Running git action...",
269 timeout: 0,
270 data: threadToastData,
271 });
272​
273 let stageIndex = 0;
274 const stageInterval = setInterval(() => {
275 stageIndex = Math.min(stageIndex + 1, progressStages.length - 1);
276 toastManager.update(progressToastId, {
277 title: progressStages[stageIndex] ?? "Running git action...",
278 type: "loading",
279 timeout: 0,
280 data: threadToastData,
281 });
282 }, 1100);
283​
284 const stopProgressUpdates = () => {
285 clearInterval(stageInterval);
286 };
287​
288 const promise = runImmediateGitActionMutation.mutateAsync({
289 action,
290 ...(commitMessage ? { commitMessage } : {}),
291 });
292​
293 try {
294 const result = await promise;
295 stopProgressUpdates();
296 const resultToast = summarizeGitResult(result);
297​
298 const existingOpenPrUrl =
299 gitStatusForActions?.pr?.state === "open" ? gitStatusForActions.pr.url : undefined;
300 const prUrl = result.pr.url ?? existingOpenPrUrl;
301 const shouldOfferPushCta = action === "commit" && result.commit.status === "created";
302 const shouldOfferOpenPrCta =
303 (action === "commit_push" || action === "commit_push_pr") && !!prUrl && !isDefaultBranch;
304 const shouldOfferCreatePrCta =
305 action === "commit_push" && !prUrl && result.push.status === "pushed" && !isDefaultBranch;
306 const closeResultToast = () => {
307 toastManager.close(progressToastId);
308 };
309​
310 toastManager.update(progressToastId, {
311 type: "success",
312 title: resultToast.title,
313 description: resultToast.description,
314 timeout: 0,
315 data: {
316 ...threadToastData,
317 dismissAfterVisibleMs: 10_000,
318 },
319 ...(shouldOfferPushCta
320 ? {
321 actionProps: {
322 children: "Push",
323 onClick: () => {
324 void runGitActionWithToast({
325 action: "commit_push",
326 forcePushOnlyProgress: true,
327 onConfirmed: closeResultToast,
328 });
329 },
330 },
331 }
332 : shouldOfferOpenPrCta
333 ? {
334 actionProps: {
335 children: "Open PR",
336 onClick: () => {
337 const api = readNativeApi();
338 if (!api) return;
339 closeResultToast();
340 void api.shell.openExternal(prUrl);
341 },
342 },
343 }
344 : shouldOfferCreatePrCta
345 ? {
346 actionProps: {
347 children: "Create PR",
348 onClick: () => {
349 closeResultToast();
350 setActiveDialogAction("create_pr");
351 },
352 },
353 }
354 : {}),
355 });
356 } catch (err) {
357 stopProgressUpdates();
358 toastManager.update(progressToastId, {
359 type: "error",
360 title: "Action failed",
361 description: err instanceof Error ? err.message : "An error occurred.",
362 data: threadToastData,
363 });
364 }
365 },
366​
367 [
368 gitStatusForActions?.branch,
369 gitStatusForActions?.hasWorkingTreeChanges,
370 gitStatusForActions?.pr,
371 isDefaultBranch,
372 maybeConfirmPushToDefaultBranch,
373 runImmediateGitActionMutation,
374 setActiveDialogAction,
375 threadToastData,
376 ],
377 );
378​
379 const runQuickAction = useCallback(() => {
380 if (quickAction.kind === "open_pr") {
381 void openExistingPr();
382 return;
383 }
384 if (quickAction.kind === "run_pull") {
385 const promise = pullMutation.mutateAsync();
386 toastManager.promise(promise, {
387 loading: { title: "Pulling...", data: threadToastData },
388 success: (result) => ({
389 title: result.status === "pulled" ? "Pulled" : "Already up to date",
390 description:
391 result.status === "pulled"
392 ? `Updated ${result.branch} from ${result.upstreamBranch ?? "upstream"}`
393 : `${result.branch} is already synchronized.`,
394 data: threadToastData,
395 }),
396 error: (err) => ({
397 title: "Pull failed",
398 description: err instanceof Error ? err.message : "An error occurred.",
399 data: threadToastData,
400 }),
401 });
402 void promise.catch(() => undefined);
403 return;
404 }
405 if (quickAction.kind === "show_hint") {
406 toastManager.add({
407 type: "info",
408 title: quickAction.label,
409 description: quickAction.hint,
410 data: threadToastData,
411 });
412 return;
413 }
414 if (quickAction.action) {
415 void runGitActionWithToast({ action: quickAction.action });
416 }
417 }, [openExistingPr, pullMutation, quickAction, runGitActionWithToast, threadToastData]);
418​
419 const openDialogForMenuItem = useCallback(
420 (item: GitActionMenuItem) => {
421 if (item.disabled) return;
422 if (item.kind === "open_pr") {
423 void openExistingPr();
424 return;
425 }
426 if (item.dialogAction === "push") {
427 void runGitActionWithToast({ action: "commit_push", forcePushOnlyProgress: true });
428 return;
429 }
430 if (item.dialogAction) {
431 setActiveDialogAction(item.dialogAction);
432 }
433 },
434 [openExistingPr, runGitActionWithToast],
435 );
436​
437 const runDialogAction = useCallback(() => {
438 if (!activeDialogAction) return;
439 const action: GitStackedAction =
440 activeDialogAction === "commit"
441 ? "commit"
442 : activeDialogAction === "push"
443 ? "commit_push"
444 : "commit_push_pr";
445 const commitMessage = activeDialogAction === "commit" ? dialogCommitMessage.trim() : "";
446 const forcePushOnlyProgress = activeDialogAction === "push";
447 setActiveDialogAction(null);
448 void runGitActionWithToast({
449 action,
450 ...(commitMessage ? { commitMessage } : {}),
451 ...(forcePushOnlyProgress ? { forcePushOnlyProgress } : {}),
452 });
453 }, [activeDialogAction, dialogCommitMessage, runGitActionWithToast]);
454​
455 const openChangedFileInEditor = useCallback(
456 (filePath: string) => {
457 const api = readNativeApi();
458 if (!api || !gitCwd) {
459 toastManager.add({
460 type: "error",
461 title: "Editor opening is unavailable.",
462 data: threadToastData,
463 });
464 return;
465 }
466 const target = resolvePathLinkTarget(filePath, gitCwd);
467 void api.shell.openInEditor(target, preferredTerminalEditor()).catch((error) => {
468 toastManager.add({
469 type: "error",
470 title: "Unable to open file",
471 description: error instanceof Error ? error.message : "An error occurred.",
472 data: threadToastData,
473 });
474 });
475 },
476 [gitCwd, threadToastData],
477 );
478​
479 if (!gitCwd) return null;
480​
481 return (
482 <>
483 {!isRepo ? (
484 <Button
485 variant="outline"
486 size="xs"
487 disabled={initMutation.isPending}
488 onClick={() => initMutation.mutate()}
489 >
490 {initMutation.isPending ? "Initializing..." : "Initialize Git"}
491 </Button>
492 ) : (
493 <Group aria-label="Git actions">
494 {quickActionDisabledReason ? (
495 <Popover>
496 <PopoverTrigger
497 openOnHover
498 render={
499 <Button
500 aria-disabled="true"
501 className="cursor-not-allowed rounded-e-none border-e-0 opacity-64 before:rounded-e-none"
502 size="xs"
503 variant="outline"
504 />
505 }
506 >
507 <GitQuickActionIcon quickAction={quickAction} />
508 <span className="sr-only @sm/header-actions:not-sr-only @sm/header-actions:ml-0.5">
509 {quickAction.label}
510 </span>
511 </PopoverTrigger>
512 <PopoverPopup tooltipStyle side="bottom" align="start">
513 {quickActionDisabledReason}
514 </PopoverPopup>
515 </Popover>
516 ) : (
517 <Button
518 variant="outline"
519 size="xs"
520 disabled={isGitActionRunning || quickAction.disabled}
521 onClick={runQuickAction}
522 >
523 <GitQuickActionIcon quickAction={quickAction} />
524 <span className="sr-only @sm/header-actions:not-sr-only @sm/header-actions:ml-0.5">
525 {quickAction.label}
526 </span>
527 </Button>
528 )}
529 <GroupSeparator className="hidden @sm/header-actions:block" />
530 <Menu
531 onOpenChange={(open) => {
532 if (open) void invalidateGitQueries(queryClient);
533 }}
534 >
535 <MenuTrigger
536 render={<Button aria-label="Git action options" size="icon-xs" variant="outline" />}
537 disabled={isGitActionRunning}
538 >
539 <ChevronDownIcon aria-hidden="true" className="size-4" />
540 </MenuTrigger>
541 <MenuPopup align="end" className="w-full">
542 {gitActionMenuItems.map((item) => {
543 const disabledReason = getMenuActionDisabledReason(
544 item,
545 gitStatusForActions,
546 isGitActionRunning,
547 );
548 if (item.disabled && disabledReason) {
549 return (
550 <Popover key={`${item.id}-${item.label}`}>
551 <PopoverTrigger
552 openOnHover
553 nativeButton={false}
554 render={<span className="block w-max cursor-not-allowed" />}
555 >
556 <MenuItem className="w-full" disabled>
557 <GitActionItemIcon icon={item.icon} />
558 {item.label}
559 </MenuItem>
560 </PopoverTrigger>
561 <PopoverPopup tooltipStyle side="left" align="center">
562 {disabledReason}
563 </PopoverPopup>
564 </Popover>
565 );
566 }
567​
568 return (
569 <MenuItem
570 key={`${item.id}-${item.label}`}
571 disabled={item.disabled}
572 onClick={() => {
573 openDialogForMenuItem(item);
574 }}
575 >
576 <GitActionItemIcon icon={item.icon} />
577 {item.label}
578 </MenuItem>
579 );
580 })}
581 {gitStatusForActions?.branch === null && (
582 <p className="px-2 py-1.5 text-xs text-warning">
583 Detached HEAD: create and checkout a branch to enable push and PR actions.
584 </p>
585 )}
586 {gitStatusForActions &&
587 gitStatusForActions.branch !== null &&
588 !gitStatusForActions.hasWorkingTreeChanges &&
589 gitStatusForActions.behindCount > 0 &&
590 gitStatusForActions.aheadCount === 0 && (
591 <p className="px-2 py-1.5 text-xs text-warning">
592 Behind upstream. Pull/rebase first.
593 </p>
594 )}
595 {isGitStatusOutOfSync && (
596 <p className="px-2 py-1.5 text-xs text-muted-foreground">
597 Refreshing git status...
598 </p>
599 )}
600 {gitStatusError && (
601 <p className="px-2 py-1.5 text-xs text-destructive">{gitStatusError.message}</p>
602 )}
603 </MenuPopup>
604 </Menu>
605 </Group>
606 )}
607​
608 <Dialog
609 open={activeDialogAction !== null}
610 onOpenChange={(open) => {
611 if (!open) {
612 setActiveDialogAction(null);
613 setDialogCommitMessage("");
614 }
615 }}
616 >
617 <DialogPopup>
618 <DialogHeader>
619 <DialogTitle>{DIALOG_TITLE_BY_ACTION[activeDialogAction ?? "commit"]}</DialogTitle>
620 <DialogDescription>
621 {DIALOG_DESCRIPTION_BY_ACTION[activeDialogAction ?? "commit"]}
622 </DialogDescription>
623 </DialogHeader>
624 <DialogPanel className="space-y-4">
625 <div className="space-y-3 rounded-lg border border-input bg-muted/40 p-3 text-xs">
626 <div className="grid grid-cols-[auto_1fr] items-center gap-x-2 gap-y-1">
627 <span className="text-muted-foreground">Branch</span>
628 <span className="font-medium">
629 {gitStatusForActions?.branch ?? "(detached HEAD)"}
630 </span>
631 {activeDialogAction !== "commit" && (
632 <>
633 <span className="text-muted-foreground">Upstream</span>
634 <span className="font-medium">
635 {!gitStatusForActions || !gitStatusForActions.hasUpstream
636 ? "No upstream configured"
637 : gitStatusForActions.aheadCount === 0 &&
638 gitStatusForActions.behindCount === 0
639 ? "Up to date"
640 : gitStatusForActions.aheadCount > 0 &&
641 gitStatusForActions.behindCount > 0
642 ? `Diverged (+${gitStatusForActions.aheadCount} / -${gitStatusForActions.behindCount})`
643 : gitStatusForActions.aheadCount > 0
644 ? `Ahead by ${gitStatusForActions.aheadCount}`
645 : `Behind by ${gitStatusForActions.behindCount}`}
646 </span>
647 <span className="text-muted-foreground">Working tree</span>
648 <span className="font-medium">
649 {!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges
650 ? "Clean"
651 : `${gitStatusForActions.workingTree.files.length} file(s)`}
652 </span>
653 <span className="text-muted-foreground">Diff</span>
654 <span className="font-mono">
655 {!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges ? (
656 "none"
657 ) : (
658 <>
659 <span className="text-success">
660 +{gitStatusForActions.workingTree.insertions}
661 </span>
662 <span className="text-muted-foreground"> / </span>
663 <span className="text-destructive">
664 -{gitStatusForActions.workingTree.deletions}
665 </span>
666 </>
667 )}
668 </span>
669 </>
670 )}
671 </div>
672 <div className="space-y-1">
673 <p className="text-muted-foreground">Files</p>
674 {!gitStatusForActions || gitStatusForActions.workingTree.files.length === 0 ? (
675 <p className="font-medium">none</p>
676 ) : (
677 <div className="space-y-2">
678 <ScrollArea className="h-44 rounded-md border border-input bg-background">
679 <div className="space-y-1 p-1">
680 {gitStatusForActions.workingTree.files.map((file) => (
681 <button
682 type="button"
683 key={file.path}
684 className="flex w-full items-center justify-between gap-3 rounded-md px-2 py-1 font-mono text-left transition-colors hover:bg-accent/50"
685 onClick={() => openChangedFileInEditor(file.path)}
686 >
687 <span className="truncate">{file.path}</span>
688 <span className="shrink-0">
689 <span className="text-success">+{file.insertions}</span>
690 <span className="text-muted-foreground"> / </span>
691 <span className="text-destructive">-{file.deletions}</span>
692 </span>
693 </button>
694 ))}
695 </div>
696 </ScrollArea>
697 <div className="flex justify-end font-mono">
698 <span className="text-success">
699 +{gitStatusForActions.workingTree.insertions}
700 </span>
701 <span className="text-muted-foreground"> / </span>
702 <span className="text-destructive">
703 -{gitStatusForActions.workingTree.deletions}
704 </span>
705 </div>
706 </div>
707 )}
708 </div>
709 </div>
710 {activeDialogAction === "commit" && (
711 <div className="space-y-1">
712 <p className="text-xs font-medium">Commit message (optional)</p>
713 <Textarea
714 value={dialogCommitMessage}
715 onChange={(event) => setDialogCommitMessage(event.target.value)}
716 placeholder="Leave empty to auto-generate"
717 size="sm"
718 />
719 </div>
720 )}
721 </DialogPanel>
722 <DialogFooter>
723 <Button
724 variant="outline"
725 size="sm"
726 onClick={() => {
727 setActiveDialogAction(null);
728 setDialogCommitMessage("");
729 }}
730 >
731 Cancel
732 </Button>
733 <Button size="sm" onClick={runDialogAction}>
734 {activeDialogAction === "commit"
735 ? "Commit"
736 : activeDialogAction === "push"
737 ? "Push"
738 : "Create PR"}
739 </Button>
740 </DialogFooter>
741 </DialogPopup>
742 </Dialog>
743 </>
744 );