Skip to content

Commit

Permalink
Merge pull request slack-go#1145 from TailrecIO/datetime
Browse files Browse the repository at this point in the history
add datetimepicker component
  • Loading branch information
kanata2 authored Dec 24, 2022
2 parents 342d501 + 68bc30c commit a735199
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type BlockAction struct {
SelectedConversations []string `json:"selected_conversations"`
SelectedDate string `json:"selected_date"`
SelectedTime string `json:"selected_time"`
SelectedDateTime int64 `json:"selected_date_time"`
InitialOption OptionBlockObject `json:"initial_option"`
InitialUser string `json:"initial_user"`
InitialChannel string `json:"initial_channel"`
Expand Down
5 changes: 5 additions & 0 deletions block_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ func (b *InputBlock) UnmarshalJSON(data []byte) error {
e = &DatePickerBlockElement{}
case "timepicker":
e = &TimePickerBlockElement{}
case "datetimepicker":
e = &DateTimePickerBlockElement{}
case "plain_text_input":
e = &PlainTextInputBlockElement{}
case "email_text_input":
Expand Down Expand Up @@ -190,6 +192,8 @@ func (b *BlockElements) UnmarshalJSON(data []byte) error {
blockElement = &DatePickerBlockElement{}
case "timepicker":
blockElement = &TimePickerBlockElement{}
case "datetimepicker":
blockElement = &DateTimePickerBlockElement{}
case "plain_text_input":
blockElement = &PlainTextInputBlockElement{}
case "email_text_input":
Expand Down Expand Up @@ -233,6 +237,7 @@ func (a *Accessory) MarshalJSON() ([]byte, error) {

// UnmarshalJSON implements the Unmarshaller interface for Accessory, so that any JSON
// unmarshalling is delegated and proper type determination can be made before unmarshal
// Note: datetimepicker is not supported in Accessory
func (a *Accessory) UnmarshalJSON(data []byte) error {
var r json.RawMessage

Expand Down
24 changes: 24 additions & 0 deletions block_element.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
METOverflow MessageElementType = "overflow"
METDatepicker MessageElementType = "datepicker"
METTimepicker MessageElementType = "timepicker"
METDatetimepicker MessageElementType = "datetimepicker"
METPlainTextInput MessageElementType = "plain_text_input"
METRadioButtons MessageElementType = "radio_buttons"
METEmailTextInput MessageElementType = "email_text_input"
Expand Down Expand Up @@ -392,6 +393,29 @@ func NewTimePickerBlockElement(actionID string) *TimePickerBlockElement {
}
}

// DateTimePickerBlockElement defines an element that allows the selection of both
// a date and a time of day formatted as a UNIX timestamp.
// More Information: https://api.slack.com/reference/messaging/block-elements#datetimepicker
type DateTimePickerBlockElement struct {
Type MessageElementType `json:"type"`
ActionID string `json:"action_id,omitempty"`
InitialDateTime int64 `json:"initial_date_time,omitempty"`
Confirm *ConfirmationBlockObject `json:"confirm,omitempty"`
}

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

// NewDatePickerBlockElement returns an instance of a datetime picker element
func NewDateTimePickerBlockElement(actionID string) *DateTimePickerBlockElement {
return &DateTimePickerBlockElement{
Type: METDatetimepicker,
ActionID: actionID,
}
}

// EmailTextInputBlockElement creates a field where a user can enter email
// data.
// email-text-input elements are currently only available in modals.
Expand Down
6 changes: 6 additions & 0 deletions block_element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func TestNewTimePickerBlockElement(t *testing.T) {
assert.Equal(t, timepickerElement.ActionID, "test")
}

func TestNewDateTimePickerBlockElement(t *testing.T) {
datetimepickerElement := NewDateTimePickerBlockElement("test")
assert.Equal(t, string(datetimepickerElement.Type), "datetimepicker")
assert.Equal(t, datetimepickerElement.ActionID, "test")
}

func TestNewPlainTextInputBlockElement(t *testing.T) {

plainTextInputElement := NewPlainTextInputBlockElement(nil, "test")
Expand Down

0 comments on commit a735199

Please sign in to comment.