Compare commits
2 changed files with 65 additions and 32 deletions
|
|
@ -2520,4 +2520,6 @@ body.dashboard-shell.has-selection { padding-bottom: 4.5em; }
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
.move-picker .btn-move {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -933,49 +933,80 @@ window.marked = marked;
|
||||||
disabledTitle: why('PURG3', managerNames.map((n) => `\`${n}\` is the manager`)),
|
disabledTitle: why('PURG3', managerNames.map((n) => `\`${n}\` is the manager`)),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Move agent(s) in the topology tree — selecting an option in the
|
// Move agent(s) in the topology tree — see
|
||||||
// M0V3 dropdown immediately confirms + executes the move. "(no parent)"
|
// docs/web-ui.md::Selection bar for the two affordances:
|
||||||
// promotes to root (empty new_parent on the backend). Cycle-safe:
|
|
||||||
// dropdown filters out self and descendants on the client side; the
|
|
||||||
// backend rechecks via `topology::set_parent`.
|
|
||||||
//
|
//
|
||||||
// Backend: POST /api/topology/set-parent (dashboard.rs),
|
// ⇡ M0V3 → ROOT promote selected agent(s) to top-level (parent=null)
|
||||||
// form-encoded `child=<name>&new_parent=<target-or-empty>`. Re-emits
|
// ⇢ M0V3 → [sel] reparent the single selected agent under a picked
|
||||||
// container snapshots on success so the tree repaints without a
|
// parent (cycle-safe — the dropdown filters out self
|
||||||
// separate refresh.
|
// and own descendants on the client side; the
|
||||||
|
// backend rechecks via `topology::set_parent`).
|
||||||
|
//
|
||||||
|
// Backend lives at POST /api/topology/set-parent (dashboard.rs),
|
||||||
|
// form-encoded `child=<name>&new_parent=<target-or-empty>`. The
|
||||||
|
// backend re-emits container snapshots on success, so the tree
|
||||||
|
// repaints without a separate refresh.
|
||||||
addMoveActions(actions, selected, containers);
|
addMoveActions(actions, selected, containers);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the M0V3 picker in the selection bar. Selecting any real option
|
// Render the M0V3 affordances inside the selection bar — separate
|
||||||
// (including "(no parent)") immediately fires a confirm + POST — no
|
// helper because the picker variant needs a select + button pair,
|
||||||
// separate button. Backend `topology::set_parent` refuses invalid moves
|
// not the single-button shape addBulkButton ships. Backend
|
||||||
// and the refusal surfaces in the alert roll-up.
|
// `topology::set_parent` refuses moves it can't satisfy (manager
|
||||||
|
// included) and the refusal surfaces in the bulk-action error
|
||||||
|
// roll-up.
|
||||||
function addMoveActions(parent, selected, containers) {
|
function addMoveActions(parent, selected, containers) {
|
||||||
|
// M0V3 → ROOT: parent=null for every selected agent. Only meaningful
|
||||||
|
// when at least one selected agent currently has a non-null parent;
|
||||||
|
// otherwise it's a no-op for everything.
|
||||||
|
const someNotAtRoot = selected.some((c) => c.parent);
|
||||||
|
addBulkButton(parent, 'btn-move', '⇡ M0V3 → ROOT', someNotAtRoot, selected, {
|
||||||
|
action: '/api/topology/set-parent',
|
||||||
|
perAgentBodyFor: (name) => ({ child: name, new_parent: '' }),
|
||||||
|
confirm: (names) => `promote ${names.length} agent${names.length === 1 ? '' : 's'} (${names.join(', ')}) to top-level (parent → root)?`,
|
||||||
|
disabledTitle: !someNotAtRoot
|
||||||
|
? '⇡ M0V3 → ROOT not available — all selected agents are already at root'
|
||||||
|
: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
// M0V3 → <pick>: inline `<select>` of candidate parents + submit
|
||||||
|
// button. Available for any selection size. Picker omits each
|
||||||
|
// selected agent itself plus the union of every selected agent's
|
||||||
|
// descendants (cycle-safe; backend `topology::set_parent`
|
||||||
|
// re-checks). Empty candidate list ⇒ disable the picker.
|
||||||
const candidates = validReparentCandidates(selected, containers);
|
const candidates = validReparentCandidates(selected, containers);
|
||||||
const wrap = el('span', { class: 'move-picker' });
|
const wrap = el('span', { class: 'move-picker' });
|
||||||
const selectTitle = selected.length === 1
|
const selectTitle = selected.length === 1
|
||||||
? `change ${selected[0].name}'s parent`
|
? `change ${selected[0].name}'s parent`
|
||||||
: `change ${selected.length} agents' parent`;
|
: `change ${selected.length} agents' parent`;
|
||||||
const sel = el('select', { class: 'move-picker-select', title: selectTitle });
|
const sel = el('select', { class: 'move-picker-select', title: selectTitle });
|
||||||
sel.append(el('option', { value: '' }, '⇢ M0V3 →'));
|
sel.append(el('option', { value: '' }, '— pick parent —'));
|
||||||
// "(no parent)" → empty new_parent on the backend (promotes to root).
|
|
||||||
sel.append(el('option', { value: '__root__' }, '(no parent)'));
|
|
||||||
for (const name of candidates) {
|
for (const name of candidates) {
|
||||||
sel.append(el('option', { value: name }, name));
|
sel.append(el('option', { value: name }, name));
|
||||||
}
|
}
|
||||||
sel.addEventListener('change', async () => {
|
if (!candidates.length) {
|
||||||
if (sel.selectedIndex === 0) return;
|
sel.disabled = true;
|
||||||
const newParent = sel.value === '__root__' ? '' : sel.value;
|
sel.title = selected.length === 1
|
||||||
const newParentLabel = sel.value === '__root__' ? '(no parent)' : sel.value;
|
? `no valid parents for ${selected[0].name} (every other agent is its descendant)`
|
||||||
|
: `no valid parents — every other agent is a descendant of one of the selected`;
|
||||||
|
}
|
||||||
|
const btn = el('button', { type: 'button', class: 'btn btn-move' }, '⇢ M0V3');
|
||||||
|
btn.disabled = true;
|
||||||
|
sel.addEventListener('change', () => { btn.disabled = !sel.value; });
|
||||||
|
btn.addEventListener('click', async () => {
|
||||||
|
const newParent = sel.value;
|
||||||
|
if (!newParent) return;
|
||||||
const names = selected.map((c) => c.name);
|
const names = selected.map((c) => c.name);
|
||||||
const promptMsg = names.length === 1
|
const promptMsg = names.length === 1
|
||||||
? `move ${names[0]} → ${newParentLabel}?`
|
? `move ${names[0]} under ${newParent}?`
|
||||||
: `move ${names.length} agents (${names.join(', ')}) → ${newParentLabel}?`;
|
: `move ${names.length} agents (${names.join(', ')}) under ${newParent}?`;
|
||||||
if (!confirm(promptMsg)) {
|
if (!confirm(promptMsg)) return;
|
||||||
sel.selectedIndex = 0;
|
btn.disabled = true;
|
||||||
return;
|
const original = btn.innerHTML;
|
||||||
}
|
btn.innerHTML = '<span class="spinner">◐</span> ⇢ M0V3';
|
||||||
sel.disabled = true;
|
// Sequential POSTs — same shape as the bulk-button loop. Each
|
||||||
|
// call is small + backend serialises topology writes via the
|
||||||
|
// file-lock anyway.
|
||||||
const failures = [];
|
const failures = [];
|
||||||
for (const name of names) {
|
for (const name of names) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -996,13 +1027,13 @@ window.marked = marked;
|
||||||
failures.push(`${name}: ${err}`);
|
failures.push(`${name}: ${err}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sel.disabled = false;
|
btn.innerHTML = original;
|
||||||
sel.selectedIndex = 0;
|
btn.disabled = !sel.value;
|
||||||
if (failures.length) {
|
if (failures.length) {
|
||||||
alert(`M0V3 completed with ${failures.length} failure${failures.length === 1 ? '' : 's'}:\n\n` + failures.join('\n'));
|
alert(`⇢ M0V3 completed with ${failures.length} failure${failures.length === 1 ? '' : 's'}:\n\n` + failures.join('\n'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
wrap.append(sel);
|
wrap.append(sel, btn);
|
||||||
parent.append(wrap);
|
parent.append(wrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue