Skip to content

Commit

Permalink
Add RichTextInputElement to slack_sdk.models (#1406)
Browse files Browse the repository at this point in the history
seratch authored Oct 3, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 398923a commit c28a813
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions slack_sdk/models/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -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
@@ -81,6 +82,7 @@
"InteractiveElement",
"LinkButtonElement",
"OverflowMenuElement",
"RichTextInputElement",
"PlainTextInputElement",
"EmailInputElement",
"UrlInputElement",
41 changes: 40 additions & 1 deletion slack_sdk/models/blocks/block_elements.py
Original file line number Diff line number Diff line change
@@ -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 (
@@ -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
# -------------------------------------------------
21 changes: 21 additions & 0 deletions tests/slack_sdk/models/test_elements.py
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
NumberInputElement,
UrlInputElement,
WorkflowButtonElement,
RichTextInputElement,
)
from . import STRING_3001_CHARS, STRING_301_CHARS

@@ -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 = {

0 comments on commit c28a813

Please sign in to comment.