dashboard: /approve, /deny, /answer-question, /cancel-question, /request-spawn return 200; matching forms opt out of refetch
This commit is contained in:
parent
d8d393da6d
commit
f559441a06
2 changed files with 28 additions and 12 deletions
|
|
@ -22,10 +22,14 @@
|
|||
}
|
||||
return e;
|
||||
};
|
||||
const form = (action, btnClass, btnLabel, confirmMsg, extra = {}) => {
|
||||
const form = (action, btnClass, btnLabel, confirmMsg, extra = {}, opts = {}) => {
|
||||
const f = el('form', {
|
||||
method: 'POST', action, class: 'inline', 'data-async': '',
|
||||
...(confirmMsg ? { 'data-confirm': confirmMsg } : {}),
|
||||
// Endpoints whose mutation fires a DashboardEvent (and whose
|
||||
// derived store applies it live) opt out of the post-submit
|
||||
// /api/state refetch. See the async-form handler.
|
||||
...(opts.noRefresh ? { 'data-no-refresh': '' } : {}),
|
||||
});
|
||||
for (const [name, value] of Object.entries(extra)) {
|
||||
f.append(el('input', { type: 'hidden', name, value }));
|
||||
|
|
@ -195,7 +199,15 @@
|
|||
if (btn) { btn.disabled = false; btn.innerHTML = original; }
|
||||
// Clear text inputs whose value was just submitted.
|
||||
f.querySelectorAll('input[type="text"], input:not([type]), textarea').forEach((i) => { i.value = ''; });
|
||||
refreshState();
|
||||
// Forms whose endpoint already emits a DashboardEvent that
|
||||
// updates the derived store can opt out of the post-submit
|
||||
// /api/state refetch (the event delivers the new row faster
|
||||
// than the snapshot poll anyway). Container-lifecycle forms
|
||||
// still rely on the refresh since `ContainerView` isn't yet
|
||||
// event-derivable.
|
||||
if (!f.hasAttribute('data-no-refresh')) {
|
||||
refreshState();
|
||||
}
|
||||
} catch (err) {
|
||||
alert('action failed: ' + err);
|
||||
if (btn) { btn.disabled = false; btn.innerHTML = original; }
|
||||
|
|
@ -587,7 +599,7 @@
|
|||
li.append(head, el('div', { class: 'q-body' }, q.question));
|
||||
const f = el('form', {
|
||||
method: 'POST', action: '/answer-question/' + q.id,
|
||||
class: 'qform', 'data-async': '',
|
||||
class: 'qform', 'data-async': '', 'data-no-refresh': '',
|
||||
});
|
||||
const hasOptions = q.options && q.options.length;
|
||||
const isMulti = !!q.multi && hasOptions;
|
||||
|
|
@ -638,7 +650,7 @@
|
|||
// merge-on-submit handler attached to the main form.
|
||||
const cancelForm = el('form', {
|
||||
method: 'POST', action: '/cancel-question/' + q.id,
|
||||
class: 'qform-cancel', 'data-async': '',
|
||||
class: 'qform-cancel', 'data-async': '', 'data-no-refresh': '',
|
||||
'data-confirm': 'cancel this question? manager will see '
|
||||
+ '"[cancelled]" as the answer.',
|
||||
});
|
||||
|
|
@ -768,7 +780,7 @@
|
|||
// the containers list (the agent doesn't exist yet).
|
||||
const spawn = el('form', {
|
||||
method: 'POST', action: '/request-spawn',
|
||||
class: 'spawnform', 'data-async': '',
|
||||
class: 'spawnform', 'data-async': '', 'data-no-refresh': '',
|
||||
});
|
||||
spawn.append(
|
||||
el('input', {
|
||||
|
|
@ -851,13 +863,13 @@
|
|||
// HelperEvent::ApprovalResolved { note }.
|
||||
const denyForm = el('form', {
|
||||
method: 'POST', action: '/deny/' + a.id,
|
||||
class: 'inline', 'data-async': '',
|
||||
class: 'inline', 'data-async': '', 'data-no-refresh': '',
|
||||
'data-prompt': 'reason for denying (optional, sent to manager):',
|
||||
});
|
||||
denyForm.append(el('button', { type: 'submit', class: 'btn btn-deny' }, 'DENY'));
|
||||
row.append(
|
||||
' ',
|
||||
form('/approve/' + a.id, 'btn-approve', '◆ APPR0VE'),
|
||||
form('/approve/' + a.id, 'btn-approve', '◆ APPR0VE', null, {}, { noRefresh: true }),
|
||||
' ',
|
||||
denyForm,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue