Skip to content

Commit 52e8b21

Browse files
committed
Allow for session.bookmark.update_query_string(query_string=) to be optional. Default to current bookmark url
1 parent 69a23d5 commit 52e8b21

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

shiny/bookmark/_bookmark.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import warnings
44
from abc import ABC, abstractmethod
55
from pathlib import Path
6-
from typing import TYPE_CHECKING, Awaitable, Callable, Literal
6+
from typing import TYPE_CHECKING, Awaitable, Callable, Literal, Optional
77

88
from .._docstring import add_example
99
from .._utils import AsyncCallbacks, CancelCallback, wrap_async
@@ -167,7 +167,7 @@ def on_restored(
167167
@abstractmethod
168168
async def update_query_string(
169169
self,
170-
query_string: str,
170+
query_string: Optional[str] = None,
171171
mode: Literal["replace", "push"] = "replace",
172172
) -> None:
173173
"""
@@ -176,7 +176,7 @@ async def update_query_string(
176176
Parameters
177177
----------
178178
query_string
179-
The query string to set.
179+
The query string to set. If `None`, the current bookmark state URL will be used.
180180
mode
181181
Whether to replace the current URL or push a new one. Pushing a new value
182182
will add to the user's browser history.
@@ -448,9 +448,12 @@ async def invoke_on_restored_callbacks():
448448

449449
async def update_query_string(
450450
self,
451-
query_string: str,
451+
query_string: Optional[str] = None,
452452
mode: Literal["replace", "push"] = "replace",
453453
) -> None:
454+
if query_string is None:
455+
query_string = await self.get_bookmark_url()
456+
454457
if mode not in {"replace", "push"}:
455458
raise ValueError(f"Invalid mode: {mode}")
456459
await self._root_session._send_message(

0 commit comments

Comments
 (0)