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

Add RichTextInputElement to slack_sdk.models #1406

Merged
merged 1 commit into from
Oct 3, 2023
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
2 changes: 2 additions & 0 deletions slack_sdk/models/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .block_elements import InteractiveElement
from .block_elements import LinkButtonElement
from .block_elements import OverflowMenuElement
from .block_elements import RichTextInputElement
from .block_elements import PlainTextInputElement
from .block_elements import EmailInputElement
from .block_elements import UrlInputElement
Expand Down Expand Up @@ -81,6 +82,7 @@
"InteractiveElement",
"LinkButtonElement",
"OverflowMenuElement",
"RichTextInputElement",
"PlainTextInputElement",
"EmailInputElement",
"UrlInputElement",
Expand Down
41 changes: 40 additions & 1 deletion slack_sdk/models/blocks/block_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import warnings
from abc import ABCMeta
from typing import Iterator, List, Optional, Set, Type, Union, Sequence
from typing import Iterator, List, Optional, Set, Type, Union, Sequence, Dict, Any

from slack_sdk.models import show_unknown_key_warning
from slack_sdk.models.basic_objects import (
Expand Down Expand Up @@ -1331,6 +1331,45 @@ def __init__(
self.max_selected_items = max_selected_items


# -------------------------------------------------
# Rich Text Input Element
# -------------------------------------------------


class RichTextInputElement(InputInteractiveElement):
type = "rich_text_input"

@property
def attributes(self) -> Set[str]:
return super().attributes.union(
{
"initial_value",
"dispatch_action_config",
}
)

def __init__(
self,
*,
action_id: Optional[str] = None,
placeholder: Optional[Union[str, dict, TextObject]] = None,
initial_value: Optional[Dict[str, Any]] = None, # TODO: Add rich_text block class and its element classes
dispatch_action_config: Optional[Union[dict, DispatchActionConfig]] = None,
focus_on_load: Optional[bool] = None,
**others: dict,
):
super().__init__(
type=self.type,
action_id=action_id,
placeholder=TextObject.parse(placeholder, PlainTextObject.type),
focus_on_load=focus_on_load,
)
show_unknown_key_warning(self, others)

self.initial_value = initial_value
self.dispatch_action_config = dispatch_action_config


# -------------------------------------------------
# Plain Text Input Element
# -------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions tests/slack_sdk/models/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
NumberInputElement,
UrlInputElement,
WorkflowButtonElement,
RichTextInputElement,
)
from . import STRING_3001_CHARS, STRING_301_CHARS

Expand Down Expand Up @@ -1013,6 +1014,26 @@ def test_document(self):
# -------------------------------------------------


class RichTextInputElementTests(unittest.TestCase):
def test_simple(self):
input = {
"type": "rich_text_input",
"action_id": "rich_input",
"placeholder": {"type": "plain_text", "text": "Enter some plain text"},
}
self.assertDictEqual(input, RichTextInputElement(**input).to_dict())

def test_document(self):
input = {
"type": "rich_text_input",
"action_id": "rich_text_input-action",
"dispatch_action_config": {"trigger_actions_on": ["on_character_entered"]},
"focus_on_load": True,
"placeholder": {"type": "plain_text", "text": "Enter text"},
}
self.assertDictEqual(input, RichTextInputElement(**input).to_dict())


class PlainTextInputElementTests(unittest.TestCase):
def test_document_1(self):
input = {
Expand Down