Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add block elements for email_text_input and url_text_input #1140

Merged
merged 4 commits into from
Dec 10, 2022
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
8 changes: 8 additions & 0 deletions block_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (b *InputBlock) UnmarshalJSON(data []byte) error {
e = &TimePickerBlockElement{}
case "plain_text_input":
e = &PlainTextInputBlockElement{}
case "email_text_input":
e = &EmailTextInputBlockElement{}
case "url_text_input":
e = &URLTextInputBlockElement{}
case "static_select", "external_select", "users_select", "conversations_select", "channels_select":
e = &SelectBlockElement{}
case "multi_static_select", "multi_external_select", "multi_users_select", "multi_conversations_select", "multi_channels_select":
Expand Down Expand Up @@ -188,6 +192,10 @@ func (b *BlockElements) UnmarshalJSON(data []byte) error {
blockElement = &TimePickerBlockElement{}
case "plain_text_input":
blockElement = &PlainTextInputBlockElement{}
case "email_text_input":
blockElement = &EmailTextInputBlockElement{}
case "url_text_input":
blockElement = &URLTextInputBlockElement{}
case "checkboxes":
blockElement = &CheckboxGroupsBlockElement{}
case "radio_buttons":
Expand Down
60 changes: 60 additions & 0 deletions block_element.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
METTimepicker MessageElementType = "timepicker"
METPlainTextInput MessageElementType = "plain_text_input"
METRadioButtons MessageElementType = "radio_buttons"
METEmailTextInput MessageElementType = "email_text_input"
METURLTextInput MessageElementType = "url_text_input"
METNumber MessageElementType = "number_input"

MixedElementImage MixedElementType = "mixed_image"
Expand Down Expand Up @@ -390,6 +392,64 @@ func NewTimePickerBlockElement(actionID string) *TimePickerBlockElement {
}
}

// EmailTextInputBlockElement creates a field where a user can enter email
// data.
// email-text-input elements are currently only available in modals.
//
// More Information: https://api.slack.com/reference/block-kit/block-elements#email
type EmailTextInputBlockElement struct {
Type MessageElementType `json:"type"`
ActionID string `json:"action_id,omitempty"`
Placeholder *TextBlockObject `json:"placeholder,omitempty"`
InitialValue string `json:"initial_value,omitempty"`
DispatchActionConfig *DispatchActionConfig `json:"dispatch_action_config,omitempty"`
FocusOnLoad bool `json:"focus_on_load,omitempty"`
}

// ElementType returns the type of the Element
func (s EmailTextInputBlockElement) ElementType() MessageElementType {
return s.Type
}

// NewEmailTextInputBlockElement returns an instance of a plain-text input
// element
func NewEmailTextInputBlockElement(placeholder *TextBlockObject, actionID string) *EmailTextInputBlockElement {
return &EmailTextInputBlockElement{
Type: METEmailTextInput,
ActionID: actionID,
Placeholder: placeholder,
}
}

// URLTextInputBlockElement creates a field where a user can enter url data.
//
// url-text-input elements are currently only available in modals.
//
// More Information: https://api.slack.com/reference/block-kit/block-elements#url
type URLTextInputBlockElement struct {
ameliagapin marked this conversation as resolved.
Show resolved Hide resolved
Type MessageElementType `json:"type"`
ActionID string `json:"action_id,omitempty"`
Placeholder *TextBlockObject `json:"placeholder,omitempty"`
InitialValue string `json:"initial_value,omitempty"`
DispatchActionConfig *DispatchActionConfig `json:"dispatch_action_config,omitempty"`
FocusOnLoad bool `json:"focus_on_load,omitempty"`
}

// ElementType returns the type of the Element
func (s URLTextInputBlockElement) ElementType() MessageElementType {
return s.Type
}

// NewURLTextInputBlockElement returns an instance of a plain-text input
// element
func NewURLTextInputBlockElement(placeholder *TextBlockObject, actionID string) *URLTextInputBlockElement {
return &URLTextInputBlockElement{
Type: METURLTextInput,
ActionID: actionID,
Placeholder: placeholder,
}
}

// PlainTextInputBlockElement creates a field where a user can enter freeform
// data.
// Plain-text input elements are currently only available in modals.
Expand Down
14 changes: 14 additions & 0 deletions block_element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ func TestNewPlainTextInputBlockElement(t *testing.T) {

}

func TestNewEmailTextInputBlockElement(t *testing.T) {
emailTextInputElement := NewEmailTextInputBlockElement(nil, "example@example.com")

assert.Equal(t, string(emailTextInputElement.Type), "email_text_input")
assert.Equal(t, emailTextInputElement.ActionID, "example@example.com")
}

func TestNewURLTextInputBlockElement(t *testing.T) {
urlTextInputElement := NewURLTextInputBlockElement(nil, "www.example.com")

assert.Equal(t, string(urlTextInputElement.Type), "url_text_input")
assert.Equal(t, urlTextInputElement.ActionID, "www.example.com")
}

func TestNewCheckboxGroupsBlockElement(t *testing.T) {
// Build Text Objects associated with each option
checkBoxOptionTextOne := NewTextBlockObject("plain_text", "Check One", false, false)
Expand Down