Skip to content

Commit

Permalink
Add overwriting of default
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Oct 31, 2023
1 parent 03a9d40 commit afdf2e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lumen/filters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def __init__(self, **params):
self.widget.link(self, bidirectional=True, value='value', visible='visible', disabled='disabled')
if self._sync_with_url:
pn.state.location.sync(self.widget, {'value': self.field}, on_error=self._url_sync_error)
if self.default is not None and not self.widget.value:
if self.default is not None and self.value is None:
self.widget.value = self.default

@classmethod
Expand Down
12 changes: 12 additions & 0 deletions lumen/tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ def test_dashboard_with_url_sync_filters_with_default(set_root, document):
assert f2.value == ['foo1', 'foo2', 'foo3']
assert f2.widget.value == ['foo1', 'foo2', 'foo3']

def test_dashboard_with_url_sync_filters_with_overwritten_default(set_root, document):
root = pathlib.Path(__file__).parent / 'sample_dashboard'
set_root(str(root))
dashboard = Dashboard(str(root / 'sync_query_filters_default.yaml'))
dashboard._render_dashboard()
layout = dashboard.layouts[0]
f1, f2 = list(layout._pipelines.values())[0].filters
f1.value = (0.1, 0.7)
f2.value = [] # overwriting default with empty list
assert pn.state.location.search == '?A=%5B0.1%2C+0.7%5D&C=%5B%5D'
assert f2.widget.value == []

@sql_available
def test_dashboard_with_sql_source_and_transforms(set_root, document, mixed_df_object_type):
root = pathlib.Path(__file__).parent / 'sample_dashboard'
Expand Down

0 comments on commit afdf2e9

Please sign in to comment.