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

Raise on ChatReactionIcons instance in ChatFeed.message_params #6814

Merged
merged 2 commits into from
May 8, 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
12 changes: 11 additions & 1 deletion panel/chat/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from ..layout.card import Card
from ..layout.spacer import VSpacer
from ..pane.image import SVG
from .icon import ChatReactionIcons
from .message import ChatMessage

if TYPE_CHECKING:
Expand Down Expand Up @@ -213,7 +214,7 @@ def __init__(self, *objects, **params):
super().__init__(*objects, **params)

if self.help_text:
self.objects = [ChatMessage(self.help_text, user="Help"), *self.objects]
self.objects = [ChatMessage(self.help_text, user="Help", **message_params), *self.objects]

# instantiate the card's column
linked_params = dict(
Expand Down Expand Up @@ -291,6 +292,15 @@ def _cleanup(self, root: Model | None = None) -> None:
self._card._cleanup(root)
super()._cleanup(root)

@param.depends("message_params", watch=True, on_init=True)
def _validate_message_params(self):
reaction_icons = self.message_params.get("reaction_icons")
if isinstance(reaction_icons, ChatReactionIcons):
raise ValueError(
"Cannot pass a ChatReactionIcons instance to message_params; "
"use a dict of the options instead."
)

@param.depends("load_buffer", "auto_scroll_limit", "scroll_button_threshold", watch=True)
def _update_chat_log_params(self):
self._chat_log.load_buffer = self.load_buffer
Expand Down
6 changes: 6 additions & 0 deletions panel/tests/chat/test_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from panel.chat.feed import ChatFeed
from panel.chat.icon import ChatReactionIcons
from panel.chat.message import ChatMessage
from panel.layout import Column, Row
from panel.pane.image import Image
Expand Down Expand Up @@ -442,6 +443,11 @@ def test_forward_message_params(self, chat_feed):
assert chat_message.reactions == ["like"]
assert chat_message.reaction_icons.options == {"like": "thumb-up"}

def test_message_params_no_chat_reaction_icons_instance(self, chat_feed):
with pytest.raises(ValueError, match="Cannot pass"):
chat_feed.message_params = {"reaction_icons": ChatReactionIcons(
options={"like": "thumb-up", "dislike": "thumb-down"})}

def test_update_chat_log_params(self, chat_feed):
chat_feed = ChatFeed(load_buffer=5, scroll_button_threshold=5, auto_scroll_limit=5)
assert chat_feed._chat_log.load_buffer == 5
Expand Down
Loading