Improve git action menu and modal workflow
- Split Git actions into context-aware Commit, Push, and PR menu items - Add modal action selection with clearer availability and disabled-state guidance - Migrate git status and immediate actions to React Query and add a custom GitHub icon Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
62cc55ab06
commit
9accd1ffb7
2 files changed
+354
-227
No files matched your search
@@ -4,36 +4,44 @@ import {
|
||||
type GitStatusResult,
|
||||
type NativeApi,
|
||||
} from "@t3tools/contracts";
|
||||
import { queryOptions, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import {
|
||||
CheckIcon,
|
||||
CircleIcon,
|
||||
CloudUploadIcon,
|
||||
GitCommitIcon,
|
||||
GithubIcon,
|
||||
Loader2Icon,
|
||||
MinusIcon,
|
||||
XIcon,
|
||||
} from "lucide-react";
|
||||
import { GitHubIcon } from "./Icons";
|
||||
|
||||
interface GitActionsControlProps {
|
||||
api: NativeApi | undefined;
|
||||
gitCwd: string | null;
|
||||
}
|
||||
|
||||
type GitActionIconName = "commit" | "push" | "pr";
|
||||
|
||||
interface GitActionMenuItem {
|
||||
id: GitStackedAction;
|
||||
id: "commit" | "push" | "pr";
|
||||
label: string;
|
||||
disabled: boolean;
|
||||
icon: "commit" | "push" | "pr";
|
||||
icon: GitActionIconName;
|
||||
kind: "open_modal" | "run_action" | "open_pr";
|
||||
action?: GitStackedAction;
|
||||
}
|
||||
|
||||
type GitProgressStepStatus =
|
||||
| "pending"
|
||||
| "running"
|
||||
| "completed"
|
||||
| "skipped"
|
||||
| "failed";
|
||||
interface GitModalActionOption {
|
||||
action: GitStackedAction;
|
||||
label: string;
|
||||
disabled: boolean;
|
||||
icon: GitActionIconName;
|
||||
detail?: string;
|
||||
}
|
||||
|
||||
type GitProgressStepStatus = "pending" | "running" | "completed" | "skipped" | "failed";
|
||||
|
||||
interface GitProgressStep {
|
||||
id: "generate" | "commit" | "push" | "pr";
|
||||
@@ -42,7 +50,7 @@ interface GitProgressStep {
|
||||
detail?: string;
|
||||
}
|
||||
|
||||
function GitActionIcon(props: { icon: GitActionMenuItem["icon"]; disabled: boolean }) {
|
||||
function GitActionIcon(props: { icon: GitActionIconName; disabled: boolean }) {
|
||||
const toneClass = props.disabled ? "text-muted-foreground/45" : "text-foreground/85";
|
||||
|
||||
if (props.icon === "commit") {
|
||||
@@ -53,13 +61,11 @@ function GitActionIcon(props: { icon: GitActionMenuItem["icon"]; disabled: boole
|
||||
return <CloudUploadIcon className={`h-5 w-5 shrink-0 ${toneClass}`} />;
|
||||
}
|
||||
|
||||
return <GithubIcon className={`h-5 w-5 shrink-0 ${toneClass}`} />;
|
||||
return <GitHubIcon className={`h-5 w-5 shrink-0 ${toneClass}`} />;
|
||||
}
|
||||
|
||||
function gitActionModalTitle(action: GitStackedAction): string {
|
||||
if (action === "commit") return "Commit your changes";
|
||||
if (action === "commit_push") return "Commit and push changes";
|
||||
return "Commit, push and open PR";
|
||||
function gitActionModalTitle(): string {
|
||||
return "Commit your changes";
|
||||
}
|
||||
|
||||
function initialGitProgressSteps(
|
||||
@@ -119,102 +125,198 @@ function updateProgressStep(
|
||||
}
|
||||
|
||||
function runActionLabel(action: GitStackedAction): string {
|
||||
if (action === "commit") return "Commit";
|
||||
if (action === "commit_push") return "Commit & Push";
|
||||
return "Commit, Push & Open PR";
|
||||
if (action === "commit") return "Commit changes";
|
||||
if (action === "commit_push") return "Commit and push";
|
||||
return "Commit and create PR";
|
||||
}
|
||||
|
||||
function isViewPrOnlyAction(
|
||||
action: GitStackedAction,
|
||||
function buildGitActionMenuItems(
|
||||
gitStatus: GitStatusResult | null,
|
||||
): boolean {
|
||||
if (action !== "commit_push_pr") return false;
|
||||
if (!gitStatus?.openPr) return false;
|
||||
return !gitStatus.hasWorkingTreeChanges && gitStatus.aheadCount === 0;
|
||||
isDisabled: boolean,
|
||||
): GitActionMenuItem[] {
|
||||
if (!gitStatus) return [];
|
||||
|
||||
const hasBranch = gitStatus.branch !== null;
|
||||
const hasOpenPr = gitStatus.openPr !== null;
|
||||
const hasChanges = gitStatus.hasWorkingTreeChanges;
|
||||
const hasAhead = gitStatus.aheadCount > 0;
|
||||
const canCommit = !isDisabled && hasChanges;
|
||||
const canPush = !isDisabled && hasBranch && !hasChanges && hasAhead;
|
||||
const canOpenPr = !isDisabled && hasOpenPr;
|
||||
const canCreatePr =
|
||||
!isDisabled &&
|
||||
hasBranch &&
|
||||
!hasOpenPr &&
|
||||
!hasChanges &&
|
||||
gitStatus.hasUpstream &&
|
||||
gitStatus.behindCount === 0;
|
||||
|
||||
if (!hasChanges && !hasAhead && hasOpenPr) {
|
||||
return [
|
||||
{
|
||||
id: "pr",
|
||||
label: "Open PR",
|
||||
disabled: !canOpenPr,
|
||||
icon: "pr",
|
||||
kind: "open_pr",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
id: "commit",
|
||||
label: "Commit",
|
||||
disabled: !canCommit,
|
||||
icon: "commit",
|
||||
kind: "open_modal",
|
||||
},
|
||||
{
|
||||
id: "push",
|
||||
label: "Push",
|
||||
disabled: !canPush,
|
||||
icon: "push",
|
||||
kind: "run_action",
|
||||
action: "commit_push",
|
||||
},
|
||||
hasOpenPr
|
||||
? {
|
||||
id: "pr",
|
||||
label: "View PR",
|
||||
disabled: !canOpenPr,
|
||||
icon: "pr",
|
||||
kind: "open_pr",
|
||||
}
|
||||
: {
|
||||
id: "pr",
|
||||
label: "Create PR",
|
||||
disabled: !canCreatePr,
|
||||
icon: "pr",
|
||||
kind: "run_action",
|
||||
action: "commit_push_pr",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function buildGitModalActionOptions(
|
||||
gitStatus: GitStatusResult | null,
|
||||
isDisabled: boolean,
|
||||
): GitModalActionOption[] {
|
||||
const hasBranch = gitStatus?.branch !== null;
|
||||
const hasOpenPr = gitStatus?.openPr !== null;
|
||||
|
||||
return [
|
||||
{
|
||||
action: "commit",
|
||||
label: "Commit",
|
||||
disabled: isDisabled,
|
||||
icon: "commit",
|
||||
},
|
||||
{
|
||||
action: "commit_push",
|
||||
label: "Commit and push",
|
||||
disabled: isDisabled || !hasBranch,
|
||||
icon: "push",
|
||||
...(!hasBranch ? { detail: "Requires an attached branch." } : {}),
|
||||
},
|
||||
{
|
||||
action: "commit_push_pr",
|
||||
label: "Commit and create PR",
|
||||
disabled: isDisabled || !hasBranch || hasOpenPr,
|
||||
icon: "pr",
|
||||
...(!hasBranch
|
||||
? { detail: "Requires an attached branch." }
|
||||
: hasOpenPr
|
||||
? { detail: "A PR is already open for this branch." }
|
||||
: {}),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getGitStatusQueryKey(gitCwd: string | null): readonly ["git", "status", string | null] {
|
||||
return ["git", "status", gitCwd];
|
||||
}
|
||||
|
||||
function gitStatusQueryOptions(api: NativeApi | undefined, gitCwd: string | null) {
|
||||
return queryOptions({
|
||||
queryKey: getGitStatusQueryKey(gitCwd),
|
||||
queryFn: async () => {
|
||||
if (!api || !gitCwd) {
|
||||
throw new Error("Git status is unavailable.");
|
||||
}
|
||||
return api.git.status({ cwd: gitCwd });
|
||||
},
|
||||
enabled: !!api && !!gitCwd,
|
||||
});
|
||||
}
|
||||
|
||||
export default function GitActionsControl({ api, gitCwd }: GitActionsControlProps) {
|
||||
const queryClient = useQueryClient();
|
||||
const [isGitMenuOpen, setIsGitMenuOpen] = useState(false);
|
||||
const [isGitActionRunning, setIsGitActionRunning] = useState(false);
|
||||
const [gitStatus, setGitStatus] = useState<GitStatusResult | null>(null);
|
||||
const [isGitModalActionRunning, setIsGitModalActionRunning] = useState(false);
|
||||
const [gitActionError, setGitActionError] = useState<string | null>(null);
|
||||
const [gitModalAction, setGitModalAction] = useState<GitStackedAction | null>(null);
|
||||
const [isGitModalOpen, setIsGitModalOpen] = useState(false);
|
||||
const [gitModalSelectedAction, setGitModalSelectedAction] = useState<GitStackedAction>("commit");
|
||||
const [gitModalCommitMessage, setGitModalCommitMessage] = useState("");
|
||||
const [gitModalProgress, setGitModalProgress] = useState<GitProgressStep[]>([]);
|
||||
const [gitModalError, setGitModalError] = useState<string | null>(null);
|
||||
const [gitModalResult, setGitModalResult] = useState<GitRunStackedActionResult | null>(null);
|
||||
const gitMenuRef = useRef<HTMLDivElement>(null);
|
||||
const latestGitCwdRef = useRef<string | null>(null);
|
||||
|
||||
const { data: gitStatus = null, error: gitStatusError } = useQuery(
|
||||
gitStatusQueryOptions(api, gitCwd),
|
||||
);
|
||||
|
||||
const runImmediateGitActionMutation = useMutation({
|
||||
mutationFn: async (action: GitStackedAction) => {
|
||||
if (!api || !gitCwd) {
|
||||
throw new Error("Git action is unavailable.");
|
||||
}
|
||||
return api.git.runStackedAction({ cwd: gitCwd, action });
|
||||
},
|
||||
onMutate: () => {
|
||||
setIsGitMenuOpen(false);
|
||||
setGitActionError(null);
|
||||
setGitModalError(null);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ["git"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
setGitActionError(error instanceof Error ? error.message : "Git action failed.");
|
||||
},
|
||||
});
|
||||
|
||||
const isGitActionRunning = isGitModalActionRunning || runImmediateGitActionMutation.isPending;
|
||||
|
||||
const gitBaseDisabled = !api || !gitCwd || !gitStatus || isGitActionRunning;
|
||||
const gitActionMenuItems = useMemo<GitActionMenuItem[]>(() => {
|
||||
if (!gitStatus) return [];
|
||||
|
||||
const hasBranch = gitStatus.branch !== null;
|
||||
const hasOpenPr = gitStatus.openPr !== null;
|
||||
const canCommit = !gitBaseDisabled && gitStatus.hasWorkingTreeChanges;
|
||||
const canPush =
|
||||
!gitBaseDisabled &&
|
||||
hasBranch &&
|
||||
(gitStatus.hasWorkingTreeChanges || gitStatus.aheadCount > 0);
|
||||
const canViewPr =
|
||||
!gitBaseDisabled &&
|
||||
hasBranch &&
|
||||
gitStatus.behindCount === 0 &&
|
||||
(gitStatus.hasWorkingTreeChanges || gitStatus.aheadCount > 0 || hasOpenPr);
|
||||
|
||||
return [
|
||||
{
|
||||
id: "commit",
|
||||
label: "Commit",
|
||||
disabled: !canCommit,
|
||||
icon: "commit",
|
||||
},
|
||||
{
|
||||
id: "commit_push",
|
||||
label: "Push",
|
||||
disabled: !canPush,
|
||||
icon: "push",
|
||||
},
|
||||
{
|
||||
id: "commit_push_pr",
|
||||
label: "View PR",
|
||||
disabled: !canViewPr,
|
||||
icon: "pr",
|
||||
},
|
||||
];
|
||||
}, [gitBaseDisabled, gitStatus]);
|
||||
|
||||
const isGitModalOpen = gitModalAction !== null;
|
||||
const gitModalPreviewSteps = useMemo(
|
||||
() =>
|
||||
gitModalAction
|
||||
? initialGitProgressSteps(gitModalAction, gitModalCommitMessage)
|
||||
: ([] as GitProgressStep[]),
|
||||
[gitModalAction, gitModalCommitMessage],
|
||||
const gitActionMenuItems = useMemo(
|
||||
() => buildGitActionMenuItems(gitStatus, gitBaseDisabled),
|
||||
[gitBaseDisabled, gitStatus],
|
||||
);
|
||||
const gitModalSteps = gitModalProgress.length > 0 ? gitModalProgress : gitModalPreviewSteps;
|
||||
|
||||
useEffect(() => {
|
||||
latestGitCwdRef.current = gitCwd;
|
||||
}, [gitCwd]);
|
||||
const gitModalActionOptions = useMemo(
|
||||
() => buildGitModalActionOptions(gitStatus, !gitStatus || isGitActionRunning),
|
||||
[gitStatus, isGitActionRunning],
|
||||
);
|
||||
const selectedGitModalActionOption = useMemo(
|
||||
() => gitModalActionOptions.find((option) => option.action === gitModalSelectedAction) ?? null,
|
||||
[gitModalActionOptions, gitModalSelectedAction],
|
||||
);
|
||||
const visibleGitActionError = gitActionError ?? gitStatusError?.message;
|
||||
const gitModalHasProgress = gitModalProgress.length > 0;
|
||||
const gitModalSelectionMode = !gitModalHasProgress && gitModalResult === null;
|
||||
const gitModalSteps = gitModalProgress;
|
||||
|
||||
const refreshGitStatus = useCallback(async () => {
|
||||
const requestCwd = gitCwd;
|
||||
if (!api || !requestCwd) {
|
||||
setGitStatus(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const nextStatus = await api.git.status({ cwd: requestCwd });
|
||||
if (latestGitCwdRef.current !== requestCwd) return;
|
||||
setGitStatus(nextStatus);
|
||||
if (!api || !gitCwd) return;
|
||||
await queryClient.invalidateQueries({ queryKey: ["git"] });
|
||||
setGitActionError(null);
|
||||
}, [api, gitCwd]);
|
||||
}, [api, gitCwd, queryClient]);
|
||||
|
||||
const openGitActionModal = useCallback((action: GitStackedAction) => {
|
||||
const openGitActionModal = useCallback(() => {
|
||||
setIsGitMenuOpen(false);
|
||||
setGitModalAction(action);
|
||||
setIsGitModalOpen(true);
|
||||
setGitModalSelectedAction("commit");
|
||||
setGitModalCommitMessage("");
|
||||
setGitModalProgress([]);
|
||||
setGitModalError(null);
|
||||
@@ -224,7 +326,8 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
|
||||
const closeGitActionModal = useCallback(() => {
|
||||
if (isGitActionRunning) return;
|
||||
setGitModalAction(null);
|
||||
setIsGitModalOpen(false);
|
||||
setGitModalSelectedAction("commit");
|
||||
setGitModalCommitMessage("");
|
||||
setGitModalProgress([]);
|
||||
setGitModalError(null);
|
||||
@@ -232,44 +335,37 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
}, [isGitActionRunning]);
|
||||
|
||||
const runGitActionImmediately = useCallback(
|
||||
async (action: GitStackedAction) => {
|
||||
if (!api || !gitCwd) return;
|
||||
const actionCwd = gitCwd;
|
||||
|
||||
setIsGitMenuOpen(false);
|
||||
setGitActionError(null);
|
||||
setGitModalError(null);
|
||||
setIsGitActionRunning(true);
|
||||
|
||||
try {
|
||||
await api.git.runStackedAction({
|
||||
cwd: actionCwd,
|
||||
action,
|
||||
});
|
||||
} catch (error) {
|
||||
setGitActionError(error instanceof Error ? error.message : "Git action failed.");
|
||||
} finally {
|
||||
setIsGitActionRunning(false);
|
||||
try {
|
||||
if (latestGitCwdRef.current === actionCwd) {
|
||||
await refreshGitStatus();
|
||||
}
|
||||
} catch {
|
||||
setGitStatus(null);
|
||||
}
|
||||
}
|
||||
(action: GitStackedAction) => {
|
||||
runImmediateGitActionMutation.mutate(action);
|
||||
},
|
||||
[api, gitCwd, refreshGitStatus],
|
||||
[runImmediateGitActionMutation],
|
||||
);
|
||||
|
||||
const openExistingPr = useCallback(() => {
|
||||
setIsGitMenuOpen(false);
|
||||
setGitActionError(null);
|
||||
|
||||
const prUrl = gitStatus?.openPr?.url ?? null;
|
||||
if (!prUrl) {
|
||||
setGitActionError("No open PR found for the current branch.");
|
||||
return;
|
||||
}
|
||||
|
||||
const popup = window.open(prUrl, "_blank", "noopener,noreferrer");
|
||||
if (!popup) {
|
||||
setGitActionError("Unable to open PR. Allow popups and try again.");
|
||||
}
|
||||
}, [gitStatus?.openPr?.url]);
|
||||
|
||||
const runGitAction = useCallback(async () => {
|
||||
if (!api || !gitCwd || !gitModalAction) return;
|
||||
if (!api || !gitCwd || !isGitModalOpen) return;
|
||||
if (!selectedGitModalActionOption || selectedGitModalActionOption.disabled) return;
|
||||
const actionCwd = gitCwd;
|
||||
const action = gitModalAction;
|
||||
const action = selectedGitModalActionOption.action;
|
||||
const commitMessage = gitModalCommitMessage.trim();
|
||||
const includeGeneratedCommitMessage = commitMessage.length === 0;
|
||||
|
||||
setIsGitActionRunning(true);
|
||||
setIsGitModalActionRunning(true);
|
||||
setGitModalError(null);
|
||||
setGitActionError(null);
|
||||
setGitModalResult(null);
|
||||
@@ -322,11 +418,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
}
|
||||
|
||||
if (commitRun.commit.status === "created") {
|
||||
updateStep(
|
||||
"commit",
|
||||
"completed",
|
||||
commitRun.commit.subject ?? "Committed local changes.",
|
||||
);
|
||||
updateStep("commit", "completed", commitRun.commit.subject ?? "Committed local changes.");
|
||||
} else {
|
||||
updateStep("commit", "skipped", "No local changes to commit.");
|
||||
}
|
||||
@@ -362,9 +454,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
updateStep(
|
||||
"pr",
|
||||
"completed",
|
||||
prRun.pr.number
|
||||
? `Opened existing PR #${prRun.pr.number}.`
|
||||
: "Opened existing PR.",
|
||||
prRun.pr.number ? `Opened existing PR #${prRun.pr.number}.` : "Opened existing PR.",
|
||||
);
|
||||
} else if (prRun.pr.status === "created") {
|
||||
updateStep(
|
||||
@@ -388,53 +478,37 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
return updateProgressStep(steps, active.id, "failed", message);
|
||||
});
|
||||
} finally {
|
||||
setIsGitActionRunning(false);
|
||||
try {
|
||||
if (latestGitCwdRef.current === actionCwd) {
|
||||
await refreshGitStatus();
|
||||
}
|
||||
} catch {
|
||||
setGitStatus(null);
|
||||
}
|
||||
setIsGitModalActionRunning(false);
|
||||
await refreshGitStatus().catch(() => undefined);
|
||||
}
|
||||
}, [api, gitCwd, gitModalAction, gitModalCommitMessage, refreshGitStatus]);
|
||||
}, [
|
||||
api,
|
||||
gitCwd,
|
||||
gitModalCommitMessage,
|
||||
isGitModalOpen,
|
||||
refreshGitStatus,
|
||||
selectedGitModalActionOption,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
setGitActionError(null);
|
||||
setGitModalError(null);
|
||||
setGitModalAction(null);
|
||||
setIsGitModalOpen(false);
|
||||
setGitModalSelectedAction("commit");
|
||||
setGitModalCommitMessage("");
|
||||
setGitModalProgress([]);
|
||||
setGitModalResult(null);
|
||||
}, [gitCwd]);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
if (!api || !gitCwd) {
|
||||
setGitStatus(null);
|
||||
return;
|
||||
if (!isGitModalOpen) return;
|
||||
if (selectedGitModalActionOption && !selectedGitModalActionOption.disabled) return;
|
||||
|
||||
const fallback = gitModalActionOptions.find((option) => !option.disabled);
|
||||
if (fallback) {
|
||||
setGitModalSelectedAction(fallback.action);
|
||||
}
|
||||
|
||||
const load = async () => {
|
||||
try {
|
||||
const nextStatus = await api.git.status({ cwd: gitCwd });
|
||||
if (!cancelled) {
|
||||
setGitStatus(nextStatus);
|
||||
setGitActionError(null);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!cancelled) {
|
||||
setGitStatus(null);
|
||||
setGitActionError(error instanceof Error ? error.message : "Failed to read git status.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void load();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [api, gitCwd]);
|
||||
}, [gitModalActionOptions, isGitModalOpen, selectedGitModalActionOption]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isGitMenuOpen) return;
|
||||
@@ -492,16 +566,24 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
{gitActionMenuItems.map((item) => {
|
||||
return (
|
||||
<button
|
||||
key={item.id}
|
||||
key={`${item.id}-${item.label}`}
|
||||
type="button"
|
||||
className="mb-1.5 flex w-full items-center gap-3 rounded-2xl px-3 py-2.5 text-left text-[14px] text-foreground transition-colors duration-150 hover:bg-accent disabled:cursor-not-allowed disabled:text-muted-foreground/65"
|
||||
disabled={item.disabled}
|
||||
onClick={() => {
|
||||
if (isViewPrOnlyAction(item.id, gitStatus)) {
|
||||
void runGitActionImmediately(item.id);
|
||||
if (item.kind === "open_modal") {
|
||||
openGitActionModal();
|
||||
return;
|
||||
}
|
||||
openGitActionModal(item.id);
|
||||
|
||||
if (item.kind === "open_pr") {
|
||||
openExistingPr();
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.action) {
|
||||
void runGitActionImmediately(item.action);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<GitActionIcon icon={item.icon} disabled={item.disabled} />
|
||||
@@ -523,18 +605,18 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
Branch is behind upstream. Pull/rebase before opening a PR.
|
||||
</p>
|
||||
)}
|
||||
{gitActionError && (
|
||||
{visibleGitActionError && (
|
||||
<p className="px-3 pt-2 text-[11px] text-rose-500 dark:text-rose-300">
|
||||
{gitActionError}
|
||||
{visibleGitActionError}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isGitModalOpen && gitModalAction && (
|
||||
{isGitModalOpen && (
|
||||
<div
|
||||
className="fixed inset-0 z-[80] flex items-center justify-center bg-black/35 px-4 py-6"
|
||||
className="fixed inset-0 z-80 flex items-center justify-center bg-black/35 px-4 py-6"
|
||||
onMouseDown={() => {
|
||||
closeGitActionModal();
|
||||
}}
|
||||
@@ -552,13 +634,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="rounded-2xl bg-accent p-3">
|
||||
<GitActionIcon
|
||||
icon={
|
||||
gitModalAction === "commit"
|
||||
? "commit"
|
||||
: gitModalAction === "commit_push"
|
||||
? "push"
|
||||
: "pr"
|
||||
}
|
||||
icon={selectedGitModalActionOption?.icon ?? "commit"}
|
||||
disabled={false}
|
||||
/>
|
||||
</div>
|
||||
@@ -567,7 +643,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
Git actions
|
||||
</p>
|
||||
<h3 className="text-3xl font-semibold tracking-tight text-foreground">
|
||||
{gitActionModalTitle(gitModalAction)}
|
||||
{gitActionModalTitle()}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
@@ -581,7 +657,6 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
<XIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 space-y-2 rounded-2xl border border-border/80 bg-card/40 px-4 py-3">
|
||||
<div className="flex items-center justify-between gap-4 text-sm">
|
||||
<span className="text-muted-foreground/70">Branch</span>
|
||||
@@ -592,11 +667,12 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
<div className="flex items-center justify-between gap-4 text-sm">
|
||||
<span className="text-muted-foreground/70">Changes</span>
|
||||
<span className="text-foreground">
|
||||
{gitStatus?.hasWorkingTreeChanges ? "Working tree has changes" : "No local changes"}
|
||||
{gitStatus?.hasWorkingTreeChanges
|
||||
? "Working tree has changes"
|
||||
: "No local changes"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-6">
|
||||
<label
|
||||
htmlFor="git-commit-message"
|
||||
@@ -611,62 +687,95 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
placeholder="Leave blank to autogenerate a commit message"
|
||||
value={gitModalCommitMessage}
|
||||
onChange={(event) => setGitModalCommitMessage(event.target.value)}
|
||||
disabled={isGitActionRunning || gitModalResult !== null}
|
||||
disabled={!gitModalSelectionMode || isGitActionRunning}
|
||||
/>
|
||||
<p className="mt-1.5 text-xs text-muted-foreground/65">
|
||||
Leave this empty to use AI-generated commit text.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mt-6">
|
||||
<p className="text-sm font-medium text-foreground">Next steps</p>
|
||||
<div className="mt-2 overflow-hidden rounded-2xl border border-border">
|
||||
{gitModalSteps.map((step, index) => {
|
||||
const borderClass =
|
||||
index < gitModalSteps.length - 1 ? "border-b border-border/70" : "";
|
||||
const statusTextClass =
|
||||
step.status === "failed"
|
||||
? "text-rose-500 dark:text-rose-300"
|
||||
: step.status === "completed"
|
||||
? "text-emerald-600 dark:text-emerald-300"
|
||||
: "text-muted-foreground/70";
|
||||
{gitModalSelectionMode &&
|
||||
gitModalActionOptions.map((option, index) => {
|
||||
const borderClass =
|
||||
index < gitModalActionOptions.length - 1 ? "border-b border-border/70" : "";
|
||||
const selected = option.action === gitModalSelectedAction && !option.disabled;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={step.id}
|
||||
className={`flex items-start gap-3 bg-card/45 px-4 py-3 ${borderClass}`}
|
||||
>
|
||||
<span className="mt-0.5">
|
||||
{step.status === "running" ? (
|
||||
<Loader2Icon className="h-4 w-4 animate-spin text-foreground" />
|
||||
) : step.status === "completed" ? (
|
||||
<CheckIcon className="h-4 w-4 text-emerald-600 dark:text-emerald-300" />
|
||||
) : step.status === "skipped" ? (
|
||||
<MinusIcon className="h-4 w-4 text-muted-foreground/70" />
|
||||
) : step.status === "failed" ? (
|
||||
<XIcon className="h-4 w-4 text-rose-500 dark:text-rose-300" />
|
||||
) : (
|
||||
<CircleIcon className="h-4 w-4 text-muted-foreground/60" />
|
||||
)}
|
||||
</span>
|
||||
<div className="min-w-0">
|
||||
<p className="text-sm text-foreground">{step.label}</p>
|
||||
{step.detail && (
|
||||
<p className={`mt-0.5 text-xs ${statusTextClass}`}>{step.detail}</p>
|
||||
)}
|
||||
return (
|
||||
<button
|
||||
key={option.action}
|
||||
type="button"
|
||||
className={`flex w-full items-start gap-3 px-4 py-3 text-left transition-colors duration-150 ${borderClass} ${
|
||||
selected ? "bg-accent/55" : "bg-card/45 hover:bg-accent/35"
|
||||
} disabled:cursor-not-allowed disabled:bg-card/45 disabled:text-muted-foreground/65`}
|
||||
disabled={option.disabled || isGitActionRunning}
|
||||
onClick={() => {
|
||||
setGitModalSelectedAction(option.action);
|
||||
}}
|
||||
>
|
||||
<span className="mt-0.5">
|
||||
<GitActionIcon icon={option.icon} disabled={option.disabled} />
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm text-foreground">{option.label}</p>
|
||||
{option.detail && (
|
||||
<p className="mt-0.5 text-xs text-muted-foreground/70">
|
||||
{option.detail}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{selected ? (
|
||||
<CheckIcon className="mt-0.5 h-4 w-4 shrink-0 text-foreground" />
|
||||
) : null}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{!gitModalSelectionMode &&
|
||||
gitModalSteps.map((step, index) => {
|
||||
const borderClass =
|
||||
index < gitModalSteps.length - 1 ? "border-b border-border/70" : "";
|
||||
const statusTextClass =
|
||||
step.status === "failed"
|
||||
? "text-rose-500 dark:text-rose-300"
|
||||
: step.status === "completed"
|
||||
? "text-emerald-600 dark:text-emerald-300"
|
||||
: "text-muted-foreground/70";
|
||||
|
||||
return (
|
||||
<div
|
||||
key={step.id}
|
||||
className={`flex items-start gap-3 bg-card/45 px-4 py-3 ${borderClass}`}
|
||||
>
|
||||
<span className="mt-0.5">
|
||||
{step.status === "running" ? (
|
||||
<Loader2Icon className="h-4 w-4 animate-spin text-foreground" />
|
||||
) : step.status === "completed" ? (
|
||||
<CheckIcon className="h-4 w-4 text-emerald-600 dark:text-emerald-300" />
|
||||
) : step.status === "skipped" ? (
|
||||
<MinusIcon className="h-4 w-4 text-muted-foreground/70" />
|
||||
) : step.status === "failed" ? (
|
||||
<XIcon className="h-4 w-4 text-rose-500 dark:text-rose-300" />
|
||||
) : (
|
||||
<CircleIcon className="h-4 w-4 text-muted-foreground/60" />
|
||||
)}
|
||||
</span>
|
||||
<div className="min-w-0">
|
||||
<p className="text-sm text-foreground">{step.label}</p>
|
||||
{step.detail && (
|
||||
<p className={`mt-0.5 text-xs ${statusTextClass}`}>{step.detail}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{(gitModalError ?? gitActionError) && (
|
||||
{(gitModalError ?? visibleGitActionError) && (
|
||||
<div className="mt-4 rounded-lg border border-rose-300/50 bg-rose-500/10 px-3 py-2 text-xs text-rose-600 dark:text-rose-200">
|
||||
{gitModalError ?? gitActionError}
|
||||
{gitModalError ?? visibleGitActionError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{gitModalResult?.pr.url && (
|
||||
<div className="mt-4 rounded-lg border border-border bg-card/40 px-3 py-2 text-xs text-muted-foreground/80">
|
||||
PR:{" "}
|
||||
@@ -680,7 +789,6 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-6 flex justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
@@ -697,9 +805,13 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
onClick={() => {
|
||||
void runGitAction();
|
||||
}}
|
||||
disabled={isGitActionRunning}
|
||||
disabled={isGitActionRunning || !selectedGitModalActionOption}
|
||||
>
|
||||
{isGitActionRunning ? "Running..." : runActionLabel(gitModalAction)}
|
||||
{isGitActionRunning
|
||||
? "Running..."
|
||||
: gitModalSelectionMode
|
||||
? "Continue"
|
||||
: runActionLabel(gitModalSelectedAction)}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { SVGProps } from "react";
|
||||
|
||||
export type Icon = React.FC<SVGProps<SVGSVGElement>>;
|
||||
|
||||
export const GitHubIcon: Icon = (props) => (
|
||||
<svg {...props} viewBox="0 0 1024 1024" fill="none">
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
clipRule="evenodd"
|
||||
d="M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z"
|
||||
transform="scale(64)"
|
||||
fill="#1B1F23"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
Reference in new issue
Block a user