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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
value = ContextActionsBlock.class,
name = ContextActionsBlock.TYPE
),
@JsonSubTypes.Type(value = Table.class, name = Table.TYPE),
@JsonSubTypes.Type(value = DataTable.class, name = DataTable.TYPE),
}
)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ public enum BlockElementLengthLimits {
MAX_OPTION_GROUP_LABEL_LENGTH(75),
MAX_OPTION_VALUE_LENGTH(75),
MAX_CHECKBOXES_NUMBER(10),
MAX_RADIO_BUTTONS_NUMBER(10);
MAX_RADIO_BUTTONS_NUMBER(10),
MAX_TABLE_ROWS(100),
MAX_TABLE_COLUMNS(20),
MAX_TABLE_BLOCK_ID_LENGTH(255),
MIN_DATA_TABLE_ROWS(2),
MAX_DATA_TABLE_PAGE_SIZE(100);

private final int limit;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.hubspot.slack.client.models.blocks;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.blocks.table.DataTableCell;
import com.hubspot.slack.client.models.blocks.table.RawTextTableCell;
import java.util.Optional;
import org.immutables.value.Value;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface DataTableIF extends Block {
String TYPE = "data_table";

@Override
@Value.Derived
default String getType() {
return TYPE;
}

@Value.Parameter(order = 1)
String getCaption();

@Value.Parameter(order = 2)
ImmutableList<ImmutableList<DataTableCell>> getRows();

@JsonProperty("page_size")
Optional<Integer> getPageSize();
Comment thread
VictorHLi404 marked this conversation as resolved.

@JsonProperty("row_header_column_index")
Optional<Integer> getRowHeaderColumnIndex();

@Check
default void check() {
Preconditions.checkState(
getRows().size() >= BlockElementLengthLimits.MIN_DATA_TABLE_ROWS.getLimit(),
"A data_table block must have at least %s rows (1 header + 1 body)",
BlockElementLengthLimits.MIN_DATA_TABLE_ROWS.getLimit()
);
Preconditions.checkState(
getRows().size() <= BlockElementLengthLimits.MAX_TABLE_ROWS.getLimit(),
"A data_table block cannot have more than %s rows",
BlockElementLengthLimits.MAX_TABLE_ROWS.getLimit()
);
getRows()
.forEach(row ->
Preconditions.checkState(
row.size() <= BlockElementLengthLimits.MAX_TABLE_COLUMNS.getLimit(),
"A data_table row cannot have more than %s columns",
BlockElementLengthLimits.MAX_TABLE_COLUMNS.getLimit()
)
);
int columnCount = getRows().get(0).size();
getRows()
.forEach(row ->
Preconditions.checkState(
row.size() == columnCount,
"All rows in a data_table block must have the same number of columns"
)
);
getRows()
.get(0)
.forEach(cell ->
Preconditions.checkState(
cell instanceof RawTextTableCell,
"Header row cells must be of type raw_text"
)
);
getPageSize()
.ifPresent(pageSize ->
Preconditions.checkState(
pageSize >= 1 &&
pageSize <= BlockElementLengthLimits.MAX_DATA_TABLE_PAGE_SIZE.getLimit(),
"page_size must be between 1 and %s",
BlockElementLengthLimits.MAX_DATA_TABLE_PAGE_SIZE.getLimit()
)
);
getBlockId()
.ifPresent(blockId ->
Preconditions.checkState(
blockId.length() <=
BlockElementLengthLimits.MAX_TABLE_BLOCK_ID_LENGTH.getLimit(),
"block_id cannot exceed %s characters",
BlockElementLengthLimits.MAX_TABLE_BLOCK_ID_LENGTH.getLimit()
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.hubspot.slack.client.models.blocks;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.blocks.table.TableCell;
import com.hubspot.slack.client.models.blocks.table.TableColumnSetting;
import org.immutables.value.Value;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface TableIF extends Block {
String TYPE = "table";

@Override
@Value.Derived
default String getType() {
return TYPE;
}

@Value.Parameter
ImmutableList<ImmutableList<TableCell>> getRows();

ImmutableList<TableColumnSetting> getColumnSettings();

@Check
default void check() {
Preconditions.checkState(
getRows().size() <= BlockElementLengthLimits.MAX_TABLE_ROWS.getLimit(),
"A table block cannot have more than %s rows",
BlockElementLengthLimits.MAX_TABLE_ROWS.getLimit()
);
getRows()
.forEach(row ->
Preconditions.checkState(
row.size() <= BlockElementLengthLimits.MAX_TABLE_COLUMNS.getLimit(),
"A table row cannot have more than %s cells",
BlockElementLengthLimits.MAX_TABLE_COLUMNS.getLimit()
)
);
Preconditions.checkState(
getColumnSettings().size() <= BlockElementLengthLimits.MAX_TABLE_COLUMNS.getLimit(),
"A table block cannot have more than %s column settings",
BlockElementLengthLimits.MAX_TABLE_COLUMNS.getLimit()
);
getBlockId()
.ifPresent(blockId ->
Preconditions.checkState(
blockId.length() <=
BlockElementLengthLimits.MAX_TABLE_BLOCK_ID_LENGTH.getLimit(),
"block_id cannot exceed %s characters",
BlockElementLengthLimits.MAX_TABLE_BLOCK_ID_LENGTH.getLimit()
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hubspot.slack.client.models.blocks.table;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type",
defaultImpl = UnknownTableCell.class
)
@JsonSubTypes(
{
@JsonSubTypes.Type(value = RawTextTableCell.class, name = RawTextTableCell.TYPE),
@JsonSubTypes.Type(value = RawNumberTableCell.class, name = RawNumberTableCell.TYPE),
@JsonSubTypes.Type(value = RichTextTableCell.class, name = RichTextTableCell.TYPE),
}
)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface DataTableCell extends TableCell {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hubspot.slack.client.models.blocks.table;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import org.immutables.value.Value;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface RawNumberTableCellIF extends DataTableCell {
String TYPE = "raw_number";

@Override
@Value.Derived
default String getType() {
return TYPE;
}

@Value.Parameter(order = 1)
double getValue();

@Value.Parameter(order = 2)
String getText();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.hubspot.slack.client.models.blocks.table;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import org.immutables.value.Value;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface RawTextTableCellIF extends DataTableCell {
String TYPE = "raw_text";

@Override
@Value.Derived
default String getType() {
return TYPE;
}

@Value.Parameter
String getText();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hubspot.slack.client.models.blocks.table;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.google.common.collect.ImmutableList;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.blocks.elements.richtextelements.RichTextObject;
import org.immutables.value.Value;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface RichTextTableCellIF extends DataTableCell {
String TYPE = "rich_text";

@Override
@Value.Derived
default String getType() {
return TYPE;
}

@JsonProperty("elements")
ImmutableList<RichTextObject> getElements();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.hubspot.slack.client.models.blocks.table;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type",
defaultImpl = UnknownTableCell.class
)
@JsonSubTypes(
{
@JsonSubTypes.Type(value = RawTextTableCell.class, name = RawTextTableCell.TYPE),
@JsonSubTypes.Type(value = RichTextTableCell.class, name = RichTextTableCell.TYPE),

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.

Could you please check if we shouldn't include RawNumberTableCellIF here as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In documentation it says that Tables supports RawNumberTableCell, but in practice / what's actually implemented it doesn't support it. Not sure where the right place to raise that issue is to Slack, but I've omitted RawNumberTableCell here because of that.

}
)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface TableCell {
String getType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hubspot.slack.client.models.blocks.table;

import com.fasterxml.jackson.annotation.JsonValue;

public enum TableColumnAlign {
LEFT("left"),
CENTER("center"),
RIGHT("right");

private final String value;

TableColumnAlign(String value) {
this.value = value;
}

@JsonValue
public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hubspot.slack.client.models.blocks.table;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import java.util.Optional;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_ABSENT)
public interface TableColumnSettingIF {
Optional<TableColumnAlign> getAlign();

@JsonProperty("is_wrapped")
Optional<Boolean> isWrapped();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.hubspot.slack.client.models.blocks.table;

public class UnknownTableCell implements DataTableCell {

public static final String TYPE = "unknown";

protected UnknownTableCell() {}

@Override
public String getType() {
return TYPE;
}
}
Loading