Skip to content

Edit history

panel_flowdash.history

The edit history of a dashboard: a version for every edit, undo and redo, and its storage.

Every change made through the editor, by the person using it or by an agent, becomes a version of the dashboard's document artifact in a panel-agents RunState: the dashboard YAML as the editor's user sees it, with metadata saying which operation made it. A gesture (dragging nodes, typing into a config field, resizing tiles) becomes one version, not one per event.

The versions of the dashboard in the editor are written to its store with a panel-agents HistoryRecorder as they are made, and loaded again when the dashboard is next opened, so undo reaches edits of earlier sessions; while the assistant's drawer is open it is loaded as soon as a dashboard opens, so the drawer lists them. The stored history starts with a format record (:data:HEADER_KEY). The store keeps a limited number and size of versions per dashboard and drops a dashboard's history with the dashboard.

An agent session shares the editor's RunState (:attr:EditHistory.state), so its drawer lists the same versions, grouped by the agent's runs, and its Undo, Redo and Revert buttons go through the same checks as :meth:~panel_flowdash.editor.FlowDash.undo.

ARTIFACT_KIND = 'flowdash-dashboard' module-attribute

EditHistory

The versions of the dashboards an editor has open, and undo and redo over them.

Created by :class:~panel_flowdash.editor.FlowDash, which calls :meth:record after every edit and :meth:opened whenever another dashboard (or a new one) is shown. Use the editor's :meth:~panel_flowdash.editor.FlowDash.undo and :meth:~panel_flowdash.editor.FlowDash.redo rather than this object; :attr:state is the RunState holding the versions, to show them in a panel-agents ArtifactView or to share with an AgentRunner.

active property

Whether edits are recorded: history is on and the user may edit the dashboard.

artifact property

The open dashboard's document artifact, once it has a version.

artifact_id property

The id of the open dashboard's document artifact in :attr:state.

busy property

Whether a request to an agent is running, during which undo and redo wait.

can_redo property

Whether :meth:redo would redo something now.

can_undo property

Whether :meth:undo would undo something now.

editor = editor instance-attribute

on_load = None instance-attribute

redo_label property

What :meth:redo would bring back, for menus.

refused property

Why the open dashboard's stored history is not shown, if it was loaded and is not.

requests_pending property

Whether an agent request has edits not yet published as its version.

shown = False instance-attribute

state = RunState(max_events=MAX_EVENTS) instance-attribute

undo_label property

What :meth:undo would take back, e.g. "Added kpi", for menus.

versions property

The open dashboard's versions, oldest first, including the edit in progress.

batched()

Take the canvas once for the agent's edits made inside, rather than after each of them.

Each agent edit otherwise writes the whole dashboard as YAML, which on a large dashboard is the bulk of an edit's time. Only for edits made without yielding to the event loop, such as Explore's Add: a person's edit cannot land between them, so the canvas at the end is the one the agent's last edit left.

close()

Publish the edit in progress and stop writing to the store.

drop_requests(run_id)

Forget the edits request run_id made so far without a version, e.g. once taken back.

end_requests(run_id=None)

Publish the version of each agent request that ended: all of them, or those of run_id.

The editor calls it when the agent's turns end, and the history when a run in its state finishes or fails, so a request is one version whether it finished, failed or was cancelled. The tiles the request added are laid out first, as part of its version.

flush()

Publish the edit in progress, if any, as a version.

follow(state)

Treat the runs of another agent's state like those in :attr:state.

For an agent whose runs are shown apart from the history's, such as the Explore view's: undo and redo wait while one of its runs is going, and each request's edits become a version when its run ends.

grouped(*, atomic=False)

Make the person's edits inside the block one version, which one undo reverts.

The edit in progress before the block is published first, so undo never takes it along with the block's. With atomic, a block that raises puts the dashboard back as it was before the block, also while the history is off, and its edits never become a version, so neither undo nor redo brings them back.

load()

Load the open dashboard's stored history now, to show it before any edit.

Loading writes nothing to the store: the dashboard as opened becomes a version at the first edit, undo or restore, as without loading. In view mode retention is applied to what is shown, not to the store.

opened()

Start recording the dashboard now in the editor, as it is now.

The stored history is loaded at the first edit, undo or look at the versions, so opening a dashboard to view it costs one YAML dump. The dashboard as opened becomes a version just before the first edit or undo, unless the stored history ends with it.

record(op, args, label, turn)

Record an edit the editor just made, as a new version or as part of the gesture in progress.

Parameters:

Name Type Description Default
op str

The operation, e.g. "add_node" or "set_config".

required
args dict[str, Any]

What it was applied to, e.g. {"name": "kpi"}. Never config values or data, which the version's YAML holds anyway.

required
label str | None

A sentence for people, e.g. "Added kpi".

required
turn AssetTurn | None

The turn the edit belongs to.

required

redo()

Redo what the last undo undid, in one step. See :meth:FlowDash.redo.

request_run()

Return the run of the open dashboard's one agent request still open, or None.

restore(artifact, version)

Make the canvas match version, for an ArtifactView's on_apply.

The view records the step itself. Raises PermissionError if the version holds nodes the user may not bring back.

saved()

Note that the canvas as it is now was saved, under the editor's dashboard id.

When the canvas had no dashboard before, its versions so far move to the saved dashboard's history, so they are stored and undo keeps them.

snapshot()

Return the dashboard YAML as the editor's user sees it, and its revision.

The text starts with the # revision: line DashboardOps.get_dashboard writes.

step_value(action)

Return the version :meth:undo (action "undo") or :meth:redo would apply, if any.

undo(*, whole_runs=True)

Undo the last change, or the agent's whole last request. See :meth:FlowDash.undo.