fix(webui): sp17 one field of one workflow step saves in three clicks, one workflow editor (#1873) #1982

Merged
jason.woltje merged 5 commits from sp17-workflow-clicks into refactor 2026-11-16 18:40:01 +00:00
3 changed files with 34 additions and 1 deletions
Showing only changes of commit 6fe3625fae - Show all commits

No files matched your search

+10
View File
@@ -547,6 +547,7 @@
// dropped when the answer redraws the form. Drawn off when busy; a held form (data-live-hold) is set here.
const lockForms = off => document.querySelectorAll('#bus-view [data-wfg-page] :is([data-wfg-step-form],[data-wfg-meta-form])').forEach(f =>
f.querySelectorAll('input[name="title"],textarea,select,[data-wfg-roles-pick]').forEach(c => { c.disabled = off; }));
const toAddTitle = () => document.querySelector('#bus-view [data-wfg-page] [data-wfg-add-form] input[name="title"]')?.focus();
// Put focus back in the step form's title after a refusal (the form may be a held node).
const toTitle = () => { const f = stepFormEl()?.elements.title; if (f) { f.focus(); f.setSelectionRange(f.value.length, f.value.length); } };
@@ -618,6 +619,15 @@
async function save({ org, name, scope, s, key }) {
const d = drafts.get(key);
if (!d || d.busy) return;
// SP17 review: a new step typed in the add form is not saved over or dropped: Save says so and keeps the
// form. An add form with nothing typed in it is closed and the rest is saved.
if (d.edit?.mode === 'add') {
if (d.edit.title.trim() || d.edit.roles.length) {
d.atBar = false; d.status = `Not saved: new step ${d.edit.i + 1} is not added yet. Press Add step, or Cancel to drop it.`;
say(d.status); paint(); return toAddTitle();
}
d.edit = null;
}
// SP17: the open step's edit goes in with the save; one the save check refuses stays in its form.
const unfit = carry(d);
d.atBar = false;
@@ -124,7 +124,8 @@ test('E2E6 P2-2: a pack apply re-reads the other sections and keeps its receipt'
const before = { ...counts };
await b.evaluate(`document.querySelector('[data-pack-apply]').click();true`);
await waitFor(b, `/^Applied\\./.test(document.querySelector('[data-packs-status]')?.textContent??'')`, 'apply');
for (let i = 0; i < 300 && counts.workflows === before.workflows; i++) await new Promise(r => setTimeout(r, 30));
// Both reads are waited for: the autonomy read can answer after the workflows read on a loaded host.
for (let i = 0; i < 300 && (counts.workflows === before.workflows || counts.autonomy === before.autonomy); i++) await new Promise(r => setTimeout(r, 30));
assert.ok(counts.workflows > before.workflows, 'workflows read again after the apply');
assert.ok(counts.autonomy > before.autonomy, 'autonomy read again after the apply');
await b.evaluate(`new Promise(r=>setTimeout(()=>r(true),300))`);
@@ -975,3 +975,25 @@ test('SP17: while a Save is in flight the form takes no typing, and takes it aga
assert.deepEqual(await b.evaluate(fields), [false, false, false], 'on again after a refusal');
assert.equal(await b.evaluate(`document.querySelector('${form} input[name="title"]').value`), 'Ship again');
});
// SP17 review 2 P2-1: a new step typed in the add form is not dropped by the bar's Save: Save says it is not
// added yet and keeps the form; once added, Save sends it.
test('SP17: the bar Save with a new step typed in the add form says so and keeps it, and saves it once added', { timeout: 60000 }, async t => {
const { b, wait, st } = await setup(t, { path: '#/orgs/acme/workflows/change?project=site&step=1' });
await retitle(b, wait, 1, 'Build it');
await b.evaluate(press('[data-wfg-add]'));
await wait(`!!document.querySelector('[data-wfg-add-form]')`, 'add form');
await b.evaluate(fill('[data-wfg-add-form] input[name="title"]', 'Check'));
await b.evaluate(`document.querySelector('[data-wfg-add-form] input[name="role"][value="human"]').click();true`);
await b.evaluate(press('[data-wfg-bar] [data-wfg-save]'));
await wait(`/new step 2 is not added yet/.test(${text('[data-wfg-bar] [data-wfg-status]')})`, 'refused in words');
assert.equal(st.writes.length, 0, 'nothing written');
assert.equal(await b.evaluate(`document.querySelector('[data-wfg-add-form] input[name="title"]')?.value`), 'Check', 'the typed step is kept');
assert.equal(await b.evaluate(`document.activeElement === document.querySelector('[data-wfg-add-form] input[name="title"]')`), true, 'focus in the new step');
assert.equal(await b.evaluate(`window.MosaicWorkflows.hasDraft()`), true);
await b.evaluate(press('[data-wfg-add-step]'));
await wait(`${titles}.length === 3`, 'step added');
await b.evaluate(press('[data-wfg-save]'));
await wait(`/Saved change\\./.test(${text('[data-wfg-status]')})`, 'saved');
assert.deepEqual(st.writes.at(-1).args.workflow.steps.map(s => [s.title, s.roles]), [['Build it', ['coder']], ['Check', ['human']], ['Ship', ['human']]]);
});