Skip to content

Commit

Permalink
fix based on PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ElijahAhianyo committed Sep 7, 2023
1 parent f76f94c commit 8f5b1e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
12 changes: 6 additions & 6 deletions integration/test_event_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def click_yield_nested(self):

def redirect_return_chain(self):
self.event_order.append("redirect_return_chain")
yield rx.redirect("/on_load_return_chain")
yield rx.redirect("/on-load-return-chain")

def redirect_yield_chain(self):
self.event_order.append("redirect_yield_chain")
yield rx.redirect("/on_load_yield_chain")
yield rx.redirect("/on-load-yield-chain")

def click_return_int_type(self):
self.event_order.append("click_return_int_type")
Expand Down Expand Up @@ -367,7 +367,7 @@ def test_event_chain_click(event_chain, driver, button_id, exp_event_order):
("uri", "exp_event_order"),
[
(
"/on_load_return_chain",
"/on-load-return-chain",
[
"on_load_return_chain",
"event_arg:1",
Expand All @@ -376,7 +376,7 @@ def test_event_chain_click(event_chain, driver, button_id, exp_event_order):
],
),
(
"/on_load_yield_chain",
"/on-load-yield-chain",
[
"on_load_yield_chain",
"event_arg:4",
Expand Down Expand Up @@ -411,7 +411,7 @@ def test_event_chain_on_load(event_chain, driver, uri, exp_event_order):
("uri", "exp_event_order"),
[
(
"/on_mount_return_chain",
"/on-mount-return-chain",
[
"on_load_return_chain",
"event_arg:unmount",
Expand All @@ -426,7 +426,7 @@ def test_event_chain_on_load(event_chain, driver, uri, exp_event_order):
],
),
(
"/on_mount_yield_chain",
"/on-mount-yield-chain",
[
"on_load_yield_chain",
"event_arg:mount",
Expand Down
18 changes: 17 additions & 1 deletion reflex/utils/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ def to_title_case(text: str) -> str:
return "".join(word.capitalize() for word in text.split("_"))


def to_kebab_case(text: str) -> str:
"""Convert a string to kebab case.
The words in the text are converted to lowercase and
separated by hyphens.
Args:
text: The string to convert.
Returns:
The title case string.
"""
return to_snake_case(text).replace("_", "-")


def format_string(string: str) -> str:
"""Format the given string as a JS string literal..
Expand Down Expand Up @@ -207,14 +222,15 @@ def format_route(route: str, format_case=True) -> str:
Args:
route: The route to format.
format_case: whether to format case to kebab case.
Returns:
The formatted route.
"""
route = route.strip("/")
# Strip the route and format casing.
if format_case:
route = to_snake_case(route)
route = to_kebab_case(route)

# If the route is empty, return the index route.
if route == "":
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ def test_is_generic_alias(cls: type, expected: bool):
("custom-route/", False, "custom-route"),
("/custom-route", True, "custom-route"),
("/custom-route", False, "custom-route"),
("/custom_route", True, "custom_route"),
("/custom_route", True, "custom-route"),
("/custom_route", False, "custom_route"),
("/CUSTOM_route", True, "custom_route"),
("/CUSTOM_route", True, "custom-route"),
("/CUSTOM_route", False, "CUSTOM_route"),
],
)
Expand Down

0 comments on commit 8f5b1e7

Please sign in to comment.