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

Actually pass card_params into ChatFeed's internal Card #6154

Merged
merged 2 commits into from
Jan 9, 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
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