Skip to content

Commit

Permalink
Display loading indicator on View (#435)
Browse files Browse the repository at this point in the history
* Display loading indicator on View

* Add guard
  • Loading branch information
philippjfr authored Jan 24, 2023
1 parent 5ab929f commit 5475c1a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lumen/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ class View(MultiTypeComponent, Viewer):
The download objects determines whether and how the source tables
can be downloaded.""")

loading_indicator = param.Boolean(default=True, constant=True, doc="""
Whether to display a loading indicator on the View when the
Pipeline is refreshing the data.""")

pipeline = param.ClassSelector(class_=Pipeline, doc="""
The data pipeline that drives the View.""")

Expand Down Expand Up @@ -178,6 +182,8 @@ def __init__(self, **params):
if isinstance(self.param[fp], param.Selector):
self.param[fp].objects = fields
pipeline.param.watch(self.update, 'data')
if self.loading_indicator:
pipeline._update_widget.param.watch(self._update_loading, 'loading')
super().__init__(pipeline=pipeline, refs=refs, **params)
self.param.watch(self.update, [p for p in self.param if p not in ('rerender', 'selection_expr', 'name')])
self.download.view = self
Expand All @@ -190,6 +196,10 @@ def __panel__(self) -> Viewable:
self.update()
return pn.panel(pn.bind(lambda e: self.panel, self.param.rerender))

def _update_loading(self, event):
if self._panel is not None:
self._panel.loading = event.new

def _update_ref(self, pname: str, ref: str, *events: param.parameterized.Event) -> None:
# Note: Do not trigger update in View if Pipeline references
# the same variable and is not set up to auto-update
Expand Down

0 comments on commit 5475c1a

Please sign in to comment.