diff --git a/block-kit/README.md b/block-kit/README.md index ee77ff0..eba5e78 100644 --- a/block-kit/README.md +++ b/block-kit/README.md @@ -11,6 +11,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes - **[Actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block)**: Holds multiple interactive elements. [Implementation](./src/blocks/actions.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). +- **[Data table](https://docs.slack.dev/reference/block-kit/blocks/data-table-block)**: Displays data arranged in rows and columns with built-in pagination. [Implementation](./src/blocks/data_table.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). - **[File](https://docs.slack.dev/reference/block-kit/blocks/file-block)**: Displays info about remote files. [Implementation](./src/blocks/file.py). - **[Header](https://docs.slack.dev/reference/block-kit/blocks/header-block)**: Displays a larger-sized text. [Implementation](./src/blocks/header.py). diff --git a/block-kit/src/blocks/data_table.py b/block-kit/src/blocks/data_table.py new file mode 100644 index 0000000..9cc15fb --- /dev/null +++ b/block-kit/src/blocks/data_table.py @@ -0,0 +1,79 @@ +from slack_sdk.models.blocks import DataTableBlock + + +def example01() -> DataTableBlock: + """ + Displays rich tables that support pagination, sorting, filtering, and interactivity. + https://docs.slack.dev/reference/block-kit/blocks/data-table-block/ + + A data table of departments with raw text and rich text cells. + """ + block = DataTableBlock( + caption="A Fabulous Table", + rows=[ + [ + {"type": "raw_text", "text": "Name"}, + {"type": "raw_text", "text": "Department"}, + {"type": "raw_text", "text": "Badge"}, + ], + [ + {"type": "raw_text", "text": "Data Refinement Department"}, + {"type": "raw_text", "text": "MDR"}, + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Blue", + "style": {"bold": True}, + } + ], + } + ], + }, + ], + [ + {"type": "raw_text", "text": "Art Sourcing Department"}, + {"type": "raw_text", "text": "O&D"}, + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + {"type": "text", "text": "Green"}, + { + "type": "text", + "text": "review", + "style": {"italic": True}, + }, + ], + } + ], + }, + ], + [ + {"type": "raw_text", "text": "Wellness Department"}, + {"type": "raw_text", "text": "Wellness Center"}, + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Limited", + "style": {"bold": True}, + } + ], + } + ], + }, + ], + ], + ) + return block diff --git a/block-kit/tests/blocks/test_data_table.py b/block-kit/tests/blocks/test_data_table.py new file mode 100644 index 0000000..9752d4e --- /dev/null +++ b/block-kit/tests/blocks/test_data_table.py @@ -0,0 +1,78 @@ +import json + +from src.blocks import data_table + + +def test_example01(): + block = data_table.example01() + actual = block.to_dict() + expected = { + "type": "data_table", + "caption": "A Fabulous Table", + "rows": [ + [ + {"type": "raw_text", "text": "Name"}, + {"type": "raw_text", "text": "Department"}, + {"type": "raw_text", "text": "Badge"}, + ], + [ + {"type": "raw_text", "text": "Data Refinement Department"}, + {"type": "raw_text", "text": "MDR"}, + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Blue", + "style": {"bold": True}, + } + ], + } + ], + }, + ], + [ + {"type": "raw_text", "text": "Art Sourcing Department"}, + {"type": "raw_text", "text": "O&D"}, + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + {"type": "text", "text": "Green"}, + { + "type": "text", + "text": "review", + "style": {"italic": True}, + }, + ], + } + ], + }, + ], + [ + {"type": "raw_text", "text": "Wellness Department"}, + {"type": "raw_text", "text": "Wellness Center"}, + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Limited", + "style": {"bold": True}, + } + ], + } + ], + }, + ], + ], + } + assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)