-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug(data frame filter): When the filter is reset, be sure to use a ""…
… value for the input (#1557)
- Loading branch information
Showing
6 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
tests/playwright/shiny/components/data_frame/filter_reset/app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import cast | ||
|
||
import pandas as pd | ||
from palmerpenguins import load_penguins # pyright: ignore[reportMissingTypeStubs] | ||
|
||
from shiny import reactive | ||
from shiny.express import input, render, ui | ||
|
||
penguins = cast(pd.DataFrame, load_penguins()) | ||
|
||
ui.input_action_button("update_filters", "Update filters") | ||
ui.input_action_button("reset_filters", "Reset filters") | ||
|
||
ui.h5("Current filters: ", {"class": "pt-2"}) | ||
|
||
|
||
@render.code | ||
def penguins_code(): | ||
return str(penguins_df.filter()) | ||
|
||
|
||
@render.data_frame | ||
def penguins_df(): | ||
return render.DataGrid(penguins, filters=True) | ||
|
||
|
||
@reactive.effect | ||
@reactive.event(input.update_filters) | ||
async def _(): | ||
await penguins_df.update_filter( | ||
[ | ||
{"col": 0, "value": "Gentoo"}, | ||
{"col": 2, "value": (50, None)}, | ||
{"col": 3, "value": (None, 17)}, | ||
{"col": 4, "value": (220, 225)}, | ||
], | ||
) | ||
|
||
|
||
@reactive.effect | ||
@reactive.event(input.reset_filters) | ||
async def _(): | ||
await penguins_df.update_filter(None) # << |
43 changes: 43 additions & 0 deletions
43
tests/playwright/shiny/components/data_frame/filter_reset/test_filter_reset.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from playwright.sync_api import Page, expect | ||
|
||
from shiny.playwright import controller | ||
from shiny.run import ShinyAppProc | ||
|
||
|
||
def test_filters_are_reset(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
penguin_df = controller.OutputDataFrame(page, "penguins_df") | ||
penguin_code = controller.OutputCode(page, "penguins_code") | ||
update_filters = controller.InputActionButton(page, "update_filters") | ||
reset_filters = controller.InputActionButton(page, "reset_filters") | ||
|
||
filter_inputs = penguin_df.loc_column_filter.locator("input") | ||
|
||
expect(filter_inputs).to_have_count(8 + 5) # 8 columns including 5 numeric columns | ||
|
||
penguin_code.expect_value("()") | ||
for element in filter_inputs.element_handles(): | ||
assert element.input_value() == "" | ||
|
||
update_filters.click() | ||
|
||
penguin_code.expect_value( | ||
"(" | ||
"{'col': 0, 'value': 'Gentoo'}, " | ||
"{'col': 2, 'value': (50, None)}, " | ||
"{'col': 3, 'value': (None, 17)}, " | ||
"{'col': 4, 'value': (220, 225)}" | ||
")" | ||
) | ||
for value, element in zip( | ||
["Gentoo", "", "50", "", "", "17", "220", "225", "", "", "", "", ""], | ||
filter_inputs.element_handles(), | ||
): | ||
assert element.input_value() == value | ||
|
||
reset_filters.click() | ||
|
||
penguin_code.expect_value("()") | ||
for element in filter_inputs.element_handles(): | ||
assert element.input_value() == "" |