Skip to content

Commit 694cdab

Browse files
committed
feat: Improve URL selection handling in DataUI; clear stale selections on load
1 parent e8d5ea6 commit 694cdab

2 files changed

Lines changed: 8 additions & 44 deletions

File tree

dvue/dataui.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,11 @@ def _setup_selection_url_sync(self):
15381538
if not loc:
15391539
return
15401540

1541-
# --- Restore on load ---
1541+
# --- Restore on load (one-shot) ---
1542+
# Apply any selection encoded in the URL, then immediately clear it
1543+
# so that the next server startup begins with no stale selection.
1544+
# The watcher below is registered *after* this block, so the clear
1545+
# is not overwritten by the change event from the initial restore.
15421546
query_params = loc.query_params or {}
15431547
sel_str = query_params.get("sel", "")
15441548
if sel_str:
@@ -1547,6 +1551,9 @@ def _setup_selection_url_sync(self):
15471551
indices = self._dfcat.index[self._dfcat["name"].isin(names)].tolist()
15481552
if indices and hasattr(self, "display_table"):
15491553
self.display_table.selection = indices
1554+
# Clear from URL before the watcher is registered so the next
1555+
# startup does not auto-select rows from a stale browser URL.
1556+
loc.update_query(sel="")
15501557

15511558
# --- Watch for changes and update URL ---
15521559
def _on_selection_change(event):

dvue/session_persistence.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -319,30 +319,7 @@ def make_app():
319319
if user_id:
320320
_registry[user_id] = {"mgr": mgr, "ui": ui, "template": tmpl}
321321

322-
sel = saved.get("selection", [])
323-
324322
def _on_load():
325-
# Replay saved selection → re-trigger Plot action. Only
326-
# meaningful after a server restart when diskcache had a saved
327-
# selection; fresh users have no saved state.
328-
if sel and hasattr(ui, "display_table") and hasattr(ui, "_registered_actions"):
329-
plot_cb = next(
330-
(
331-
a["callback"]
332-
for a in ui._registered_actions
333-
if a.get("name") == "Plot"
334-
),
335-
None,
336-
)
337-
if plot_cb:
338-
n_rows = len(ui.display_table.value) if ui.display_table.value is not None else 0
339-
valid_sel = [i for i in sel if i < n_rows]
340-
if valid_sel:
341-
ui.display_table.selection = valid_sel
342-
pn.state.curdoc.add_next_tick_callback(
343-
lambda: plot_cb(None, ui)
344-
)
345-
346323
# Wire live-persistence watchers so any param change is
347324
# immediately flushed to diskcache (only when persist=True).
348325
if persist:
@@ -690,31 +667,11 @@ def make_app():
690667
if user_id:
691668
_registry[user_id] = {"mgr": mgr, "ui": ui, "template": tmpl}
692669

693-
sel = saved.get("selection", [])
694-
695670
def _on_load():
696671
# Capture the running Tornado IOLoop so the pywebview GUI thread can
697672
# schedule confirmation callbacks via IOLoop.add_callback (thread-safe).
698673
_app_state["ioloop"] = _tornado_ioloop.IOLoop.current()
699674

700-
if sel and hasattr(ui, "display_table") and hasattr(ui, "_registered_actions"):
701-
plot_cb = next(
702-
(
703-
a["callback"]
704-
for a in ui._registered_actions
705-
if a.get("name") == "Plot"
706-
),
707-
None,
708-
)
709-
if plot_cb:
710-
n_rows = len(ui.display_table.value) if ui.display_table.value is not None else 0
711-
valid_sel = [i for i in sel if i < n_rows]
712-
if valid_sel:
713-
ui.display_table.selection = valid_sel
714-
pn.state.curdoc.add_next_tick_callback(
715-
lambda: plot_cb(None, ui)
716-
)
717-
718675
if persist:
719676
def _do_save(event=None):
720677
if user_id:

0 commit comments

Comments
 (0)