Skip to content
Draft
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
1 change: 1 addition & 0 deletions block-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
79 changes: 79 additions & 0 deletions block-kit/src/blocks/data_table.py
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions block-kit/tests/blocks/test_data_table.py
Original file line number Diff line number Diff line change
@@ -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)
Loading