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
5 changes: 5 additions & 0 deletions .changeset/data-table-block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slack/types": minor
---

feat: add the [`data_table`](https://docs.slack.dev/reference/block-kit/blocks/data-table-block) Block Kit block type (`DataTableBlock`)
29 changes: 29 additions & 0 deletions packages/types/src/block-kit/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
import type {
MrkdwnElement,
PlainTextElement,
RawNumberElement,
RawTextElement,
SlackFileImageObject,
TextObject,
Expand Down Expand Up @@ -61,6 +62,7 @@ export type KnownBlock =
| ContainerBlock
| ContextBlock
| ContextActionsBlock
| DataTableBlock
| DividerBlock
| FileBlock
| HeaderBlock
Expand Down Expand Up @@ -289,6 +291,33 @@ export interface ContextActionsBlock extends Block {
elements: ContextActionsBlockElement[];
}

/**
* @description Displays rich tables that support pagination, sorting, filtering, and interactivity.
* @see {@link https://docs.slack.dev/reference/block-kit/blocks/data-table-block Data table block reference}.
*/
export interface DataTableBlock extends Block {
/**
* @description The type of block. For a data table block, `type` is always `data_table`.
*/
type: 'data_table';
/**
* @description An array consisting of table rows.
*/
rows: (RawTextElement | RawNumberElement | RichTextBlock)[][];
/**
* @description A caption for the table; used as the value for the HTML caption element.
*/
caption: string;
/**
* @description Number of rows per page. Min `1`, Max `100`. Defaults to `5` if omitted.
*/
page_size?: number;
/**
* @description The 0-based index of the column that uniquely identifies each row (the row header). This column is treated as the row's primary identifier for screen readers. Defaults to `0` if omitted.
*/
row_header_column_index?: number;
}

/**
* @description Visually separates pieces of info inside of a message. A content divider, like an `<hr>`, to split up
* different blocks inside of a message. The divider block is nice and neat, requiring only a `type`.
Expand Down
18 changes: 18 additions & 0 deletions packages/types/src/block-kit/composition-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,24 @@ export interface MrkdwnElement {
verbatim?: boolean;
}

/**
* @description Defines an object containing a numeric value.
*/
export interface RawNumberElement {
/**
* @description The formatting to use for this numeric object.
*/
type: 'raw_number';
/**
* @description The numeric value.
*/
value: number;
/**
* @description The text used to display the value. The minimum length is 1 character.
*/
text: string;
}
Comment on lines +176 to +192

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📣 note: This addresses part of #2689 but not for the table block itself!

Comment on lines +179 to +192

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

working great!


/**
* @description Defines an object containing some text.
* @see {@link https://docs.slack.dev/reference/block-kit/composition-objects/text-object Text object reference}.
Expand Down
52 changes: 51 additions & 1 deletion packages/types/test/blocks.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectAssignable, expectError } from 'tsd';
import type { AlertBlock, CardBlock, CarouselBlock, ContainerBlock, KnownBlock } from '../src/index';
import type { AlertBlock, CardBlock, CarouselBlock, ContainerBlock, DataTableBlock, KnownBlock } from '../src/index';

// CardBlock
// -- sad path
Expand Down Expand Up @@ -102,3 +102,53 @@ expectAssignable<KnownBlock>({
title: { type: 'plain_text', text: 'Known' },
child_blocks: [{ type: 'divider' }],
});

// DataTableBlock
// -- sad path
expectError<DataTableBlock>({}); // missing type, rows, and caption
expectError<DataTableBlock>({ type: 'data_table' }); // missing required rows and caption
expectError<DataTableBlock>({
type: 'data_table',
rows: [[{ type: 'raw_text', text: 'Name' }]],
}); // missing required caption
expectError<DataTableBlock>({
type: 'data_table',
caption: 'A list of fruit and their quantities',
}); // missing required rows
// -- happy path
expectAssignable<DataTableBlock>({
type: 'data_table',
caption: 'A list of fruit and their quantities',
rows: [
[
{ type: 'raw_text', text: 'Fruit' },
{ type: 'raw_text', text: 'Quantity' },
],
[
{ type: 'raw_text', text: 'Apples' },
{ type: 'raw_number', value: 12, text: '12' },
],
],
});
expectAssignable<DataTableBlock>({
type: 'data_table',
caption: 'A list of users',
block_id: 'users_table',
page_size: 10,
row_header_column_index: 0,
rows: [
[
{ type: 'raw_text', text: 'User' },
{ type: 'raw_text', text: 'Bio' },
],
[
{ type: 'raw_text', text: 'Mark' },
{ type: 'rich_text', elements: [{ type: 'rich_text_section', elements: [{ type: 'text', text: 'Founder' }] }] },
],
],
});
expectAssignable<KnownBlock>({
type: 'data_table',
caption: 'A minimal table',
rows: [[{ type: 'raw_text', text: 'Header' }], [{ type: 'raw_text', text: 'Value' }]],
});