diff --git a/block-kit/README.md b/block-kit/README.md index ee77ff0..d4686ee 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 rich tables that support pagination, sorting, filtering, and interactivity. [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..1d71367 --- /dev/null +++ b/block-kit/src/blocks/data_table.py @@ -0,0 +1,76 @@ +from slack_sdk.models.blocks import ( + DataTableBlock, + RawTextObject, + RichTextBlock, + RichTextElementParts, + RichTextSectionElement, +) + + +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 sample data table block. + """ + block = DataTableBlock( + caption="A Fabulous Table", + rows=[ + [ + RawTextObject(text="Name"), + RawTextObject(text="Department"), + RawTextObject(text="Badge"), + ], + [ + RawTextObject(text="Data Refinement Department"), + RawTextObject(text="MDR"), + RichTextBlock( + elements=[ + RichTextSectionElement( + elements=[ + RichTextElementParts.Text( + text="Blue", + style=RichTextElementParts.TextStyle(bold=True), + ), + ], + ), + ], + ), + ], + [ + RawTextObject(text="Art Sourcing Department"), + RawTextObject(text="O&D"), + RichTextBlock( + elements=[ + RichTextSectionElement( + elements=[ + RichTextElementParts.Text(text="Green"), + RichTextElementParts.Text( + text="review", + style=RichTextElementParts.TextStyle(italic=True), + ), + ], + ), + ], + ), + ], + [ + RawTextObject(text="Wellness Department"), + RawTextObject(text="Wellness Center"), + RichTextBlock( + elements=[ + RichTextSectionElement( + elements=[ + RichTextElementParts.Text( + text="Limited", + style=RichTextElementParts.TextStyle(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..bb78b1e --- /dev/null +++ b/block-kit/tests/blocks/test_data_table.py @@ -0,0 +1,114 @@ +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)