From ac17b765d6abcd253649db52aaeabe90be9afeb2 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Thu, 4 Jan 2024 00:58:55 -0800 Subject: [PATCH 1/2] Add expected behavior for card param --- panel/chat/feed.py | 15 ++++++++++----- panel/tests/chat/test_feed.py | 12 ++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/panel/chat/feed.py b/panel/chat/feed.py index ffa45b44cc..7ba2b621d7 100644 --- a/panel/chat/feed.py +++ b/panel/chat/feed.py @@ -240,10 +240,8 @@ def __init__(self, *objects, **params): stylesheets=self._stylesheets, **linked_params ) - self.link(self._chat_log, objects='objects', bidirectional=True) - # we have a card for the title - self._card = Card( - self._chat_log, VSpacer(), + card_params = linked_params.copy() + card_params.update( margin=self.param.margin, align=self.param.align, header=self.header, @@ -257,7 +255,14 @@ def __init__(self, *objects, **params): title_css_classes=["chat-feed-title"], styles={"padding": "0px"}, stylesheets=self._stylesheets + self.param.stylesheets.rx(), - **linked_params + ) + card_params.update(self.card_params) + self.link(self._chat_log, objects='objects', bidirectional=True) + # we have a card for the title + self._card = Card( + self._chat_log, + VSpacer(), + **card_params ) # handle async callbacks using this trick diff --git a/panel/tests/chat/test_feed.py b/panel/tests/chat/test_feed.py index 2c44c315d3..20ff5403fa 100644 --- a/panel/tests/chat/test_feed.py +++ b/panel/tests/chat/test_feed.py @@ -41,6 +41,18 @@ def test_hide_header(self, chat_feed): chat_feed.header = "" assert chat_feed._card.hide_header + def test_card_params(self): + chat_feed = ChatFeed( + card_params={ + "header_background": "red", + "header": "Test", + "hide_header": False + }, + ) + assert chat_feed._card.header_background == "red" + assert chat_feed._card.header == "Test" + assert not chat_feed._card.hide_header + def test_send(self, chat_feed): message = chat_feed.send("Message") wait_until(lambda: len(chat_feed.objects) == 1) From ed8ef0f1ab953ddd8a766bf8c057df4581f9923f Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Thu, 4 Jan 2024 10:28:51 -0800 Subject: [PATCH 2/2] Allow dynamic updates --- panel/chat/feed.py | 4 ++++ panel/tests/chat/test_feed.py | 14 ++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/panel/chat/feed.py b/panel/chat/feed.py index 7ba2b621d7..835b60ac20 100644 --- a/panel/chat/feed.py +++ b/panel/chat/feed.py @@ -279,6 +279,10 @@ def _cleanup(self, root: Model | None = None) -> None: self._card._cleanup(root) super()._cleanup(root) + @param.depends("card_params", watch=True) + def _update_card_params(self): + self._card.param.update(**self.card_params) + @param.depends("placeholder_text", watch=True, on_init=True) def _update_placeholder(self): loading_avatar = SVG( diff --git a/panel/tests/chat/test_feed.py b/panel/tests/chat/test_feed.py index 20ff5403fa..eab16c9b60 100644 --- a/panel/tests/chat/test_feed.py +++ b/panel/tests/chat/test_feed.py @@ -41,14 +41,12 @@ def test_hide_header(self, chat_feed): chat_feed.header = "" assert chat_feed._card.hide_header - def test_card_params(self): - chat_feed = ChatFeed( - card_params={ - "header_background": "red", - "header": "Test", - "hide_header": False - }, - ) + def test_card_params(self, chat_feed): + chat_feed.card_params = { + "header_background": "red", + "header": "Test", + "hide_header": False + } assert chat_feed._card.header_background == "red" assert chat_feed._card.header == "Test" assert not chat_feed._card.hide_header