From 24551c9eead03fb1c671d6c77959651343b3a455 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Mon, 16 Nov 2026 11:52:57 -0600 Subject: [PATCH] fix(webui): sp17 review, no edit is dropped without a word: an open edit of one step goes into the pending workflow as typed when another step is drawn or typed in (a card step link, the address or Back opened it), so Save sends both and Reset step on the second puts back only that one, and a step the save check refuses is named by Save, which checks every step; while a Save or delete is in flight the step and workflow forms' fields are off, drawn off when busy and set off on a held form, and on again after the answer or a refusal, so nothing typed then is lost when the form is drawn again; tests open step 2 from the card and from the address with step 1 changed and see both in the write (red before: step 1 went back to Build), and check the fields are off during a held write and a redraw and on after it and after a refusal (red before: the fields stayed on) (#1873, lane sp17-workflow-clicks) --- packages/webui/src/public/workflows.js | 40 +++++++++---- .../webui/tests/workflows-browser.test.mjs | 59 +++++++++++++++++++ 2 files changed, 86 insertions(+), 13 deletions(-) diff --git a/packages/webui/src/public/workflows.js b/packages/webui/src/public/workflows.js index d10003a30..5ecfb3f3a 100644 --- a/packages/webui/src/public/workflows.js +++ b/packages/webui/src/public/workflows.js @@ -309,16 +309,16 @@ } // The role picker: human, the organization's roles, the role templates, and first any role the step names // that resolves to none of those (checked and marked, so leaving it in is a choice the save check names). - function rolePick(s, chosen, prefix) { + function rolePick(s, chosen, prefix, off = false) { const defs = [...(s.data.roles.definitions || [])].sort(), tpl = [...(s.data.roles.templates || [])].filter(r => !defs.includes(r)).sort(); const odd = chosen.filter(r => !s.known.has(r)); const box = (r, mark = '') => ``; const group = (title, list, mark) => (list.length ? `

${title}

${list.map(r => box(r, mark)).join('')}` : ''); - return `
Roles, one to eight + return `
Roles, one to eight ${group('Named in this step', odd, ` ${MISSING}`)}${box('human', ' a person')} ${group('This organization\'s roles', defs.filter(r => r !== 'human'), '')}${group('Role templates', tpl.filter(r => r !== 'human'), '')}
`; } - const stateSelect = (value, key) => ``; + const stateSelect = (value, key, off = false) => ``; // A new step's form: Add step puts it in the graph on this page, unsaved. function addForm(org, s, scope, name, d) { const e = d.edit, n = e.i + 1; @@ -344,10 +344,10 @@ // into it, and holds its node across a repaint only once it differs from the step (data-live-hold). function editForm(org, s, scope, name, steps, sel, d) { const i = sel - 1, st = steps[i], e = d?.edit?.mode === 'edit' && d.edit.i === i ? d.edit : null; - const v = e ?? { title: st.title, state: st.state, roles: rolesOf(st), why: '' }, dirty = editDirty(e); + const v = e ?? { title: st.title, state: st.state, roles: rolesOf(st), why: '' }, dirty = editDirty(e), off = !!d?.busy; return `
- - ${stateSelect(v.state, 'wfg-f-state')}${rolePick(s, v.roles, 'wfg-f')} + + ${stateSelect(v.state, 'wfg-f-state', off)}${rolePick(s, v.roles, 'wfg-f', off)}

${esc(v.why ?? '')}

${saveButton(d)}

${statusLine(formStatus(org, scope, name, d))}
`; } @@ -355,8 +355,8 @@ // organization-page form did. Each change goes into the pending workflow at once. function metaForm(org, s, scope, name, d, w) { return `
- - + +

${saveButton(d)}

${statusLine(formStatus(org, scope, name, d))}
`; } // `inPanel`: the panel shows a form with its own Save, so the bar does not repeat it. @@ -410,6 +410,7 @@ if (!fresh && !d) return { title: esc(name), sub: '', body: `${note ? `

${esc(note)}

` : ''}

No workflow named ${esc(name)} in ${scope ? `project ${esc(scope)}` : 'the organization'}.

` }; const w = d ? d.flow : norm(fresh), steps = w.steps; const raw = Number(q.get('step')), sel = Number.isInteger(raw) && raw >= 1 && raw <= steps.length ? raw : 0; + if (d && !d.busy) park(d, sel - 1); const sub = `${esc(scopeLabel(scope))}, ${esc(name)}, ${count(steps.length)}.${w.description ? ` ${esc(w.description)}` : ''}`; const body = steps.length ? `${bar(org, s, scope, name, d, !!s.data.writable && d?.edit?.mode !== 'add')}
${graph(org, s, scope, name, d ? preview(d) : steps, sel)}
${detail(org, s, scope, name, steps, sel, d, w)}` @@ -533,6 +534,19 @@ d.flow.steps[e.i] = st; d.edit = null; return ''; } + // SP17 review: an open edit of a step other than the one shown (a card step link, the address or Back opened + // another step) goes into the pending workflow as typed, never dropped. A step the save check refuses is then + // named by Save, which checks every step. + function park(d, i) { + const e = d?.edit; + if (!e || e.mode !== 'edit' || e.i === i) return; + if (editDirty(e) && d.flow.steps[e.i]) d.flow.steps[e.i] = { title: e.title.trim(), state: e.state, roles: [...e.roles] }; + d.edit = null; + } + // SP17 review: while a Save or delete is in flight the form's fields take no typing, so nothing typed then is + // 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; })); // 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); } }; @@ -611,7 +625,7 @@ const refused = refusal(s, { isNew: d.isNew, scope, name, steps: d.flow.steps }); if (refused) { d.status = refused; say(refused); return paint('wfg-save'); } if (!changed(d)) return paint(); - d.busy = true; d.status = 'Saving…'; paint(); + d.busy = true; d.status = 'Saving…'; paint(); lockForms(true); try { const workflow = shape(d.flow); await writing(org, async () => written(org, s, scope, name, workflow, await saveFlow(org, s, { scope, name, revision: d.revision, workflow }))); @@ -625,13 +639,13 @@ d.busy = false; d.status = kept[error.code] ?? `Not saved: ${error.message} Your change is kept.`; say(d.status); - paint('wfg-save'); + paint('wfg-save'); lockForms(false); } } async function remove({ org, name, scope, s, key }) { const d = drafts.get(key); if (!d || d.busy) return; - d.busy = true; paint(); + d.busy = true; paint(); lockForms(true); try { // The revision of the workflow the page shows (settle moves it on only while this workflow is unchanged): // a change made to it since is refused, not deleted over. @@ -645,7 +659,7 @@ // Recheck B: Discard shows only with a pending change; without one the next read draws the current version. d.status = error.code === 'revision-conflict' ? `Not deleted: the organization file changed this workflow since the page read it. ${changed(d) ? 'Discard to load the current version.' : 'The page shows the current version at its next read.'}` : `Not deleted: ${error.message}`; say(d.status); - paint('wfg-delete'); + paint('wfg-delete'); lockForms(false); } } // SP17: after a change in a panel form, the bar and the form's own buttons follow it without redrawing the @@ -681,7 +695,7 @@ return follow(at, d, form); } const i = Number(form.dataset.wfgStepForm); - if (!(d.edit?.mode === 'edit' && d.edit.i === i)) { if (!d.flow.steps[i]) return; openForm(d, 'edit', i, d.flow.steps[i]); } + if (!(d.edit?.mode === 'edit' && d.edit.i === i)) { if (!d.flow.steps[i]) return; park(d, i); openForm(d, 'edit', i, d.flow.steps[i]); } readForm(form, d.edit); follow(at, d, form); }); diff --git a/packages/webui/tests/workflows-browser.test.mjs b/packages/webui/tests/workflows-browser.test.mjs index 7ada9cf0f..7ad61b925 100644 --- a/packages/webui/tests/workflows-browser.test.mjs +++ b/packages/webui/tests/workflows-browser.test.mjs @@ -916,3 +916,62 @@ test('SP17: Restart bus on the organization page with a step edit open keeps it, assert.equal(st.writes[0].args.revision, REV_A); assert.equal(st.docs.acme.projects.site.workflows.change.steps[1].title, 'Ship it'); }); + +// SP17 review P2-1: an open edit of one step is not dropped when another step is opened from the card or the +// address and typed in. Both edits go in the one Save. +test('SP17: an edit of step 1 is kept when step 2 is opened from the card or the address and changed, and Save sends both', { timeout: 90000 }, 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'); + // From the card: the card says the change is kept; its step link opens step 2. + await b.evaluate(`location.hash = '#/orgs/acme/organization';true`); + await wait(`!!document.querySelector('[data-wfg-card] [data-wfg-held-link]')`, 'card kept note'); + await b.evaluate(`document.querySelector('[data-wfg-card] a[data-wfg-card-step][href="#/orgs/acme/workflows/change?project=site&step=2"]').click();true`); + await wait(`document.querySelector('${form}')?.dataset.wfgStepForm === '1'`, 'step 2 form'); + assert.deepEqual(await b.evaluate(titles), ['Build it', 'Ship']); + await retitle(b, wait, 2, 'Ship it'); + assert.deepEqual(await b.evaluate(titles), ['Build it', 'Ship it'], 'typing in step 2 keeps step 1 as changed'); + 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), ['Build it', 'Ship it']); + // From the address: step 1 changed, then the address names step 2. + await b.evaluate(`location.hash = '#/orgs/acme/workflows/change?project=site&step=1';true`); + await retitle(b, wait, 1, 'Build again'); + await b.evaluate(`location.hash = '#/orgs/acme/workflows/change?project=site&step=2';true`); + await wait(`document.querySelector('${form}')?.dataset.wfgStepForm === '1'`, 'step 2 form from the address'); + await retitle(b, wait, 2, 'Ship again'); + assert.deepEqual(await b.evaluate(titles), ['Build again', 'Ship again']); + // Reset step on step 2 puts back step 2 only. + await b.evaluate(press('[data-wfg-cancel]')); + await wait(`${titles}[1] === 'Ship it'`, 'step 2 reset'); + assert.deepEqual(await b.evaluate(titles), ['Build again', 'Ship it'], 'Reset step on step 2 leaves step 1 changed'); + await b.evaluate(press('[data-wfg-save]')); + await wait(`/Saved change\\./.test(${text('[data-wfg-status]')})`, 'second save'); + assert.deepEqual(st.writes.at(-1).args.workflow.steps.map(s => s.title), ['Build again', 'Ship it']); +}); + +// SP17 review P2-2: nothing typed while a Save is in flight is dropped: the form's fields take no typing until +// the write answers. +test('SP17: while a Save is in flight the form takes no typing, and takes it again after', { timeout: 60000 }, async t => { + const { b, wait, st } = await setup(t, { path: '#/orgs/acme/workflows/change?project=site&step=2' }); + await retitle(b, wait, 2, 'Ship it'); + const fields = `[...document.querySelectorAll('${form} input[name="title"], ${form} select, ${form} [data-wfg-roles-pick]')].map(e=>e.disabled)`; + const openWrite = st.hold('write'); + await b.evaluate(press('[data-wfg-save]')); + await wait(`document.querySelector('[data-wfg-save]')?.disabled === true`, 'save in flight'); + assert.deepEqual(await b.evaluate(fields), [true, true, true], 'title, state and roles are off while saving'); + // A poll redraw during the write keeps them off. + await b.evaluate(`document.dispatchEvent(new CustomEvent('mosaic-workspace-render'));true`); + await b.evaluate(`new Promise(r=>setTimeout(()=>r(true),300))`); + assert.deepEqual(await b.evaluate(fields), [true, true, true], 'still off after a redraw'); + openWrite(); + await wait(`/Saved change\\./.test(${text('[data-wfg-status]')})`, 'saved'); + assert.deepEqual(await b.evaluate(fields), [false, false, false], 'on again once saved'); + assert.equal(st.writes.at(-1).args.workflow.steps[1].title, 'Ship it'); + // A refused Save gives the fields back too. + await retitle(b, wait, 2, 'Ship again'); + st.down.acme = 'restarting'; + await b.evaluate(press('[data-wfg-save]')); + await wait(`/the organization bus is not running/.test(document.querySelector('[data-wfg-status]')?.textContent ?? '')`, 'refused'); + 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'); +});