Skip to content

Commit

Permalink
Tabulator: fix error raised when setting value with multiselect editor (
Browse files Browse the repository at this point in the history
#5828)

* support event holding a list

* add a test
  • Loading branch information
maximlt authored Nov 10, 2023
1 parent e59d2ea commit 5205ca5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
14 changes: 14 additions & 0 deletions panel/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,17 @@ def change_test_dir(request):
os.chdir(request.fspath.dirname)
yield
os.chdir(request.config.invocation_dir)

@pytest.fixture
def exception_handler_accumulator():
exceptions = []

def eh(exception):
exceptions.append(exception)

old_eh = config.exception_handler
config.exception_handler = eh
try:
yield exceptions
finally:
config.exception_handler = old_eh
40 changes: 40 additions & 0 deletions panel/tests/ui/widgets/test_tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,46 @@ def test_tabulator_editors_tabulator_list_default(page):
expect(page.locator('.tabulator-edit-list')).to_have_text('AB')


def test_tabulator_editors_tabulator_multiselect(page, exception_handler_accumulator):
# https://github.com/holoviz/panel/issues/5556
df = pd.DataFrame({"tags": ['', '', '']}, index=['foo1', 'foo2', 'foo3'],
)
tabulator_editors = {
'tags': {
'type': 'list',
'values': ['red', 'green', 'blue', 'orange'],
'multiselect': True,
}
}
widget = Tabulator(value=df, editors=tabulator_editors)
clicks = []
widget.on_click(clicks.append)

serve_component(page, widget)

cell = page.locator('.tabulator-cell:visible').nth(3)
cell.click()
val = ['red', 'blue']
for v in val:
item = page.locator(f'.tabulator-edit-list-item:has-text("{v}")')
item.click()
# Validating the filters doesn't have a very nice behavior, you need to lose
# focus on the multiselect by clicking somewhere else.
# Delay required before clicking for the focus to be lost and the filters accounted for.
page.wait_for_timeout(200)
page.locator('text="foo1"').click()

cell.click()
val = ['red', 'blue']
for v in val:
item = page.locator(f'.tabulator-edit-list-item:has-text("{v}")')
item.click()
page.wait_for_timeout(200)
page.locator('text="foo1"').click()

assert not exception_handler_accumulator


@pytest.mark.parametrize('layout', Tabulator.param['layout'].objects)
def test_tabulator_column_layouts(page, df_mixed, layout):
widget = Tabulator(df_mixed, layout=layout)
Expand Down
2 changes: 1 addition & 1 deletion panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ def _process_event(self, event):
if event.event_name == 'table-edit':
if event.pre:
import pandas as pd
filter_df = pd.DataFrame([event.value], columns=[event.column])
filter_df = pd.DataFrame({event.column: [event.value]})
filters = self._get_header_filters(filter_df)
# Check if edited cell was filtered
if filters and filters[0].any():
Expand Down

0 comments on commit 5205ca5

Please sign in to comment.