Factory: merge and close buttons on the issue card, enforced order
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0e54714436
commit
391db43949
10 files changed
+121
-16
No files matched your search
@@ -78,6 +78,8 @@ interface Issue {
|
||||
branch: string;
|
||||
rounds: number;
|
||||
/** Newest phase chat that still exists. */
|
||||
/** The pull request is merged (merging comes after a positive acceptance, closing after the merge). */
|
||||
merged?: boolean;
|
||||
chat_session?: string;
|
||||
chat_phase?: Phase;
|
||||
created_at: number;
|
||||
@@ -188,6 +190,20 @@ export function Factory({ onMenu, overlayId }: { onMenu: () => void; overlayId?:
|
||||
);
|
||||
}
|
||||
|
||||
/** A button inside an issue card (the card itself is a button, so this is a span with the button role). */
|
||||
function CardAction({ children, onClick, title, primary, disabled }: { children: React.ReactNode; onClick: () => void; title?: string; primary?: boolean; disabled?: boolean }) {
|
||||
const run = (e: React.SyntheticEvent) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
if (!disabled) onClick();
|
||||
};
|
||||
return (
|
||||
<span role="button" tabIndex={disabled ? -1 : 0} aria-disabled={disabled} className={`factory-card-action ${primary ? "primary" : ""} ${disabled ? "disabled" : ""}`} title={title} onClick={run} onKeyDown={(e) => (e.key === "Enter" || e.key === " ") && run(e)}>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** The factory's main switch, coloured by state: green = running, yellow = stopping, red = stopped. */
|
||||
function PowerSwitch({ power, onToggle }: { power: Power; onToggle: (on: boolean) => void }) {
|
||||
const t = useT();
|
||||
@@ -402,20 +418,24 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const mergePr = async () => {
|
||||
if (!selected || !pr) return;
|
||||
if (!(await confirmDialog({ message: t("factory.mergeConfirm", { n: pr.number, method: t(`factory.merge.${prMethod}` as any) }) }))) return;
|
||||
const prNo = (i: Issue) => Number(i.pr_url.replace(/\/$/, "").split("/").pop()) || 0;
|
||||
/** Merge the pull request of an issue; only offered once the acceptance has passed. */
|
||||
const mergeIssue = async (i: Issue, n = prNo(i)) => {
|
||||
if (!n || i.state !== "done") return;
|
||||
if (!(await confirmDialog({ message: t("factory.mergeConfirm", { n, method: t(`factory.merge.${prMethod}` as any) }) }))) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await post("/factory/issues/pr/merge", { repo: selected.repo, number: selected.number, pr: pr.number, method: prMethod });
|
||||
await post("/factory/issues/pr/merge", { repo: i.repo, number: i.number, pr: n, method: prMethod });
|
||||
toast(t("factory.merged"));
|
||||
await loadPr();
|
||||
await reload();
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const mergePr = () => (selected && pr ? mergeIssue(selected, pr.number) : Promise.resolve());
|
||||
const removeIssue = async () => {
|
||||
if (!selected) return;
|
||||
if (!(await confirmDialog({ message: t("factory.removeConfirm", { n: selected.number }), confirmLabel: t("factory.remove"), danger: true }))) return;
|
||||
@@ -430,15 +450,16 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const closeIssue = async () => {
|
||||
if (!selected) return;
|
||||
const comment = await promptDialog({ title: t("factory.closeTitle"), message: t("factory.closeMsg", { n: selected.number }), defaultValue: t("factory.closeDefault"), confirmLabel: t("factory.close") });
|
||||
/** Close an issue; only offered once its pull request is merged. */
|
||||
const closeIssueOf = async (i: Issue) => {
|
||||
if (i.state !== "done" || !i.merged) return;
|
||||
const comment = await promptDialog({ title: t("factory.closeTitle"), message: t("factory.closeMsg", { n: i.number }), defaultValue: t("factory.closeDefault"), confirmLabel: t("factory.close") });
|
||||
if (comment === null) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await post("/factory/issues/close", { repo: selected.repo, number: selected.number, comment });
|
||||
await post("/factory/issues/close", { repo: i.repo, number: i.number, comment });
|
||||
toast(t("factory.closed"), "success");
|
||||
setSel("");
|
||||
if (selected && selected.number === i.number && selected.repo === i.repo) setSel("");
|
||||
await reload();
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
@@ -446,6 +467,7 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const closeIssue = () => (selected ? closeIssueOf(selected) : Promise.resolve());
|
||||
const phaseRunning = !!selected && ["review", "building", "testing"].includes(selected.state);
|
||||
/** Master switch: a soft stop – no new agent starts, running ones finish their phase. */
|
||||
const setPower = async (on: boolean) => {
|
||||
@@ -623,6 +645,19 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
</span>
|
||||
)}
|
||||
{tokens > 0 && <span className="hint">{fmtCompact(tokens)} {t("factory.tokens")}</span>}
|
||||
{i.state === "done" && (i.merged || prNo(i) > 0) && (
|
||||
<span className="factory-card-actions">
|
||||
{!i.merged ? (
|
||||
<CardAction primary disabled={busy} title={t("factory.mergeHint")} onClick={() => void mergeIssue(i)}>
|
||||
<Icon name="fork" /> {t("factory.mergeBtn")}
|
||||
</CardAction>
|
||||
) : (
|
||||
<CardAction disabled={busy} title={t("factory.closeHint")} onClick={() => void closeIssueOf(i)}>
|
||||
<Icon name="check" /> {t("factory.close")}
|
||||
</CardAction>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
@@ -658,7 +693,7 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
<Icon name="trash" /> {t("factory.remove")}
|
||||
</button>
|
||||
)}
|
||||
{selected && selected.state === "done" && (
|
||||
{selected && selected.state === "done" && selected.merged && (
|
||||
<button className="small" onClick={closeIssue} disabled={busy}>
|
||||
<Icon name="check" /> {t("factory.close")}
|
||||
</button>
|
||||
@@ -691,7 +726,7 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
</span>
|
||||
)}
|
||||
<span className="spacer" />
|
||||
{pr.state === "open" && (
|
||||
{pr.state === "open" && selected?.state === "done" && (
|
||||
<>
|
||||
<select value={prMethod} onChange={(e) => setPrMethod(e.target.value)} disabled={busy}>
|
||||
{["merge", "squash", "rebase"].map((m) => (
|
||||
|
||||
Reference in new issue
Block a user