Skip to content
Merged
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 @@ -21,5 +21,6 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
- **[Plan](https://docs.slack.dev/reference/block-kit/blocks/plan-block)**: Displays a collection of related tasks. [Implementation](./src/blocks/plan.py).
- **[Rich text](https://docs.slack.dev/reference/block-kit/blocks/rich-text-block)**: Displays formatted, structured representation of text. [Implementation](./src/blocks/rich_text.py).
- **[Section](https://docs.slack.dev/reference/block-kit/blocks/section-block)**: Displays text, possibly alongside elements. [Implementation](./src/blocks/section.py).
- **[Table](https://docs.slack.dev/reference/block-kit/blocks/table-block)**: Displays structured information in a table. [Implementation](./src/blocks/table.py).
- **[Task card](https://docs.slack.dev/reference/block-kit/blocks/task-card-block)**: Displays a single task, representing a single action. [Implementation](./src/blocks/task_card.py).
- **[Video](https://docs.slack.dev/reference/block-kit/blocks/video-block)**: Displays an embedded video player. [Implementation](./src/blocks/video.py).
75 changes: 75 additions & 0 deletions block-kit/src/blocks/table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from slack_sdk.models.blocks import TableBlock


def example01() -> TableBlock:
"""
Displays structured information in a table.
https://docs.slack.dev/reference/block-kit/blocks/table-block/

A table with the first column wrapped and the second column right aligned.
"""
block = TableBlock(
column_settings=[
{
"is_wrapped": True,
},
{
"align": "right",
},
],
rows=[
[
{
"type": "raw_text",
"text": "Header A",
},
{
"type": "raw_text",
"text": "Header B",
},
],
[
{
"type": "raw_text",
"text": "Data 1A",
},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "link",
"text": "Data 1B",
"url": "https://slack.com",
}
],
}
],
},
],
[
{
"type": "raw_text",
"text": "Data 2A",
},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "link",
"text": "Data 2B",
"url": "https://slack.com",
}
],
}
],
},
],
],
)
return block
58 changes: 58 additions & 0 deletions block-kit/tests/blocks/test_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import json

from src.blocks import table


def test_example01():
block = table.example01()
actual = block.to_dict()
expected = {
"type": "table",
"column_settings": [
{"is_wrapped": True},
{"align": "right"},
],
"rows": [
[
{"type": "raw_text", "text": "Header A"},
{"type": "raw_text", "text": "Header B"},
],
[
{"type": "raw_text", "text": "Data 1A"},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "link",
"text": "Data 1B",
"url": "https://slack.com",
}
],
}
],
},
],
[
{"type": "raw_text", "text": "Data 2A"},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "link",
"text": "Data 2B",
"url": "https://slack.com",
}
],
}
],
},
],
],
}
assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)