Skip to content

Commit 27c125e

Browse files
zimegClaude
andcommitted
feat(block-kit): add data table block example
Add a DataTable block-kit example (blocks/DataTable.java) demonstrating a data_table block with raw_text, raw_number, and rich_text-capable cells, plus a DataTableTest round-trip test and a README entry. Depends on the DataTableBlock / TableCell model added in slackapi/java-slack-sdk#1613 (not yet released); the block-kit module pins the published slack-api-model, so this compiles once that lands. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent 980b7a3 commit 27c125e

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

‎block-kit/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
1313
- **[Carousel](https://docs.slack.dev/reference/block-kit/blocks/carousel-block)**: Displays related card blocks in a horizontally-scrolling container. [Implementation](./src/main/java/blocks/Carousel.java).
1414
- **[Card](https://docs.slack.dev/reference/block-kit/blocks/card-block)**: Displays content in a card. [Implementation](./src/main/java/blocks/Card.java).
1515
- **[Context](https://docs.slack.dev/reference/block-kit/blocks/context-block)**: Provides contextual info, which can include both images and text. [Implementation](./src/main/java/blocks/Context.java).
16+
- **[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/main/java/blocks/DataTable.java).
1617
- **[Divider](https://docs.slack.dev/reference/block-kit/blocks/divider-block)**: Visually separates pieces of info inside of a message. [Implementation](./src/main/java/blocks/Divider.java).
1718
- **[File](https://docs.slack.dev/reference/block-kit/blocks/file-block)**: Displays info about remote files. [Implementation](./src/main/java/blocks/File.java).
1819
- **[Header](https://docs.slack.dev/reference/block-kit/blocks/header-block)**: Displays a larger-sized text. [Implementation](./src/main/java/blocks/Header.java).
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package blocks;
2+
3+
import com.slack.api.model.block.Blocks;
4+
import com.slack.api.model.block.DataTableBlock;
5+
import com.slack.api.model.block.composition.RawNumberObject;
6+
import com.slack.api.model.block.composition.RawTextObject;
7+
import java.util.List;
8+
9+
/**
10+
* Displays rich tables that support pagination, sorting, filtering, and interactivity.
11+
* {@link https://docs.slack.dev/reference/block-kit/blocks/data-table-block/}
12+
*/
13+
public class DataTable {
14+
/**
15+
* A data table pairing text labels with numeric values.
16+
*/
17+
public static DataTableBlock example01() {
18+
DataTableBlock block = Blocks.dataTable(t -> t.caption("Quarterly widget report")
19+
.pageSize(10)
20+
.rowHeaderColumnIndex(0)
21+
.rows(List.of(
22+
List.of(
23+
RawTextObject.builder().text("Item").build(),
24+
RawTextObject.builder().text("Count").build()),
25+
List.of(
26+
RawTextObject.builder().text("Widgets").build(),
27+
RawNumberObject.builder().value(42.0).text("42").build()),
28+
List.of(
29+
RawTextObject.builder().text("Gadgets").build(),
30+
RawNumberObject.builder().value(7.0).text("7").build()))));
31+
return block;
32+
}
33+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package blocks;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.google.gson.JsonParser;
6+
import com.slack.api.model.block.DataTableBlock;
7+
import com.slack.api.util.json.GsonFactory;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class DataTableTest {
11+
@Test
12+
public void testExample01() {
13+
DataTableBlock block = DataTable.example01();
14+
String actual = GsonFactory.createSnakeCase().toJson(block);
15+
String expected = """
16+
{
17+
"type": "data_table",
18+
"rows": [
19+
[
20+
{ "type": "raw_text", "text": "Item" },
21+
{ "type": "raw_text", "text": "Count" }
22+
],
23+
[
24+
{ "type": "raw_text", "text": "Widgets" },
25+
{ "type": "raw_number", "value": 42.0, "text": "42" }
26+
],
27+
[
28+
{ "type": "raw_text", "text": "Gadgets" },
29+
{ "type": "raw_number", "value": 7.0, "text": "7" }
30+
]
31+
],
32+
"caption": "Quarterly widget report",
33+
"page_size": 10,
34+
"row_header_column_index": 0
35+
}
36+
""";
37+
assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual));
38+
}
39+
}

0 commit comments

Comments
 (0)