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

GitActionsControl.tsx

735 lines26.5 KB

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