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 @@ -15,6 +15,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
- **[Container](https://docs.slack.dev/reference/block-kit/blocks/container-block)**: A general-purpose wrapper for grouping child blocks together, with a configurable size. [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).
- **[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).
Expand Down
76 changes: 76 additions & 0 deletions block-kit/src/blocks/data_table.py
Original file line number Diff line number Diff line change
@@ -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
114 changes: 114 additions & 0 deletions block-kit/tests/blocks/test_data_table.py
Original file line number Diff line number Diff line change
@@ -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)
Loading