Skip to content

Commit

Permalink
Unify is_external prop in rx.redirect and rx.link (#4389)
Browse files Browse the repository at this point in the history
* Unify `is_external` prop in `rx.redirect` and `rx.link`

* default external to `None`

* address PR comment

* use a one-liner

* reorder args for api stability

Co-authored-by: Masen Furer <m_github@0x26.net>

* reorder doc args

* external arg as deprecated in the docs

* Update reflex/event.py

Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>

* Fixup typing_extensions import and ruff

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent f4aea1b commit 206de4d
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions reflex/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
overload,
)

import typing_extensions
from typing_extensions import (
Concatenate,
ParamSpec,
Expand Down Expand Up @@ -714,26 +715,61 @@ def fn():
)


@overload
def redirect(
path: str | Var[str],
is_external: Optional[bool] = None,
replace: bool = False,
) -> EventSpec: ...


@overload
@typing_extensions.deprecated("`external` is deprecated use `is_external` instead")
def redirect(
path: str | Var[str],
is_external: Optional[bool] = None,
replace: bool = False,
external: Optional[bool] = None,
) -> EventSpec: ...


def redirect(
path: str | Var[str],
external: Optional[bool] = False,
replace: Optional[bool] = False,
is_external: Optional[bool] = None,
replace: bool = False,
external: Optional[bool] = None,
) -> EventSpec:
"""Redirect to a new path.
Args:
path: The path to redirect to.
external: Whether to open in new tab or not.
is_external: Whether to open in new tab or not.
replace: If True, the current page will not create a new history entry.
external(Deprecated): Whether to open in new tab or not.
Returns:
An event to redirect to the path.
"""
if external is not None:
console.deprecate(
"The `external` prop in `rx.redirect`",
"use `is_external` instead.",
"0.6.6",
"0.7.0",
)

# is_external should take precedence over external.
is_external = (
(False if external is None else external)
if is_external is None
else is_external
)

return server_side(
"_redirect",
get_fn_signature(redirect),
path=path,
external=external,
external=is_external,
replace=replace,
)

Expand Down

0 comments on commit 206de4d

Please sign in to comment.