Skip to content

Commit

Permalink
Actually pass card_params into ChatFeed's internal Card (#6154)
Browse files Browse the repository at this point in the history
* Add expected behavior for card param

* Allow dynamic updates
  • Loading branch information
ahuang11 committed Jan 9, 2024
1 parent 488d53c commit 2e80565
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions panel/chat/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -274,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(
Expand Down
10 changes: 10 additions & 0 deletions panel/tests/chat/test_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def test_hide_header(self, chat_feed):
chat_feed.header = ""
assert chat_feed._card.hide_header

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

def test_send(self, chat_feed):
message = chat_feed.send("Message")
wait_until(lambda: len(chat_feed.objects) == 1)
Expand Down

0 comments on commit 2e80565

Please sign in to comment.