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

Fix dynamically setting footer_objects/header_objects #6705

Merged
merged 2 commits into from
Apr 17, 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
15 changes: 8 additions & 7 deletions panel/chat/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,13 @@ def _build_layout(self):
visible=self.param.show_user, stylesheets=self._stylesheets,
)

header_objects = (
[self._user_html] +
self.param.header_objects.rx() +
[self.chat_copy_icon, self._activity_dot]
)
header_row = Row(
self._user_html,
*self.param.header_objects.rx(),
self.chat_copy_icon,
self._activity_dot,
objects=header_objects,
stylesheets=self._stylesheets + self.param.stylesheets.rx(),
sizing_mode="stretch_width",
css_classes=["header"]
Expand All @@ -317,11 +319,10 @@ def _build_layout(self):
)

footer_col = Column(
*self.param.footer_objects.rx(),
self._timestamp_html,
objects=self.param.footer_objects.rx() + [self._timestamp_html],
stylesheets=self._stylesheets + self.param.stylesheets.rx(),
sizing_mode="stretch_width",
css_classes=["footer"]
css_classes=["footer"],
)

self._right_col = right_col = Column(
Expand Down
15 changes: 6 additions & 9 deletions panel/tests/chat/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from panel.pane.image import PNG, SVG, Image
from panel.pane.markup import HTML, DataFrame, Markdown
from panel.pane.media import Audio
from panel.param import ParamFunction
from panel.tests.util import mpl_available, mpl_figure
from panel.widgets.button import Button
from panel.widgets.input import (
Expand All @@ -29,7 +28,7 @@

class TestChatMessage:
def test_layout(self):
message = ChatMessage(object="ABC", header_objects=["Header Test"], footer_objects=["Footer Test"])
message = ChatMessage(object="ABC", header_objects=["Header Test", "Header 2"], footer_objects=["Footer Test", "Footer 2"])
columns = message._composite.objects
assert len(columns) == 2

Expand All @@ -42,9 +41,8 @@ def test_layout(self):
assert isinstance(user_pane, HTML)
assert user_pane.object == "User"

header_objects = header_row[1][0]
assert isinstance(header_objects, Row)
assert isinstance(header_objects.objects[0], ParamFunction)
assert header_row[1] == "Header Test"
assert header_row[2] == "Header 2"

center_row = columns[1][1]
assert isinstance(center_row, Row)
Expand All @@ -59,11 +57,10 @@ def test_layout(self):
footer_col = columns[1][2]
assert isinstance(footer_col, Column)

footer_objects = footer_col[0][0]
assert isinstance(footer_objects, Row)
assert isinstance(footer_objects.objects[0], ParamFunction)
assert footer_col[0] == "Footer Test"
assert footer_col[1] == "Footer 2"

timestamp_pane = footer_col[1]
timestamp_pane = footer_col[2]
assert isinstance(timestamp_pane, HTML)

def test_reactions_link(self):
Expand Down
34 changes: 34 additions & 0 deletions panel/tests/ui/chat/test_chat_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

pytest.importorskip("playwright")

from playwright.sync_api import expect

from panel.chat import ChatMessage
from panel.tests.util import serve_component

pytestmark = pytest.mark.ui


def test_chat_message_dynamic_footer_objects(page):
chat_msg = ChatMessage()
serve_component(page, chat_msg)

footer = page.get_by_text("It works!")
expect(footer).to_have_count(0)

chat_msg.footer_objects = ["It works!"]
footer = page.get_by_text("It works!")
expect(footer).to_have_count(1)


def test_chat_message_dynamic_header_objects(page):
chat_msg = ChatMessage()
serve_component(page, chat_msg)

header = page.get_by_text("It works!")
expect(header).to_have_count(0)

chat_msg.header_objects = ["It works!"]
header = page.get_by_text("It works!")
expect(header).to_have_count(1)
Loading