fix(webui): SP6 review round, the writer's workflow name rule, no silent replace, preview redraw (#1873)
The workflow editor checks the writer's PLAN_NAME (lowercase letters, digits and dashes, starting with a letter), so a name the bus would refuse no longer reaches it with step guidance. A new workflow under a name its scope already holds is refused on the page instead of replacing that workflow. A pack preview the page cannot draw says so rather than leaving Preview disabled. The browser test launches Chromium with --disable-extensions.
This commit was merged in pull request #1956.
This commit is contained in:
1 parent
504fcd9220
commit
991eb8c332
3 files changed
+22
-5
No files matched your search
@@ -125,7 +125,8 @@
|
|||||||
s.status = `Applied. Added ${added}. Proposed hires are recorded for the chief to raise as decisions.`;
|
s.status = `Applied. Added ${added}. Proposed hires are recorded for the chief to raise as decisions.`;
|
||||||
}
|
}
|
||||||
} catch (error) { s.status = error.message; }
|
} catch (error) { s.status = error.message; }
|
||||||
redraw(org);
|
// A preview the page cannot draw says so, instead of leaving the button disabled with nothing shown.
|
||||||
|
try { redraw(org); } catch { s.preview = null; s.status = 'The preview could not be shown.'; redraw(org); }
|
||||||
});
|
});
|
||||||
window.MosaicPacks = { load, section };
|
window.MosaicPacks = { load, section };
|
||||||
})();
|
})();
|
||||||
@@ -10,7 +10,9 @@
|
|||||||
const base = org => `/api/orgs/${encodeURIComponent(org)}`;
|
const base = org => `/api/orgs/${encodeURIComponent(org)}`;
|
||||||
const STATES = [['todo', 'To do'], ['in-progress', 'In progress'], ['in-review', 'Review'], ['blocked', 'Blocked'], ['done', 'Done']];
|
const STATES = [['todo', 'To do'], ['in-progress', 'In progress'], ['in-review', 'Review'], ['blocked', 'Blocked'], ['done', 'Done']];
|
||||||
const STATE_LABEL = Object.fromEntries(STATES);
|
const STATE_LABEL = Object.fromEntries(STATES);
|
||||||
const NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
// The writer's workflow name rule (organization.mjs PLAN_NAME); a name it would refuse is refused here first.
|
||||||
|
const NAME = /^[a-z][a-z0-9-]{0,63}$/;
|
||||||
|
const NAME_RULE = 'A workflow name is 1 to 64 lowercase letters, digits or dashes, starting with a letter.';
|
||||||
const MISSING = 'names no current role';
|
const MISSING = 'names no current role';
|
||||||
const states = new Map();
|
const states = new Map();
|
||||||
const guidance = {
|
const guidance = {
|
||||||
@@ -77,7 +79,7 @@
|
|||||||
const e = s.editing;
|
const e = s.editing;
|
||||||
if (!e) return '';
|
if (!e) return '';
|
||||||
const scopeField = e.isNew
|
const scopeField = e.isNew
|
||||||
? `<label>Where<select name="scope">${scopes(s).map(([v, l]) => `<option value="${esc(v)}"${e.scope === v ? ' selected' : ''}>${esc(l)}</option>`).join('')}</select></label><label>Name<input name="name" maxlength="64" value="${esc(e.name)}" autocomplete="off" placeholder="lowercase letters, digits, dot, dash"></label>`
|
? `<label>Where<select name="scope">${scopes(s).map(([v, l]) => `<option value="${esc(v)}"${e.scope === v ? ' selected' : ''}>${esc(l)}</option>`).join('')}</select></label><label>Name<input name="name" maxlength="64" value="${esc(e.name)}" autocomplete="off" placeholder="lowercase letters, digits, dashes"></label>`
|
||||||
: `<p>${e.scope ? `Project ${esc(e.scope)}` : 'Organization'}, <code>${esc(e.name)}</code></p>`;
|
: `<p>${e.scope ? `Project ${esc(e.scope)}` : 'Organization'}, <code>${esc(e.name)}</code></p>`;
|
||||||
return `<form class="wf-editor" data-wf-editor><h4>${e.isNew ? 'New workflow' : 'Edit workflow'}</h4>${scopeField}
|
return `<form class="wf-editor" data-wf-editor><h4>${e.isNew ? 'New workflow' : 'Edit workflow'}</h4>${scopeField}
|
||||||
<label>Title<input name="title" maxlength="120" value="${esc(e.draft.title)}" autocomplete="off"></label>
|
<label>Title<input name="title" maxlength="120" value="${esc(e.draft.title)}" autocomplete="off"></label>
|
||||||
@@ -163,7 +165,9 @@
|
|||||||
if (!s?.editing) return;
|
if (!s?.editing) return;
|
||||||
capture(root, s);
|
capture(root, s);
|
||||||
const e = s.editing;
|
const e = s.editing;
|
||||||
if (!NAME.test(e.name)) { s.status = 'A workflow name is 1 to 64 lowercase letters, digits, dots, dashes or underscores, starting with a letter or digit.'; redraw(org); return; }
|
if (!NAME.test(e.name)) { s.status = NAME_RULE; redraw(org); return; }
|
||||||
|
// A save is a set: a new workflow under a name the scope already holds would replace it without a word.
|
||||||
|
if (e.isNew && Object.hasOwn(flowsIn(s, e.scope) ?? {}, e.name)) { s.status = `A workflow named ${e.name} already exists here. Edit it instead.`; redraw(org); return; }
|
||||||
const workflow = {
|
const workflow = {
|
||||||
...(e.draft.title.trim() ? { title: e.draft.title.trim() } : {}),
|
...(e.draft.title.trim() ? { title: e.draft.title.trim() } : {}),
|
||||||
...(e.draft.description.trim() ? { description: e.draft.description.trim() } : {}),
|
...(e.draft.description.trim() ? { description: e.draft.description.trim() } : {}),
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ async function fixture(t, { send = true } = {}) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
t.after(() => close(server));
|
t.after(() => close(server));
|
||||||
const b = await browser({ machine: false });
|
const b = await browser({ machine: false, args: ['--disable-extensions'] });
|
||||||
t.after(() => b.close());
|
t.after(() => b.close());
|
||||||
await b.viewport(1440, 900);
|
await b.viewport(1440, 900);
|
||||||
await b.navigate(`http://127.0.0.1:${server.address().port}/#/orgs/acme/organization`);
|
await b.navigate(`http://127.0.0.1:${server.address().port}/#/orgs/acme/organization`);
|
||||||
@@ -174,6 +174,18 @@ test('SP6 workflows: list by scope, a step naming no current role, titles as tex
|
|||||||
await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.scope.value='site';f.elements.name.value='Bad Name';f.querySelector('[data-wf-edit-step="0"] [name=title]').value='Plan';f.querySelector('[data-wf-edit-step="0"] [name=roles]').value='human';f.requestSubmit()}true`);
|
await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.scope.value='site';f.elements.name.value='Bad Name';f.querySelector('[data-wf-edit-step="0"] [name=title]').value='Plan';f.querySelector('[data-wf-edit-step="0"] [name=roles]').value='human';f.requestSubmit()}true`);
|
||||||
await waitFor(b, `/lowercase/.test(document.querySelector('[data-workflows-status]').textContent)`, 'name refusal');
|
await waitFor(b, `/lowercase/.test(document.querySelector('[data-workflows-status]').textContent)`, 'name refusal');
|
||||||
assert.equal(sets(), before);
|
assert.equal(sets(), before);
|
||||||
|
// The writer's name rule (PLAN_NAME): no underscore, dot or leading digit. Each is refused here, not at the bus.
|
||||||
|
for (const bad of ['release_1', 'v2.ship', '2nd-review']) {
|
||||||
|
await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.name.value=${JSON.stringify(bad)};f.requestSubmit()}true`);
|
||||||
|
assert.equal(await b.evaluate(`document.querySelector('[data-workflows-status]').textContent`), 'A workflow name is 1 to 64 lowercase letters, digits or dashes, starting with a letter.', bad);
|
||||||
|
assert.equal(sets(), before, `${bad} sends nothing`);
|
||||||
|
}
|
||||||
|
assert.equal(await b.evaluate(`document.querySelector('[data-wf-editor] input[name=name]').placeholder`), 'lowercase letters, digits, dashes');
|
||||||
|
// A new workflow under a name the scope already holds would replace it: refused, nothing sent.
|
||||||
|
await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.name.value='ship';f.requestSubmit()}true`);
|
||||||
|
assert.equal(await b.evaluate(`document.querySelector('[data-workflows-status]').textContent`), 'A workflow named ship already exists here. Edit it instead.');
|
||||||
|
assert.equal(sets(), before, 'an existing name sends nothing');
|
||||||
|
assert.equal(await b.evaluate(`document.querySelector('[data-wf-editor] select[name=scope]').value`), 'site', 'the editor keeps the chosen scope');
|
||||||
await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.name.value='plan';f.requestSubmit()}true`);
|
await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.name.value='plan';f.requestSubmit()}true`);
|
||||||
await waitFor(b, `document.querySelector('[data-workflows-status]').textContent==='Saved plan.'`, 'new save');
|
await waitFor(b, `document.querySelector('[data-workflows-status]').textContent==='Saved plan.'`, 'new save');
|
||||||
assert.deepEqual(verbs.filter(([v]) => v === 'workflow.set.console').at(-1)[1], { revision: REV('b'), name: 'plan', workflow: { steps: [{ title: 'Plan', state: 'todo', roles: ['human'] }] }, project: 'site' });
|
assert.deepEqual(verbs.filter(([v]) => v === 'workflow.set.console').at(-1)[1], { revision: REV('b'), name: 'plan', workflow: { steps: [{ title: 'Plan', state: 'todo', roles: ['human'] }] }, project: 'site' });
|
||||||
|
|||||||
Reference in new issue
Block a user