diff --git a/packages/webui/src/public/tasks-board.js b/packages/webui/src/public/tasks-board.js index c6dd6f302..966a2fc5d 100644 --- a/packages/webui/src/public/tasks-board.js +++ b/packages/webui/src/public/tasks-board.js @@ -178,10 +178,14 @@ const onServer = new URLSearchParams(readQuery()).size > 1, n = rows.length; const line = onServer ? `

Showing ${n} ${n === 1 ? 'task that matches' : 'tasks that match'} the filters.

` : n !== all ? `

Showing ${n} of ${all} tasks.

` : ''; + // An empty result is only exhaustive when every organization's tasks were read. + const unread = snap.orgs.filter(o => !tasksRead(o)); + const none = what => (unread.length ? `${what} in the organizations that answered. Tasks from ${unread.map(o => o.label).join(', ')} could not be read.` : `${what}.`); const body = !snap.orgs.length ? '

No organizations yet.

' - : !all ? `

${snap.orgs.some(tasksRead) ? 'No tasks yet.' : 'No organization answered with its tasks, so no tasks could be read.'}

` - : !rows.length ? '

No tasks match these filters.

' - : layoutNow() === 'list' ? list(rows) : kanban(rows); + : !snap.orgs.some(tasksRead) ? '

No organization answered with its tasks, so no tasks could be read.

' + : !all && !onServer ? `

${esc(none('No tasks yet'))}

` + : !rows.length ? `

${esc(none('No tasks match these filters'))}

` + : layoutNow() === 'list' ? list(rows) : kanban(rows); return `
${line}${body}
`; } @@ -357,6 +361,16 @@ if (who.join('\n') !== [...t.assignees].sort().join('\n')) body.assignees = who; return body; } + // The competing write may have moved the task out of the board's filters, so the conflict read + // asks for its one organization unfiltered. The task was just changed, so the cap keeps it. + async function current(t) { + try { + const r = await fetch(`/api/workspace?${new URLSearchParams({ sections: 'tasks', org: t.org })}`, { cache: 'no-store', redirect: 'manual' }); + if (r.type === 'opaqueredirect' || !r.ok) return null; + const b = await r.json(); + return (Array.isArray(b?.tasks) && b.tasks.find(x => x.org === t.org && x.ref === t.ref)) || null; + } catch { return null; } + } async function submit(form) { const kind = form.dataset.tbForm, btns = form.querySelectorAll('button'); if (!form.reportValidity()) return; @@ -380,7 +394,7 @@ // The task changed under the form: the form shows the current task and keeps the refusal. if (r.error === 'task-conflict' && t) { try { await reload(); } catch {} - const now = find(key(t)); + const now = find(key(t)) || await current(t); if (now) { const msg = r.message; openDialog(editForm(now), dialogEl().dataset.return, now); const f2 = dialogEl().querySelector('form'); if (f2) formStatus(f2, msg); } paint(); } else if (r.unknown) { try { await reload(); } catch {} paint(); } diff --git a/packages/webui/tests/tasks-board-browser.test.mjs b/packages/webui/tests/tasks-board-browser.test.mjs index 1f55aab56..c8404f969 100644 --- a/packages/webui/tests/tasks-board-browser.test.mjs +++ b/packages/webui/tests/tasks-board-browser.test.mjs @@ -285,3 +285,29 @@ test('a filter change asks the server for the matching tasks', async t => { await wait('document.querySelectorAll("[data-tasks-board] [data-tb-task]").length === 1'); assert.deepEqual(await cards(b), ['forge|task:42']); }); + +test('a conflict on a task another writer moved out of the board\'s filter reopens on the current task', async t => { + const { b, wait, orgs } = await open(t); + await b.evaluate('(() => { const s = document.querySelector("[data-tb-filter=state]"); s.value = "in-progress"; s.dispatchEvent(new Event("change", { bubbles: true })); })()'); + await wait('document.querySelectorAll("[data-tasks-board] [data-tb-task]").length === 1'); + await b.evaluate('document.querySelector("[data-tb-open=\'forge|task:42\']").click()'); + await wait('document.querySelector("#tb-dialog[open] form[data-tb-form=edit]")'); + // Another writer finishes the task, so the board's In progress read no longer holds it. + const t42 = orgs.store.find(s => s.n === 42); + Object.assign(t42, { state: 'done', rev: t42.rev + 1 }); + await b.evaluate('(() => { const f = document.querySelector("#tb-dialog form"); f.title.value = "Invoice export, CSV"; f.requestSubmit(); })()'); + await wait('document.querySelector("#tb-dialog form")?.state.value === "done"'); + assert.match(await b.evaluate('document.querySelector("#tb-dialog [data-tb-form-status]").textContent'), /changed after the board read it/); + assert.equal(await b.evaluate('document.querySelector("#tb-dialog").open'), true); + await b.evaluate('(() => { const f = document.querySelector("#tb-dialog form"); f.title.value = "Invoice export, CSV"; f.requestSubmit(); })()'); + await wait('/#42 saved in Forge/.test(document.querySelector("[data-tb-notice]").textContent)'); + assert.deepEqual(orgs.writes.at(-1), ['forge', 'tasks.edit', { task_ref: 'task:42', expect: D(3), title: 'Invoice export, CSV' }]); +}); + +test('an empty result names the organizations whose tasks were not read', async t => { + const { b, wait } = await open(t, { tasksFail: ['ddigital'] }); + await b.evaluate('(() => { const s = document.querySelector("[data-tb-filter=state]"); s.value = "blocked"; s.dispatchEvent(new Event("change", { bubbles: true })); })()'); + await wait('/No tasks match/.test(document.querySelector("[data-tb-results]").textContent)'); + assert.equal(await b.evaluate('document.querySelector("[data-tb-results] .ws-panel").textContent'), + 'No tasks match these filters in the organizations that answered. Tasks from Distinctly Digital, Home could not be read.'); +});