Skip to content

Commit f7b7fb4

Browse files
authored
feat(bookmark): Allow for session.bookmark.update_query_string(query_string=) to be optional (#1934)
1 parent 3a8b7b2 commit f7b7fb4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

shiny/bookmark/_bookmark.py

Lines changed: 13 additions & 6 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(
@@ -723,7 +726,9 @@ def _restore_context(self) -> RestoreContext | None:
723726
return self._root_bookmark._restore_context
724727

725728
async def update_query_string(
726-
self, query_string: str, mode: Literal["replace", "push"] = "replace"
729+
self,
730+
query_string: Optional[str] = None,
731+
mode: Literal["replace", "push"] = "replace",
727732
) -> None:
728733
await self._root_bookmark.update_query_string(query_string, mode)
729734

@@ -769,7 +774,9 @@ def on_bookmarked(
769774
return lambda: None
770775

771776
async def update_query_string(
772-
self, query_string: str, mode: Literal["replace", "push"] = "replace"
777+
self,
778+
query_string: Optional[str] = None,
779+
mode: Literal["replace", "push"] = "replace",
773780
) -> None:
774781
# no-op within ExpressStub
775782
return None

0 commit comments

Comments
 (0)