mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Make the git board's next-step Commit button commit the ticked files
AI Assisted
This commit is contained in:
1 parent
cc02631ab5
commit
9583b68a2e
3 files changed
+65
-18
No files matched your search
@@ -470,7 +470,35 @@ test("git board view: each step's click goes out as the board offers it", () =>
|
||||
const [branch, onMain] = stepButtons(main);
|
||||
click(branch);
|
||||
click(onMain);
|
||||
assert.deepEqual(main.on.calls, [["openPanel", "create", { commit: true }], ["openPanel", "commit"]]);
|
||||
const mainFiles = [...commitTicks(STATES["nb-main-dirty"].git.changes)];
|
||||
assert.deepEqual(main.on.calls, [["openPanel", "create", { commit: true }], ["send", "commit", { files: mainFiles, ignore: [] }]]);
|
||||
|
||||
// The commit table is always on show below the step, so the step's Commit
|
||||
// sends what the table has ticked rather than "opening" a panel already open.
|
||||
const dirty = draw("cp-dirty", { tab: "changes" });
|
||||
const ticked = [...commitTicks(STATES["cp-dirty"].git.changes)];
|
||||
const top = stepButtons(dirty).find((c) => c.textContent.startsWith("Commit "));
|
||||
assert.equal(top.textContent, `Commit ${ticked.length} file${ticked.length === 1 ? "" : "s"}`);
|
||||
click(top);
|
||||
assert.deepEqual(dirty.on.calls, [["send", "commit", { files: ticked, ignore: [] }]]);
|
||||
|
||||
const unticked = draw("cp-dirty", { tab: "changes" });
|
||||
unticked.board.ticks.clear();
|
||||
const redrawn = drawGitBoard({
|
||||
git: STATES["cp-dirty"].git, board: unticked.board, now: NOW, mode: "idle", step: unticked.step,
|
||||
badges: tabBadges(STATES["cp-dirty"].git, { now: NOW, stepTab: unticked.step.tab }), notice: null, activity: null, hasCard: false, h: fakeH(), on: fakeOn(),
|
||||
});
|
||||
const none = controls(walk(redrawn.node).find((n) => n.classes.has("git-step"))).find((c) => c.textContent.startsWith("Commit "));
|
||||
assert.ok(none.disabled, "nothing ticked: the step's Commit is grayed, like the table's");
|
||||
|
||||
const one = draw("cp-dirty", { tab: "changes" });
|
||||
one.board.ticks = new Set([ticked[0]]);
|
||||
const again = drawGitBoard({
|
||||
git: STATES["cp-dirty"].git, board: one.board, now: NOW, mode: "idle", step: one.step,
|
||||
badges: tabBadges(STATES["cp-dirty"].git, { now: NOW, stepTab: one.step.tab }), notice: null, activity: null, hasCard: false, h: fakeH(), on: fakeOn(),
|
||||
});
|
||||
const card = walk(again.node).find((n) => n.classes.has("git-step"));
|
||||
assert.equal(walk(card).find((n) => n.classes.has("git-step-title")).textContent, "Commit 1 file", "the card's title follows the ticks too");
|
||||
|
||||
const away = draw("pc-conflict", { tab: "changes" });
|
||||
click(walk(away.node).find((n) => n.classes.has("git-hint")));
|
||||
@@ -576,7 +604,7 @@ test("git board view: a landed result splits the step strip into Just landed and
|
||||
assert.ok(!walk(r.node).some((n) => n.classes.has("git-result")), "no thin result line beside the zones");
|
||||
const commit = controls(rest).find((c) => c.textContent === "Commit other changes");
|
||||
click(commit);
|
||||
assert.deepEqual(r.on.calls[0], ["openPanel", "commit"], "the leftover offer runs the same op the primary would");
|
||||
assert.deepEqual(r.on.calls[0], ["send", "commit", { files: [...commitTicks(STATES["cp-dirty"].git.changes)], ignore: [] }], "the leftover offer runs the same op the primary would");
|
||||
|
||||
const plain = landed("cp-dirty", { id: "git-result", kind: "notice", title: "Committed 1eef797", body: "no op marker" });
|
||||
assert.ok(walk(plain.node).some((n) => n.classes.has("git-result")), "a notice with no op keeps the thin line");
|
||||
|
||||
@@ -137,15 +137,14 @@ const settles = (control, enabled) => until(async () => (await control.isEnabled
|
||||
const settlesUsable = (page, want) => until(async () => (await usable(page)) === want, 8000);
|
||||
const titled = (page, text) => page.waitForFunction((x) => document.getElementById("title").textContent.includes(x), text);
|
||||
|
||||
test("the commit dialog sends the ticked files as one __git action, with its reply sentence", async (t) => {
|
||||
test("the next step's Commit sends the files ticked in the table as one __git action, with its reply sentence", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "git", project: changesProject({ branch: "feature/x" }), payload: READY });
|
||||
const { page } = s;
|
||||
await page.getByRole("tablist").waitFor();
|
||||
await stepButton(page, "Commit 2 files").click();
|
||||
const panel = page.locator(".git-panel");
|
||||
await panel.getByRole("button", { name: "Close" }).waitFor();
|
||||
await stepButton(page, "Commit 2 files").waitFor();
|
||||
await tickBox(page, "notes.md").uncheck();
|
||||
await panel.getByRole("button", { name: "Commit 1 file" }).click();
|
||||
// The table is already on show below, so the step's button commits rather than opening it.
|
||||
await stepButton(page, "Commit 1 file").click();
|
||||
const got = s.wait(10);
|
||||
assert.equal(got.code, 0, "the agent collected the click");
|
||||
assert.deepEqual(got.actions, [{ i: "__git", type: "git", op: "commit", files: ["src/app.js"], ignore: [] }]);
|
||||
@@ -261,7 +260,7 @@ test("a commit with no branch to land on carries the ticked files into the new b
|
||||
await tickBox(page, "notes.md").uncheck();
|
||||
// The step is on the Branches tab, and its Commit button finds no branch to commit on.
|
||||
await tabButton(page, "Branches").click();
|
||||
await stepButton(page, "Commit 2 files").click();
|
||||
await stepButton(page, "Commit 1 file").click();
|
||||
const panel = page.locator(".git-panel");
|
||||
await panel.getByRole("heading", { name: "New branch for this commit" }).waitFor();
|
||||
const create = panel.getByRole("button", { name: "Create", exact: true });
|
||||
|
||||
@@ -238,8 +238,13 @@ function tabPanel(ctx, id) {
|
||||
function runStep(ctx, s) {
|
||||
const { git, on } = ctx;
|
||||
switch (s.op) {
|
||||
case "commit":
|
||||
return on.openPanel("commit");
|
||||
// The commit table is always on show below, so the step commits what it
|
||||
// has ticked, as its own button does; on a detached HEAD a branch comes first.
|
||||
case "commit": {
|
||||
const picks = tablePicks(ctx);
|
||||
if (git.hasCommits !== false && !(git.head || {}).branch) return on.openPanel("create", { commit: true, ...picks });
|
||||
return on.send("commit", picks);
|
||||
}
|
||||
case "create-commit":
|
||||
return on.openPanel("create", { commit: true });
|
||||
case "create":
|
||||
@@ -265,7 +270,25 @@ function runStep(ctx, s) {
|
||||
|
||||
function stepButton(ctx, s, cls) {
|
||||
if (s.op === "pr") return prLink(ctx, s.url, cls);
|
||||
return control(ctx, "button", cls, s.label, { onClick: () => runStep(ctx, s) });
|
||||
const disabled = s.op === "commit" && !tablePicks(ctx).files.length;
|
||||
return control(ctx, "button", cls, stepLabel(ctx, s), { disabled, onClick: () => runStep(ctx, s) });
|
||||
}
|
||||
|
||||
// A step's name. A "Commit N files" count follows the table's ticks, so the
|
||||
// card and its button say what the click will send.
|
||||
function stepLabel(ctx, s) {
|
||||
if (!s || s.op !== "commit" || !/^Commit \d+ files?$/.test(s.label)) return s ? s.label : "";
|
||||
return `Commit ${plural(tablePicks(ctx).files.length, "file", "files")}`;
|
||||
}
|
||||
|
||||
// The commit table's ticked files and .gitignore picks, checked against the snapshot.
|
||||
function tablePicks(ctx) {
|
||||
const ch = ctx.git.changes || {};
|
||||
const board = ctx.board;
|
||||
const ticks = board.ticks || (board.ticks = commitTicks(ch));
|
||||
const ignored = board.ignore || (board.ignore = new Set());
|
||||
const known = new Set([...list(ch.files), ...list(ch.untrackedDirs)].map((f) => f.path));
|
||||
return { files: [...ticks].filter((path) => known.has(path)), ignore: [...ignored].filter((path) => known.has(path)) };
|
||||
}
|
||||
|
||||
function stepStrip(ctx, id) {
|
||||
@@ -274,7 +297,7 @@ function stepStrip(ctx, id) {
|
||||
if (id !== step.tab) {
|
||||
if (!p) return null;
|
||||
const where = GIT_TABS.find((t) => t.id === step.tab);
|
||||
return control(ctx, "button", "git-hint", `Next step is on ${where ? where.label : step.tab}: ${p.label} →`, {
|
||||
return control(ctx, "button", "git-hint", `Next step is on ${where ? where.label : step.tab}: ${stepLabel(ctx, p)} →`, {
|
||||
role: "nav",
|
||||
onClick: () => ctx.on.pickTab(step.tab),
|
||||
});
|
||||
@@ -305,8 +328,7 @@ function stepStrip(ctx, id) {
|
||||
duo.appendChild(landed);
|
||||
const left = h.el("div", "git-left");
|
||||
left.appendChild(h.el("div", "git-step-kicker", theirs ? "Still on the tree" : p ? "Still to do" : "All caught up"));
|
||||
if (theirs) left.appendChild(h.el("h3", "git-step-title", theirs.label));
|
||||
else left.appendChild(h.el("h3", "git-step-title", p ? p.label : step.line));
|
||||
left.appendChild(h.el("h3", "git-step-title", p ? stepLabel(ctx, p) : step.line));
|
||||
if (p && p.why) left.appendChild(h.el("p", "git-step-why", p.why));
|
||||
if (step.stale) left.appendChild(staleLine(ctx, step.stale));
|
||||
if (step.held) {
|
||||
@@ -328,7 +350,7 @@ function stepStrip(ctx, id) {
|
||||
}
|
||||
const box = h.el("div", "git-step" + (git.inProgress ? " is-warn" : "") + (p ? "" : " is-calm"));
|
||||
box.appendChild(h.el("div", "git-step-kicker", p ? "Next step" : "Nothing to do"));
|
||||
box.appendChild(h.el("h3", "git-step-title", p ? p.label : step.line));
|
||||
box.appendChild(h.el("h3", "git-step-title", p ? stepLabel(ctx, p) : step.line));
|
||||
if (p && p.why) box.appendChild(h.el("p", "git-step-why", p.why));
|
||||
if (step.stale) box.appendChild(staleLine(ctx, step.stale));
|
||||
if (step.held) {
|
||||
@@ -477,9 +499,7 @@ function commitPanel(ctx, frozen) {
|
||||
table.appendChild(tbody);
|
||||
p.appendChild(table);
|
||||
|
||||
const known = new Set([...list(ch.files), ...list(ch.untrackedDirs)].map((f) => f.path));
|
||||
const files = [...ticks].filter((path) => known.has(path));
|
||||
const ignore = [...ignored].filter((path) => known.has(path));
|
||||
const { files, ignore } = tablePicks(ctx);
|
||||
const send = () => on.send("commit", { files, ignore });
|
||||
const actions = h.el("div", "git-panel-actions");
|
||||
const head = git.head || {};
|
||||
|
||||
Reference in new issue
Block a user