Skip to content

Commit 9019337

Browse files
committed
Select the task card in the assign dialog, and report a failed board
The "Hand a task to a Workflow" dialog mounts before loadTasks() answers, so its taskId froze to '' and Assign posted nothing while looking accepted; and a rejected Tasks call was turned into an empty list, which the dialog rendered as "no tasks to assign". Keep a load status beside the rows, preselect the first card when the board arrives, keep Assign disabled until a card is selected, and show a failed load as an error with a Retry instead of the empty-board hint. Fixes #1457 Fixes #1458
1 parent c1b9fd2 commit 9019337

4 files changed

Lines changed: 206 additions & 17 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The "Hand a task to a Workflow" dialog now selects the first card of the Tasks board as soon as the board arrives, so `Assign` posts the task instead of closing on a silent no-op, and an empty board leaves it disabled. When the Tasks board cannot be loaded the dialog shows the error with a `Retry` control instead of claiming there are no tasks to assign, and `Assign` stays disabled while the load is in flight or failed. ([#1457](https://github.com/ThinkFlowLab/FlyBot/issues/1457), [#1458](https://github.com/ThinkFlowLab/FlyBot/issues/1458))

‎docs/subsystems/workflow.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Everything in `plugins/workflow/`: the graph rules, the run store, the matcher,
3333
| `plugins/workflow/src/match.js` | Which open card matches a Workflow or a local Bot. |
3434
| `plugins/workflow/src/template.js` | Factory delivery/weekly graphs plus `EARLY_END_GUIDANCE` for Claim/Verify/Triage early-end markers; 发布交付流水线 (a parallel branch) and the weekly report, each node with the inputs and outputs that edge carries. |
3535
| `plugins/workflow/src/narrate.js` | Progress lines for a step. A live run quotes the Bot reply when present; otherwise delivery-template nodes may use canned copy. A join line is only for a rank of more than one node. |
36-
| `plugins/workflow/client.js` | Sidebar section (with mini-flowcharts), workflow stage (view/control: one card per live run with its own title, node line, segment progress, status chip, and Pause / Resume / Stop; click a card or its Flow button to focus that run in the drawer flowchart; optional aggregate chip when several run or the queue is non-empty — no message composer), assign dialog (scrollable with sticky footer), flowchart drawer (collapsed by default, per-node inspector, fitted to the 400px panel so the graph needs no inner horizontal scroll), and Settings → Workflow graphs (canvas-first with inspector panel). The product UI starts only live runs (assign, ingest). The stage shows the queue and refreshes state while runs are active; a running node uses a breathing border animation. Visual flowcharts replace text chains across all surfaces. Sidebar rows (including factory ids such as `delivery`) support Delete with confirm. The stage and dialogs portal onto `document.body`; a missing container stays in the section tree. A stage control that fails — a graph save, Reset, Pause, Resume or Stop that throws, rejects, answers `{ok:false}` or does not answer within 10 s — ends on the section's `.wf-err` alert instead of being swallowed, and a success clears the alert. |
36+
| `plugins/workflow/client.js` | Sidebar section (with mini-flowcharts), workflow stage (view/control: one card per live run with its own title, node line, segment progress, status chip, and Pause / Resume / Stop; click a card or its Flow button to focus that run in the drawer flowchart; optional aggregate chip when several run or the queue is non-empty — no message composer), assign dialog (scrollable with sticky footer; it selects the first card once the board loads, keeps `Assign` disabled until a card is selected, and shows a failed Tasks load as an error with a `Retry` instead of the empty-board hint, #1457, #1458), flowchart drawer (collapsed by default, per-node inspector, fitted to the 400px panel so the graph needs no inner horizontal scroll), and Settings → Workflow graphs (canvas-first with inspector panel). The product UI starts only live runs (assign, ingest). The stage shows the queue and refreshes state while runs are active; a running node uses a breathing border animation. Visual flowcharts replace text chains across all surfaces. Sidebar rows (including factory ids such as `delivery`) support Delete with confirm. The stage and dialogs portal onto `document.body`; a missing container stays in the section tree. A stage control that fails — a graph save, Reset, Pause, Resume or Stop that throws, rejects, answers `{ok:false}` or does not answer within 10 s — ends on the section's `.wf-err` alert instead of being swallowed, and a success clears the alert. |
3737

3838
## Entry points
3939

@@ -59,7 +59,7 @@ Everything in `plugins/workflow/`: the graph rules, the run store, the matcher,
5959

6060
## Tests
6161

62-
`plugins/workflow/test/`: graph advance and join, graph edit, assign and persistence, the FIFO queue and concurrency cap, Bot-reply advance, a dispatch that fails without being marked handed, a bounded hand-off retry and a step deadline that fails the run and clears its timer (#1530), disposing releases the Bots before the record drops their ids and a released runner name is reusable again, assign-to-bot versus assign-to-workflow, inputs and outputs along edges, a loop that breaks and an if/else branch, failure recovery (onFail edges with max attempts, exhaustion behavior, and compatibility with failOnce and loop edges), templates, `define` / `runNamed`, the matcher, ephemeral spawn and cleanup, a stopped run with its settled node map (#1424), the reply middleware, the client canvas, the settings page (including a condition and a loop), rename and delete (including factory-id rows such as `delivery`), and a sidebar click that leaves the Workflows section in place. Run `npm test` in `plugins/workflow`. The host seam that applies `ownerBotId` is `core/test/task-route.test.js`. The host omission of run Bots, and the grant of `stepTools` plus the hidden-approval answer, is `core/test/flybot.test.js`. Which connectors a run Bot may call is `core/test/connector-access.test.js`, and the chain from a node's `tools` through `spawn` to that guard — the built-in delivery nodes included — is `core/test/workflow-node-connectors.test.js`.
62+
`plugins/workflow/test/`: graph advance and join, graph edit, assign and persistence, the FIFO queue and concurrency cap, Bot-reply advance, a dispatch that fails without being marked handed, a bounded hand-off retry and a step deadline that fails the run and clears its timer (#1530), disposing releases the Bots before the record drops their ids and a released runner name is reusable again, assign-to-bot versus assign-to-workflow, inputs and outputs along edges, a loop that breaks and an if/else branch, failure recovery (onFail edges with max attempts, exhaustion behavior, and compatibility with failOnce and loop edges), templates, `define` / `runNamed`, the matcher, ephemeral spawn and cleanup, a stopped run with its settled node map (#1424), the reply middleware, the client canvas, the settings page (including a condition and a loop), rename and delete (including factory-id rows such as `delivery`), the assign dialog's preselected card and its failed and empty board states (#1457, #1458), and a sidebar click that leaves the Workflows section in place. Run `npm test` in `plugins/workflow`. The host seam that applies `ownerBotId` is `core/test/task-route.test.js`. The host omission of run Bots, and the grant of `stepTools` plus the hidden-approval answer, is `core/test/flybot.test.js`. Which connectors a run Bot may call is `core/test/connector-access.test.js`, and the chain from a node's `tools` through `spawn` to that guard — the built-in delivery nodes included — is `core/test/workflow-node-connectors.test.js`.
6363

6464
## Connector ceiling (#1544)
6565

‎plugins/workflow/client.js‎

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ window.__ModuleLoader__.load({
106106
'Rename workflow': '重命名 Workflow',
107107
'Are you sure you want to delete "{name}"? This cannot be undone.': '确定删除「{name}」?此操作无法撤销。',
108108
'No open tasks on the Tasks board.': 'Tasks 看板上没有可分配的任务。',
109+
'Loading the Tasks board…': '正在读取 Tasks 看板…',
110+
'Could not load the Tasks board.': '无法读取 Tasks 看板。',
111+
Retry: '重试',
109112
'Could not rename this workflow': '无法重命名该 Workflow',
110113
'Could not delete this workflow': '无法删除该 Workflow',
111114
'Could not save this workflow': '无法保存该 Workflow',
@@ -812,9 +815,17 @@ window.__ModuleLoader__.load({
812815
h('button', { type: 'button', className: 'wf-btn wf-danger', onClick: onConfirm }, tr('Delete')))))
813816
}
814817

815-
function AssignModal({ workflows, tasks, roster, workflowId, onClose, onConfirm }) {
818+
function AssignModal({ workflows, tasks, tasksStatus, tasksError, roster, workflowId, onClose, onConfirm, onRetry }) {
816819
const [taskId, setTaskId] = useState(tasks[0]?.id ?? '')
817820
const [target, setTarget] = useState(workflowId || workflows[0]?.id || '')
821+
// #1457: the dialog opens before loadTasks() answers, so the first client render can have no
822+
// rows; select the first card once they arrive, or when the selected card is gone.
823+
useEffect(() => {
824+
if (tasks.length === 0) return
825+
if (taskId && tasks.some(task => task.id === taskId)) return
826+
setTaskId(tasks[0].id)
827+
}, [tasks, taskId])
828+
const canAssign = tasksStatus === 'ready' && tasks.some(task => task.id === taskId)
818829
const seen = new Set()
819830
const bots = (roster?.bots ?? []).filter(bot => {
820831
if (!bot || bot.remote === true || !bot.id || !bot.name) return false
@@ -830,14 +841,20 @@ window.__ModuleLoader__.load({
830841
h('p', { className: 'wf-hint' }, tr('A task can go to a Workflow, not only to one Bot. The Workflow then runs each Bot in order, or side by side.'))),
831842
h('div', { className: 'wf-modal-body' },
832843
h('div', { className: 'wf-step-h' }, h('b', null, '1'), tr('Pick a task card')),
833-
tasks.length === 0
834-
? h('div', { className: 'wf-muted wf-cards-empty' }, tr('No open tasks on the Tasks board.'))
835-
: h('div', { className: 'wf-cards' }, tasks.map(task => h('button', {
836-
key: task.id, type: 'button', className: `wf-kcard ${taskId === task.id ? 'sel' : ''}`, onClick: () => setTaskId(task.id),
837-
},
838-
h('div', { className: 'wf-id' }, `${shortId(task.id)} · ${priorityOf(task)}`),
839-
h('div', { className: 'wf-tt' }, task.title),
840-
h('div', { className: 'wf-kcol' }, `● ${tr(COLUMN_KEY[columnOf(task)] ?? 'Not started')}`)))),
844+
tasksStatus === 'failed'
845+
? h('div', { className: 'wf-assign-fail' },
846+
h('div', { className: 'wf-err', role: 'alert' }, tasksError || tr('Could not load the Tasks board.')),
847+
h('button', { type: 'button', className: 'wf-btn', onClick: () => onRetry?.() }, tr('Retry')))
848+
: tasksStatus !== 'ready'
849+
? h('div', { className: 'wf-muted wf-cards-empty' }, tr('Loading the Tasks board…'))
850+
: tasks.length === 0
851+
? h('div', { className: 'wf-muted wf-cards-empty' }, tr('No open tasks on the Tasks board.'))
852+
: h('div', { className: 'wf-cards' }, tasks.map(task => h('button', {
853+
key: task.id, type: 'button', className: `wf-kcard ${taskId === task.id ? 'sel' : ''}`, onClick: () => setTaskId(task.id),
854+
},
855+
h('div', { className: 'wf-id' }, `${shortId(task.id)} · ${priorityOf(task)}`),
856+
h('div', { className: 'wf-tt' }, task.title),
857+
h('div', { className: 'wf-kcol' }, `● ${tr(COLUMN_KEY[columnOf(task)] ?? 'Not started')}`)))),
841858
h('div', { className: 'wf-step-h' }, h('b', null, '2'), tr('Pick who runs it')),
842859
h('div', { className: 'wf-targets' },
843860
workflows.map(item => h('button', {
@@ -858,7 +875,7 @@ window.__ModuleLoader__.load({
858875
h('span', { className: 'wf-rad' }))))),
859876
h('div', { className: 'wf-modal-footer' },
860877
h('button', { type: 'button', className: 'wf-btn', onClick: onClose }, tr('Cancel')),
861-
h('button', { type: 'button', className: 'wf-btn wf-dark', onClick: () => onConfirm({ taskId, target }) }, tr('Assign')))))
878+
h('button', { type: 'button', className: 'wf-btn wf-dark', disabled: !canAssign, onClick: () => { if (canAssign) onConfirm({ taskId, target }) } }, tr('Assign')))))
862879
}
863880

864881
function CreateModal({ roster, templates, onClose, onCreate, onTemplate }) {
@@ -1247,6 +1264,8 @@ window.__ModuleLoader__.load({
12471264
const [assignOpen, setAssignOpen] = useState(false)
12481265
const [creating, setCreating] = useState(false)
12491266
const [tasks, setTasks] = useState([])
1267+
const [tasksStatus, setTasksStatus] = useState('idle')
1268+
const [tasksError, setTasksError] = useState('')
12501269
const [tip, setTip] = useState(null)
12511270
const [error, setError] = useState('')
12521271
const [editing, setEditing] = useState(false)
@@ -1295,7 +1314,9 @@ window.__ModuleLoader__.load({
12951314
const root = globalThis.__flybot__
12961315
if (!root) return undefined
12971316
const prev = root.openWorkflowAssign
1298-
root.openWorkflowAssign = () => { setAssignOpen(true); setOpenId(id => id) }
1317+
// #1457: this path opened the dialog without ever loading the board, so it could only
1318+
// ever show the frozen empty state.
1319+
root.openWorkflowAssign = () => { setAssignOpen(true); setOpenId(id => id); void loadTasks() }
12991320
return () => { root.openWorkflowAssign = prev }
13001321
}, [])
13011322

@@ -1349,8 +1370,15 @@ window.__ModuleLoader__.load({
13491370
}, [open?.id])
13501371

13511372
const loadTasks = async () => {
1373+
setTasksStatus('loading')
1374+
setTasksError('')
13521375
const host = globalThis.__flybot__?.host
1353-
if (typeof host !== 'function') { setTasks([]); return }
1376+
if (typeof host !== 'function') {
1377+
setTasks([])
1378+
setTasksError(tr('Could not load the Tasks board.'))
1379+
setTasksStatus('failed')
1380+
return
1381+
}
13541382
try {
13551383
const rows = await host('tasks', {})
13561384
const real = Array.isArray(rows)
@@ -1359,9 +1387,14 @@ window.__ModuleLoader__.load({
13591387
}))
13601388
: []
13611389
setTasks(real)
1390+
setTasksStatus('ready')
13621391
} catch (loadError) {
1363-
void loadError
1392+
// #1458: an empty list here used to be rendered as "no tasks to assign", which told the
1393+
// owner the board was empty instead of that the load had failed.
1394+
const detail = String(loadError?.message ?? '').trim()
13641395
setTasks([])
1396+
setTasksError(`${tr('Could not load the Tasks board.')}${detail ? ` (${detail})` : ''}`)
1397+
setTasksStatus('failed')
13651398
}
13661399
}
13671400

@@ -1505,8 +1538,8 @@ window.__ModuleLoader__.load({
15051538
},
15061539
})) : null,
15071540
assignOpen ? portal(h(AssignModal, {
1508-
workflows, tasks, roster, workflowId: openId || workflows[0]?.id,
1509-
onClose: () => setAssignOpen(false), onConfirm: confirmAssign,
1541+
workflows, tasks, tasksStatus, tasksError, roster, workflowId: openId || workflows[0]?.id,
1542+
onClose: () => setAssignOpen(false), onConfirm: confirmAssign, onRetry: loadTasks,
15101543
})) : null,
15111544
creating ? portal(h(CreateModal, {
15121545
roster, templates: pack?.templates, onClose: () => setCreating(false), onCreate: create,
@@ -1707,6 +1740,7 @@ window.__ModuleLoader__.load({
17071740
.wf-canvas-fit{position:relative;width:0;margin:0 auto;transform-origin:50% 0}
17081741
.wf-canvas-view .wf-wires path{stroke:var(--bt-ink-2,rgba(20,20,20,.55));stroke-width:2.5}
17091742
.wf-cards-empty{padding:8px 4px 12px}
1743+
.wf-assign-fail{display:flex;flex-direction:column;align-items:flex-start;gap:8px;padding:4px 0 8px}
17101744
.wf-context-menu{position:fixed;z-index:95;min-width:140px;background:var(--bt-card,#fff);border:1px solid var(--bt-line,rgba(20,20,20,.08));border-radius:10px;padding:4px;box-shadow:0 8px 24px rgba(0,0,0,.12);display:flex;flex-direction:column;gap:2px}
17111745
.wf-context-menu button{border:0;background:transparent;color:inherit;font:inherit;font-size:12.5px;text-align:left;padding:8px 10px;border-radius:8px;cursor:pointer}
17121746
.wf-context-menu button:hover{background:var(--bt-hover,rgba(119,119,119,.09))}

0 commit comments

Comments
 (0)