Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes popup being invisible forever after closing once #6347

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,23 +687,22 @@ def _process_selection_event(self):
if popup is not None:
break

if callable(popup):
popup_is_callable = callable(popup)
if popup_is_callable:
with set_curdoc(self.plot.document):
popup = popup(**stream.contents)

# If no popup is defined, hide the panel
# If no popup is defined, hide the bokeh panel wrapper
if popup is None:
if self._panel.visible:
self._panel.visible = False
return

if event is not None:
position = self._get_position(event)
Copy link
Collaborator Author

@ahuang11 ahuang11 Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this down inside existing popup since it's unused if there's no existing popup.

else:
position = None

popup_pane = panel(popup)
if not popup_pane.visible:
# offer the user ability to control when the popup bk panel shows up
# however, if the popup is not callable (singleton), we cannot do this
# check--else, it'll never re-appear if they set `visible=False` once
if popup_is_callable and not popup_pane.visible:
return

if not popup_pane.stylesheets:
Expand All @@ -724,6 +723,8 @@ def _process_selection_event(self):
# otherwise, UnknownReferenceError: can't resolve reference 'p...'
# meaning the popup has already been removed; we need to regenerate
if self._existing_popup and not self._existing_popup.visible:
self._existing_popup.visible = True
position = self._get_position(event) if event else None
if position:
self._panel.position = XY(**position)
if self.plot.comm: # update Jupyter Notebook
Expand Down
46 changes: 46 additions & 0 deletions holoviews/tests/ui/bokeh/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ def popup_form(x, y):
page.click(".bk-btn.bk-btn-default")
expect(locator).not_to_be_visible()

hv_plot.click()
locator = page.locator(".bk-btn.bk-btn-default")
expect(locator).to_have_count(1)
expect(locator).to_be_visible()


@skip_popup
@pytest.mark.usefixtures("bokeh_backend")
Expand Down Expand Up @@ -346,6 +351,47 @@ def popup_form(index):
expect(locator).to_have_count(1)


@skip_popup
@pytest.mark.usefixtures("bokeh_backend")
def test_stream_popup_noncallable_reappear(serve_hv, points):
def popup_form(name):
text_input = pn.widgets.TextInput(name='Description')
button = pn.widgets.Button(
name='Save',
on_click=lambda _: layout.param.update(visible=False),
button_type="primary"
)
layout = pn.Column(f'# {name}', text_input, button)
return layout

points = points.opts(hit_dilation=5)
hv.streams.Tap(source=points, popup=popup_form('Tap'))
points.opts(tools=["tap"], active_tools=["tap"])

page = serve_hv(points)
hv_plot = page.locator('.bk-events')
expect(hv_plot).to_have_count(1)

hv_plot.click()

locator = page.locator("#tap")
expect(locator).to_have_count(1)
locator = page.locator(".bk-btn.bk-btn-primary")
expect(locator).to_have_count(1)
expect(locator).to_be_visible()

page.click(".bk-btn.bk-btn-primary")
expect(locator).not_to_be_visible()

hv_plot.click()

locator = page.locator("#tap")
expect(locator).to_have_count(1)
locator = page.locator(".bk-btn.bk-btn-primary")
expect(locator).to_have_count(1)
expect(locator).to_be_visible()


@skip_popup
@pytest.mark.usefixtures("bokeh_backend")
def test_stream_popup_selection1d_lasso_select(serve_hv, points):
Expand Down