Open History to see the last commit
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;
48}
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.openPr !== null;
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.";
107}
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 />;
125}
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} />;
138}
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?.openPr?.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?.openPr?.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 prUrl = result.pr.url ?? gitStatusForActions?.openPr?.url;
299 const shouldOfferPushCta = action === "commit" && result.commit.status === "created";
300 const shouldOfferOpenPrCta =
301 (action === "commit_push" || action === "commit_push_pr") && !!prUrl && !isDefaultBranch;
302 const shouldOfferCreatePrCta =
303 action === "commit_push" && !prUrl && result.push.status === "pushed" && !isDefaultBranch;
304 const closeResultToast = () => {
305 toastManager.close(progressToastId);
306 };
307
308 toastManager.update(progressToastId, {
309 type: "success",
310 title: resultToast.title,
311 description: resultToast.description,
312 timeout: 0,
313 data: {
314 ...threadToastData,
315 dismissAfterVisibleMs: 10_000,
316 },
317 ...(shouldOfferPushCta
318 ? {
319 actionProps: {
320 children: "Push",
321 onClick: () => {
322 void runGitActionWithToast({
323 action: "commit_push",
324 forcePushOnlyProgress: true,
325 onConfirmed: closeResultToast,
326 });
327 },
328 },
329 }
330 : shouldOfferOpenPrCta
331 ? {
332 actionProps: {
333 children: "Open PR",
334 onClick: () => {
335 const api = readNativeApi();
336 if (!api) return;
337 closeResultToast();
338 void api.shell.openExternal(prUrl);
339 },
340 },
341 }
342 : shouldOfferCreatePrCta
343 ? {
344 actionProps: {
345 children: "Create PR",
346 onClick: () => {
347 closeResultToast();
348 setActiveDialogAction("create_pr");
349 },
350 },
351 }
352 : {}),
353 });
354 } catch (err) {
355 stopProgressUpdates();
356 toastManager.update(progressToastId, {
357 type: "error",
358 title: "Action failed",
359 description: err instanceof Error ? err.message : "An error occurred.",
360 data: threadToastData,
361 });
362 }
363 },
364
365 [
366 gitStatusForActions?.branch,
367 gitStatusForActions?.hasWorkingTreeChanges,
368 gitStatusForActions?.openPr?.url,
369 isDefaultBranch,
370 maybeConfirmPushToDefaultBranch,
371 runImmediateGitActionMutation,
372 setActiveDialogAction,
373 threadToastData,
374 ],
375 );
376
377 const runQuickAction = useCallback(() => {
378 if (quickAction.kind === "open_pr") {
379 void openExistingPr();
380 return;
381 }
382 if (quickAction.kind === "run_pull") {
383 const promise = pullMutation.mutateAsync();
384 toastManager.promise(promise, {
385 loading: { title: "Pulling...", data: threadToastData },
386 success: (result) => ({
387 title: result.status === "pulled" ? "Pulled" : "Already up to date",
388 description:
389 result.status === "pulled"
390 ? `Updated ${result.branch} from ${result.upstreamBranch ?? "upstream"}`
391 : `${result.branch} is already synchronized.`,
392 data: threadToastData,
393 }),
394 error: (err) => ({
395 title: "Pull failed",
396 description: err instanceof Error ? err.message : "An error occurred.",
397 data: threadToastData,
398 }),
399 });
400 void promise.catch(() => undefined);
401 return;
402 }
403 if (quickAction.kind === "show_hint") {
404 toastManager.add({
405 type: "info",
406 title: quickAction.label,
407 description: quickAction.hint,
408 data: threadToastData,
409 });
410 return;
411 }
412 if (quickAction.action) {
413 void runGitActionWithToast({ action: quickAction.action });
414 }
415 }, [openExistingPr, pullMutation, quickAction, runGitActionWithToast, threadToastData]);
416
417 const openDialogForMenuItem = useCallback(
418 (item: GitActionMenuItem) => {
419 if (item.disabled) return;
420 if (item.kind === "open_pr") {
421 void openExistingPr();
422 return;
423 }
424 if (item.dialogAction === "push") {
425 void runGitActionWithToast({ action: "commit_push", forcePushOnlyProgress: true });
426 return;
427 }
428 if (item.dialogAction) {
429 setActiveDialogAction(item.dialogAction);
430 }
431 },
432 [openExistingPr, runGitActionWithToast],
433 );
434
435 const runDialogAction = useCallback(() => {
436 if (!activeDialogAction) return;
437 const action: GitStackedAction =
438 activeDialogAction === "commit"
439 ? "commit"
440 : activeDialogAction === "push"
441 ? "commit_push"
442 : "commit_push_pr";
443 const commitMessage = activeDialogAction === "commit" ? dialogCommitMessage.trim() : "";
444 const forcePushOnlyProgress = activeDialogAction === "push";
445 setActiveDialogAction(null);
446 void runGitActionWithToast({
447 action,
448 ...(commitMessage ? { commitMessage } : {}),
449 ...(forcePushOnlyProgress ? { forcePushOnlyProgress } : {}),
450 });
451 }, [activeDialogAction, dialogCommitMessage, runGitActionWithToast]);
452
453 const openChangedFileInEditor = useCallback(
454 (filePath: string) => {
455 const api = readNativeApi();
456 if (!api || !gitCwd) {
457 toastManager.add({
458 type: "error",
459 title: "Editor opening is unavailable.",
460 data: threadToastData,
461 });
462 return;
463 }
464 const target = resolvePathLinkTarget(filePath, gitCwd);
465 void api.shell.openInEditor(target, preferredTerminalEditor()).catch((error) => {
466 toastManager.add({
467 type: "error",
468 title: "Unable to open file",
469 description: error instanceof Error ? error.message : "An error occurred.",
470 data: threadToastData,
471 });
472 });
473 },
474 [gitCwd, threadToastData],
475 );
476
477 if (!gitCwd) return null;
478
479 return (
480 <>
481 {!isRepo ? (
482 <Button
483 variant="outline"
484 size="xs"
485 disabled={initMutation.isPending}
486 onClick={() => initMutation.mutate()}
487 >
488 {initMutation.isPending ? "Initializing..." : "Initialize Git"}
489 </Button>
490 ) : (
491 <Group aria-label="Git actions">
492 {quickActionDisabledReason ? (
493 <Popover>
494 <PopoverTrigger
495 openOnHover
496 render={
497 <Button
498 aria-disabled="true"
499 className="cursor-not-allowed rounded-e-none border-e-0 opacity-64 before:rounded-e-none"
500 size="xs"
501 variant="outline"
502 />
503 }
504 >
505 <GitQuickActionIcon quickAction={quickAction} />
506 <span className="sr-only @sm/header-actions:not-sr-only @sm/header-actions:ml-0.5">
507 {quickAction.label}
508 </span>
509 </PopoverTrigger>
510 <PopoverPopup tooltipStyle side="bottom" align="start">
511 {quickActionDisabledReason}
512 </PopoverPopup>
513 </Popover>
514 ) : (
515 <Button
516 variant="outline"
517 size="xs"
518 disabled={isGitActionRunning || quickAction.disabled}
519 onClick={runQuickAction}
520 >
521 <GitQuickActionIcon quickAction={quickAction} />
522 <span className="sr-only @sm/header-actions:not-sr-only @sm/header-actions:ml-0.5">
523 {quickAction.label}
524 </span>
525 </Button>
526 )}
527 <GroupSeparator className="hidden @sm/header-actions:block" />
528 <Menu
529 onOpenChange={(open) => {
530 if (open) void invalidateGitQueries(queryClient);
531 }}
532 >
533 <MenuTrigger
534 render={<Button aria-label="Git action options" size="icon-xs" variant="outline" />}
535 disabled={isGitActionRunning}
536 >
537 <ChevronDownIcon aria-hidden="true" className="size-4" />
538 </MenuTrigger>
539 <MenuPopup align="end" className="w-full">
540 {gitActionMenuItems.map((item) => {
541 const disabledReason = getMenuActionDisabledReason(
542 item,
543 gitStatusForActions,
544 isGitActionRunning,
545 );
546 if (item.disabled && disabledReason) {
547 return (
548 <Popover key={`${item.id}-${item.label}`}>
549 <PopoverTrigger
550 openOnHover
551 nativeButton={false}
552 render={<span className="block w-max cursor-not-allowed" />}
553 >
554 <MenuItem className="w-full" disabled>
555 <GitActionItemIcon icon={item.icon} />
556 {item.label}
557 </MenuItem>
558 </PopoverTrigger>
559 <PopoverPopup tooltipStyle side="left" align="center">
560 {disabledReason}
561 </PopoverPopup>
562 </Popover>
563 );
564 }
565
566 return (
567 <MenuItem
568 key={`${item.id}-${item.label}`}
569 disabled={item.disabled}
570 onClick={() => {
571 openDialogForMenuItem(item);
572 }}
573 >
574 <GitActionItemIcon icon={item.icon} />
575 {item.label}
576 </MenuItem>
577 );
578 })}
579 {gitStatusForActions?.branch === null && (
580 <p className="px-2 py-1.5 text-xs text-warning">
581 Detached HEAD: create and checkout a branch to enable push and PR actions.
582 </p>
583 )}
584 {gitStatusForActions &&
585 gitStatusForActions.branch !== null &&
586 !gitStatusForActions.hasWorkingTreeChanges &&
587 gitStatusForActions.behindCount > 0 &&
588 gitStatusForActions.aheadCount === 0 && (
589 <p className="px-2 py-1.5 text-xs text-warning">
590 Behind upstream. Pull/rebase first.
591 </p>
592 )}
593 {isGitStatusOutOfSync && (
594 <p className="px-2 py-1.5 text-xs text-muted-foreground">
595 Refreshing git status...
596 </p>
597 )}
598 {gitStatusError && (
599 <p className="px-2 py-1.5 text-xs text-destructive">{gitStatusError.message}</p>
600 )}
601 </MenuPopup>
602 </Menu>
603 </Group>
604 )}
605
606 <Dialog
607 open={activeDialogAction !== null}
608 onOpenChange={(open) => {
609 if (!open) {
610 setActiveDialogAction(null);
611 setDialogCommitMessage("");
612 }
613 }}
614 >
615 <DialogPopup>
616 <DialogHeader>
617 <DialogTitle>{DIALOG_TITLE_BY_ACTION[activeDialogAction ?? "commit"]}</DialogTitle>
618 <DialogDescription>
619 {DIALOG_DESCRIPTION_BY_ACTION[activeDialogAction ?? "commit"]}
620 </DialogDescription>
621 </DialogHeader>
622 <DialogPanel className="space-y-4">
623 <div className="space-y-3 rounded-lg border border-input bg-muted/40 p-3 text-xs">
624 <div className="grid grid-cols-[auto_1fr] items-center gap-x-2 gap-y-1">
625 <span className="text-muted-foreground">Branch</span>
626 <span className="font-medium">
627 {gitStatusForActions?.branch ?? "(detached HEAD)"}
628 </span>
629 {activeDialogAction !== "commit" && (
630 <>
631 <span className="text-muted-foreground">Upstream</span>
632 <span className="font-medium">
633 {!gitStatusForActions || !gitStatusForActions.hasUpstream
634 ? "No upstream configured"
635 : gitStatusForActions.aheadCount === 0 &&
636 gitStatusForActions.behindCount === 0
637 ? "Up to date"
638 : gitStatusForActions.aheadCount > 0 &&
639 gitStatusForActions.behindCount > 0
640 ? `Diverged (+${gitStatusForActions.aheadCount} / -${gitStatusForActions.behindCount})`
641 : gitStatusForActions.aheadCount > 0
642 ? `Ahead by ${gitStatusForActions.aheadCount}`
643 : `Behind by ${gitStatusForActions.behindCount}`}
644 </span>
645 <span className="text-muted-foreground">Working tree</span>
646 <span className="font-medium">
647 {!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges
648 ? "Clean"
649 : `${gitStatusForActions.workingTree.files.length} file(s)`}
650 </span>
651 <span className="text-muted-foreground">Diff</span>
652 <span className="font-mono">
653 {!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges ? (
654 "none"
655 ) : (
656 <>
657 <span className="text-success">
658 +{gitStatusForActions.workingTree.insertions}
659 </span>
660 <span className="text-muted-foreground"> / </span>
661 <span className="text-destructive">
662 -{gitStatusForActions.workingTree.deletions}
663 </span>
664 </>
665 )}
666 </span>
667 </>
668 )}
669 </div>
670 <div className="space-y-1">
671 <p className="text-muted-foreground">Files</p>
672 {!gitStatusForActions || gitStatusForActions.workingTree.files.length === 0 ? (
673 <p className="font-medium">none</p>
674 ) : (
675 <div className="space-y-2">
676 <ScrollArea className="h-44 rounded-md border border-input bg-background">
677 <div className="space-y-1 p-1">
678 {gitStatusForActions.workingTree.files.map((file) => (
679 <button
680 type="button"
681 key={file.path}
682 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"
683 onClick={() => openChangedFileInEditor(file.path)}
684 >
685 <span className="truncate">{file.path}</span>
686 <span className="shrink-0">
687 <span className="text-success">+{file.insertions}</span>
688 <span className="text-muted-foreground"> / </span>
689 <span className="text-destructive">-{file.deletions}</span>
690 </span>
691 </button>
692 ))}
693 </div>
694 </ScrollArea>
695 <div className="flex justify-end font-mono">
696 <span className="text-success">
697 +{gitStatusForActions.workingTree.insertions}
698 </span>
699 <span className="text-muted-foreground"> / </span>
700 <span className="text-destructive">
701 -{gitStatusForActions.workingTree.deletions}
702 </span>
703 </div>
704 </div>
705 )}
706 </div>
707 </div>
708 {activeDialogAction === "commit" && (
709 <div className="space-y-1">
710 <p className="text-xs font-medium">Commit message (optional)</p>
711 <Textarea
712 value={dialogCommitMessage}
713 onChange={(event) => setDialogCommitMessage(event.target.value)}
714 placeholder="Leave empty to auto-generate"
715 size="sm"
716 />
717 </div>
718 )}
719 </DialogPanel>
720 <DialogFooter>
721 <Button
722 variant="outline"
723 size="sm"
724 onClick={() => {
725 setActiveDialogAction(null);
726 setDialogCommitMessage("");
727 }}
728 >
729 Cancel
730 </Button>
731 <Button size="sm" onClick={runDialogAction}>
732 {activeDialogAction === "commit"
733 ? "Commit"
734 : activeDialogAction === "push"
735 ? "Push"
736 : "Create PR"}
737 </Button>
738 </DialogFooter>
739 </DialogPopup>
740 </Dialog>
741 </>
742 );
743}