feat(flomni): add "Edit command" for pending command jobs in the tomo queue
CI for csaxs_bec / test (push) Successful in 3m9s
CI for csaxs_bec / test (push) Successful in 3m9s
The "Load into editor" button in the queue dialog is now dual-purpose: for a single selected tomo job it behaves as before, but for a single selected *pending* command job it relabels to "Edit command" and opens CommandJobBuilderDialog pre-populated with that job's steps/label/ idempotent flag. On OK the job is replaced in place (same queue position, same id/added_at); on Cancel the queued job is untouched. Previously a command job could only be "edited" by deleting it and rebuilding it from scratch via "Add command..." -- tedious for a multi-step job and easy to get wrong. Restricted to status == "pending" (reusing _MOVABLE_STATUSES, the same set already used for "is this row safe to reorder") -- an "incomplete" command job may have partially executed steps, a materially different and riskier case than a never-started one. Live-verified against the running simulated flomni session: button correctly relabels per selection, editing a real queued command job replaces it in place with the id/label preserved, and the session's queue was left exactly as found afterward. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NPZ9gzN2rt3wgiMnTKyrug
This commit is contained in:
1 parent
91eb55bf13
commit
8e2a320e58
2 files changed
+164
-29
No files matched your search
@@ -412,8 +412,12 @@ GUI bug and reporting gaps for the hook feature.
|
||||
|
||||
42. Queue a `done` tomo job (run one, or add one via CLI with `status`
|
||||
hand-edited to `done`). Select it in the queue dialog and confirm
|
||||
**"Load into editor"** is enabled. Select a command job (or multiple
|
||||
rows, or nothing) and confirm it's **disabled** in each case.
|
||||
**"Load into editor"** is enabled. Select multiple rows (or nothing)
|
||||
and confirm it's **disabled**. Select a *pending* command job and
|
||||
confirm the button text instead switches to **"Edit command"**
|
||||
(enabled) — see 6f below for that path; select a `running`/
|
||||
`incomplete`/`done` command job and confirm it's **disabled** (text
|
||||
reverts to "Load into editor").
|
||||
43. Click **"Load into editor"** with nothing else in progress. Confirm the
|
||||
params panel enters edit mode (Edit button hides, Submit/"Add to
|
||||
queue"/Cancel appear) with every field populated from the *job's*
|
||||
@@ -488,6 +492,28 @@ buttons living on two different windows.
|
||||
to queue" — confirm it queues normally with **no** warning (only
|
||||
fires when an edit is actually in progress).
|
||||
|
||||
## 6g. Test plan — new: "Edit command" (same button slot as "Load into editor")
|
||||
|
||||
48. Add a multi-step command job via **"Add command…"** (e.g. a `move` step
|
||||
plus a `move_foptz_with_shift` step), with a custom label and the
|
||||
idempotent checkbox left at its default. Select it in the queue table
|
||||
and confirm the button reads **"Edit command"**.
|
||||
49. Click it. Confirm `CommandJobBuilderDialog` opens titled **"Edit
|
||||
command job"**, with the step list showing both steps exactly as the
|
||||
queue table's Details column renders them, the label field pre-filled
|
||||
with your custom label, and the idempotent checkbox matching what you
|
||||
set when adding it.
|
||||
50. Click **Cancel**. Confirm the queue is completely unchanged (same job,
|
||||
same position, same `id` — check via `flomni.tomo_queue_show()` or
|
||||
`flomni._tomo_queue_proxy.as_list()` before/after).
|
||||
51. Reopen it, remove a step, add a different one, change the label, click
|
||||
**OK**. Confirm the row updates **in place** (same position in the
|
||||
table, same `id` via the CLI check above) with the new steps/label —
|
||||
no new row is appended, no old row left behind.
|
||||
52. Confirm the button is **disabled** for a `running`/`incomplete`/`done`
|
||||
command job (only `pending` is editable), and also disabled while
|
||||
**Sort queue…** mode is active.
|
||||
|
||||
## 7. Known limitations of this first iteration (by design, not bugs)
|
||||
|
||||
Worth knowing before you file something as broken:
|
||||
@@ -508,13 +534,16 @@ Worth knowing before you file something as broken:
|
||||
(`tomo_queue_add_command` with a `positions` dict of more than one
|
||||
device); the GUI builder just doesn't expose it yet. Add extra `move`
|
||||
steps instead if you need to move more than one device.
|
||||
- **No live device-limit validation.** The plan (section 6.5) mentions
|
||||
validating against `dev.<name>.limits` in addition to the schema's
|
||||
min/max; this iteration only enforces the schema bounds (via the spinbox
|
||||
range), not real hardware limits. The execution-time re-check in
|
||||
`_queue_action_move()` is still the actual safety boundary regardless
|
||||
(two-layer validation, plan section 3.3), so this is a UX gap, not a
|
||||
safety gap.
|
||||
- **Resolved, for fields that opt in: live device-limit validation.** A
|
||||
float param schema can now declare `"device_limits_from": "<device>"`
|
||||
(see `move_foptz_with_shift`'s `foptz_target`), which makes both the GUI
|
||||
spinbox's range and the CLI's add-time check (`_validate_action_kwargs`)
|
||||
use `dev.<name>.limits` instead of the schema's static `min`/`max`. The
|
||||
plain `move` action's devices (`ccm_energy`/`idgap`) don't use this --
|
||||
still just the schema bounds via the spinbox range there. The
|
||||
execution-time re-check in `_queue_action_move()`/
|
||||
`_queue_action_move_foptz_with_shift()` remains the actual safety
|
||||
boundary regardless (two-layer validation, plan section 3.3).
|
||||
- **Resolved: `Submit` is now a hard block while the beamline is busy**,
|
||||
matching plan section 6.1 literally instead of the earlier soft-warn
|
||||
confirmation dialog. The gap that made the soft warn tempting in the first
|
||||
|
||||
@@ -1666,12 +1666,10 @@ class TomoQueueDialog(QDialog):
|
||||
btn_row = QHBoxLayout()
|
||||
self._btn_add = QPushButton("Add current params to queue")
|
||||
self._btn_add_cmd = QPushButton("Add command…")
|
||||
# Text/tooltip are dual-purpose ("Load into editor" for a tomo job,
|
||||
# "Edit command" for a pending command job) and set by
|
||||
# _update_load_button(), called immediately below via _refresh().
|
||||
self._btn_load = QPushButton("Load into editor")
|
||||
self._btn_load.setToolTip(
|
||||
"Load the selected tomo job's saved settings into the params panel's "
|
||||
"editor -- doesn't touch live params or the queue itself. Review, "
|
||||
'tweak, then Submit or "Add to queue" from there.'
|
||||
)
|
||||
self._btn_load.setEnabled(False)
|
||||
self._btn_del = QPushButton("Delete selected")
|
||||
self._btn_dup = QPushButton("Duplicate selected")
|
||||
@@ -1693,7 +1691,7 @@ class TomoQueueDialog(QDialog):
|
||||
btn_exe = QPushButton("Execute queue…")
|
||||
self._btn_add.clicked.connect(self.add_to_queue)
|
||||
self._btn_add_cmd.clicked.connect(self.add_command_to_queue)
|
||||
self._btn_load.clicked.connect(self._on_load_into_editor)
|
||||
self._btn_load.clicked.connect(self._on_load_or_edit_clicked)
|
||||
self._btn_del.clicked.connect(self._delete_selected)
|
||||
self._btn_dup.clicked.connect(self._duplicate_selected)
|
||||
self._btn_clr.clicked.connect(self._clear_queue)
|
||||
@@ -1837,10 +1835,57 @@ class TomoQueueDialog(QDialog):
|
||||
job = jobs[row]
|
||||
return job if _job_kind(job) == "tomo" else None
|
||||
|
||||
def _selected_single_pending_command_job(self) -> Optional[dict]:
|
||||
"""Return the single selected job if it's a *pending* command job,
|
||||
else None. Mirrors _selected_single_tomo_job() above.
|
||||
|
||||
Restricted to self._MOVABLE_STATUSES ("pending" only, not
|
||||
"incomplete") -- the same set already used for "is this row safe
|
||||
to reorder". An incomplete command job may have partially executed
|
||||
steps; editing that is a materially different, riskier case than a
|
||||
never-started job, and not supported here.
|
||||
"""
|
||||
rows = sorted({idx.row() for idx in self._table.selectedIndexes()})
|
||||
if len(rows) != 1:
|
||||
return None
|
||||
jobs = self._load_queue()
|
||||
row = rows[0]
|
||||
if not 0 <= row < len(jobs):
|
||||
return None
|
||||
job = jobs[row]
|
||||
if _job_kind(job) != "command":
|
||||
return None
|
||||
return job if job.get("status", "pending") in self._MOVABLE_STATUSES else None
|
||||
|
||||
def _update_load_button(self) -> None:
|
||||
self._btn_load.setEnabled(
|
||||
not self._sort_mode and self._selected_single_tomo_job() is not None
|
||||
)
|
||||
"""self._btn_load is dual-purpose: "Load into editor" for a single
|
||||
selected tomo job (any status, unchanged behavior), or "Edit
|
||||
command" for a single selected *pending* command job (new -- see
|
||||
_on_load_or_edit_clicked()). Anything else disables it.
|
||||
"""
|
||||
if self._sort_mode:
|
||||
self._btn_load.setText("Load into editor")
|
||||
self._btn_load.setEnabled(False)
|
||||
return
|
||||
if self._selected_single_tomo_job() is not None:
|
||||
self._btn_load.setText("Load into editor")
|
||||
self._btn_load.setToolTip(
|
||||
"Load the selected tomo job's saved settings into the params panel's "
|
||||
"editor -- doesn't touch live params or the queue itself. Review, "
|
||||
'tweak, then Submit or "Add to queue" from there.'
|
||||
)
|
||||
self._btn_load.setEnabled(True)
|
||||
elif self._selected_single_pending_command_job() is not None:
|
||||
self._btn_load.setText("Edit command")
|
||||
self._btn_load.setToolTip(
|
||||
"Open the selected pending command job's steps in the command "
|
||||
"builder for review/editing. OK replaces this queued job in "
|
||||
"place (same position); Cancel leaves it untouched."
|
||||
)
|
||||
self._btn_load.setEnabled(True)
|
||||
else:
|
||||
self._btn_load.setText("Load into editor")
|
||||
self._btn_load.setEnabled(False)
|
||||
|
||||
def _update_duplicate_button(self) -> None:
|
||||
# Unlike Load-into-editor, duplication works for a job of any kind
|
||||
@@ -1848,15 +1893,38 @@ class TomoQueueDialog(QDialog):
|
||||
# "exactly one row selected" is the only requirement.
|
||||
self._btn_dup.setEnabled(not self._sort_mode and self._selected_single_row() >= 0)
|
||||
|
||||
def _on_load_into_editor(self) -> None:
|
||||
job = self._selected_single_tomo_job()
|
||||
if job is None:
|
||||
def _on_load_or_edit_clicked(self) -> None:
|
||||
"""Dispatches self._btn_load's two behaviors -- see
|
||||
_update_load_button()'s docstring. Re-derives the selection fresh
|
||||
rather than trusting anything cached since the last ~2s poll.
|
||||
"""
|
||||
tomo_job = self._selected_single_tomo_job()
|
||||
if tomo_job is not None:
|
||||
parent = self.parent()
|
||||
if parent is None or not hasattr(parent, "load_params_into_editor"):
|
||||
QMessageBox.warning(self, "Can't load", "No params panel available to load into.")
|
||||
return
|
||||
parent.load_params_into_editor(dict(tomo_job.get("params", {})), tomo_job.get("label", ""))
|
||||
return
|
||||
parent = self.parent()
|
||||
if parent is None or not hasattr(parent, "load_params_into_editor"):
|
||||
QMessageBox.warning(self, "Can't load", "No params panel available to load into.")
|
||||
|
||||
command_job = self._selected_single_pending_command_job()
|
||||
if command_job is None:
|
||||
return
|
||||
parent.load_params_into_editor(dict(job.get("params", {})), job.get("label", ""))
|
||||
row = sorted({idx.row() for idx in self._table.selectedIndexes()})[0]
|
||||
dlg = CommandJobBuilderDialog(self._client, parent=self, job=command_job)
|
||||
if dlg.exec() == QDialog.DialogCode.Accepted and dlg.job is not None:
|
||||
jobs = self._load_queue()
|
||||
if 0 <= row < len(jobs) and jobs[row].get("id") == command_job.get("id"):
|
||||
jobs[row] = dlg.job
|
||||
self._save_queue(jobs)
|
||||
self._refresh()
|
||||
else:
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
"Queue changed",
|
||||
"The queue changed while editing this job -- nothing was "
|
||||
"replaced. Re-select the job and try again.",
|
||||
)
|
||||
|
||||
# ── sort mode ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -2080,12 +2148,20 @@ class CommandJobBuilderDialog(QDialog):
|
||||
assembled ``steps`` list) so CLI and GUI stay interchangeable. The caller
|
||||
is responsible for appending it to the queue -- this dialog only builds
|
||||
the dict, it never touches the queue global var itself.
|
||||
|
||||
Pass an existing command ``job`` dict to pre-populate the builder for
|
||||
editing (``TomoQueueDialog._on_load_or_edit_clicked()``'s "Edit
|
||||
command" path) instead of starting empty. ``self.job`` on accept then
|
||||
keeps that job's original ``id``/``added_at`` (same queue entry being
|
||||
revised, not a new addition) -- the caller still owns writing it back
|
||||
into the queue at the right position.
|
||||
"""
|
||||
|
||||
def __init__(self, client, parent=None):
|
||||
def __init__(self, client, parent=None, job: Optional[dict] = None):
|
||||
super().__init__(parent)
|
||||
self._client = client
|
||||
self.setWindowTitle("Add command job")
|
||||
self._editing_job = job
|
||||
self.setWindowTitle("Edit command job" if job is not None else "Add command job")
|
||||
self.setMinimumSize(520, 480)
|
||||
self.job: Optional[dict] = None
|
||||
|
||||
@@ -2108,6 +2184,28 @@ class CommandJobBuilderDialog(QDialog):
|
||||
"can't be built without it.",
|
||||
)
|
||||
|
||||
if job is not None:
|
||||
self._populate_from_job(job)
|
||||
|
||||
def _populate_from_job(self, job: dict) -> None:
|
||||
"""Pre-fill the builder from an existing command job (the "Edit
|
||||
command" path). Steps are re-added in the same {action, kwargs}
|
||||
shape _on_add_step() produces, using its exact summary format, so
|
||||
pre-populated rows render identically to freshly-added ones.
|
||||
"""
|
||||
self._label_edit.setText(job.get("label", ""))
|
||||
for step in job.get("steps", []):
|
||||
action_name = step.get("action")
|
||||
kwargs = step.get("kwargs", {})
|
||||
self._steps.append({"action": action_name, "kwargs": kwargs})
|
||||
summary = f"{action_name}{kwargs}" if kwargs else action_name
|
||||
self._step_list.addItem(summary)
|
||||
# The job's actual saved flag, not a recomputed default -- mark
|
||||
# overridden so _recompute_idempotent_default() leaves it alone as
|
||||
# the operator edits steps.
|
||||
self._idem_check.setChecked(bool(job.get("idempotent", False)))
|
||||
self._idem_user_overridden = True
|
||||
|
||||
def _build_ui(self):
|
||||
vbox = QVBoxLayout(self)
|
||||
|
||||
@@ -2355,14 +2453,22 @@ class CommandJobBuilderDialog(QDialog):
|
||||
QMessageBox.warning(self, "No steps", "Add at least one step before confirming.")
|
||||
return
|
||||
label = self._label_edit.text().strip() or f"cmd_{uuid.uuid4().hex[:6]}"
|
||||
# Editing an existing job keeps its id/added_at -- it's the same
|
||||
# queue entry being revised, not a new addition.
|
||||
job_id = self._editing_job["id"] if self._editing_job else uuid.uuid4().hex
|
||||
added_at = (
|
||||
self._editing_job["added_at"]
|
||||
if self._editing_job
|
||||
else datetime.datetime.now().isoformat(timespec="seconds")
|
||||
)
|
||||
self.job = {
|
||||
"kind": "command",
|
||||
"id": uuid.uuid4().hex,
|
||||
"id": job_id,
|
||||
"label": label,
|
||||
"steps": list(self._steps),
|
||||
"idempotent": self._idem_check.isChecked(),
|
||||
"status": "pending",
|
||||
"added_at": datetime.datetime.now().isoformat(timespec="seconds"),
|
||||
"added_at": added_at,
|
||||
}
|
||||
self.accept()
|
||||
|
||||
|
||||
Reference in new issue
Block a user