diff --git a/block-kit/README.md b/block-kit/README.md index ee77ff0..bb475f8 100644 --- a/block-kit/README.md +++ b/block-kit/README.md @@ -9,6 +9,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes ### Blocks - **[Actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block)**: Holds multiple interactive elements. [Implementation](./src/blocks/actions.py). +- **[Container](https://docs.slack.dev/reference/block-kit/blocks/container-block)**: Groups child blocks together in a configurable container. [Implementation](./src/blocks/container.py). - **[Context](https://docs.slack.dev/reference/block-kit/blocks/context-block)**: Provides contextual info, which can include both images and text. [Implementation](./src/blocks/context.py). - **[Context actions](https://docs.slack.dev/reference/block-kit/blocks/context-actions-block)**: Displays actions as contextual info, which can include both feedback buttons and icon buttons. [Implementation](./src/blocks/context_actions.py). - **[Divider](https://docs.slack.dev/reference/block-kit/blocks/divider-block)**: Visually separates pieces of info inside of a message. [Implementation](./src/blocks/divider.py). diff --git a/block-kit/src/blocks/container.py b/block-kit/src/blocks/container.py new file mode 100644 index 0000000..55290f6 --- /dev/null +++ b/block-kit/src/blocks/container.py @@ -0,0 +1,61 @@ +from slack_sdk.models.blocks import ( + ActionsBlock, + ContainerBlock, + ContextBlock, + DividerBlock, + SectionBlock, +) +from slack_sdk.models.blocks.basic_components import MarkdownTextObject +from slack_sdk.models.blocks.block_elements import ButtonElement + + +def example01() -> ContainerBlock: + """ + A general-purpose wrapper for grouping child blocks together, with a configurable size. + https://docs.slack.dev/reference/block-kit/blocks/container-block/ + + A collapsible container grouping a bulk-update summary out of section, + divider, context, and actions child blocks. + """ + block = ContainerBlock( + block_id="bkb_container_bulk_update", + title="Bulk update: 2 records selected", + subtitle="Review changes before confirming", + is_collapsible=True, + child_blocks=[ + SectionBlock( + block_id="record-row-1", + text=MarkdownTextObject( + text="*DCW-1024*\nStatus: Open → Closed\nAssignee: @princessdonut → @carl" + ), + ), + DividerBlock(block_id="bulk-div-1"), + SectionBlock( + block_id="record-row-2", + text=MarkdownTextObject( + text="*DCW-1025*\nStatus: In Progress → Closed\nAssignee: @mordecai → @carl" + ), + ), + DividerBlock(block_id="bulk-div-2"), + ContextBlock( + block_id="bulk-status-bar", + elements=[ + MarkdownTextObject( + text=":white_check_mark: 2 records will be updated • Status → Closed • Assignee → @carl" + ) + ], + ), + ActionsBlock( + block_id="bulk-actions", + elements=[ + ButtonElement( + text="Confirm All", + action_id="bulk_confirm", + style="primary", + ), + ButtonElement(text="Cancel", action_id="bulk_cancel"), + ], + ), + ], + ) + return block diff --git a/block-kit/tests/blocks/test_container.py b/block-kit/tests/blocks/test_container.py new file mode 100644 index 0000000..7bdc80a --- /dev/null +++ b/block-kit/tests/blocks/test_container.py @@ -0,0 +1,75 @@ +import json + +from src.blocks import container + + +def test_example01(): + block = container.example01() + actual = block.to_dict() + expected = { + "type": "container", + "block_id": "bkb_container_bulk_update", + "title": { + "type": "plain_text", + "text": "Bulk update: 2 records selected", + }, + "subtitle": { + "type": "plain_text", + "text": "Review changes before confirming", + }, + "is_collapsible": True, + "child_blocks": [ + { + "type": "section", + "block_id": "record-row-1", + "text": { + "type": "mrkdwn", + "text": "*DCW-1024*\nStatus: Open → Closed\nAssignee: @princessdonut → @carl", + }, + }, + {"type": "divider", "block_id": "bulk-div-1"}, + { + "type": "section", + "block_id": "record-row-2", + "text": { + "type": "mrkdwn", + "text": "*DCW-1025*\nStatus: In Progress → Closed\nAssignee: @mordecai → @carl", + }, + }, + {"type": "divider", "block_id": "bulk-div-2"}, + { + "type": "context", + "block_id": "bulk-status-bar", + "elements": [ + { + "type": "mrkdwn", + "text": ":white_check_mark: 2 records will be updated • Status → Closed • Assignee → @carl", + } + ], + }, + { + "type": "actions", + "block_id": "bulk-actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Confirm All", + }, + "action_id": "bulk_confirm", + "style": "primary", + }, + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Cancel", + }, + "action_id": "bulk_cancel", + }, + ], + }, + ], + } + assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)