57 lines
2.0 KiB
Go
57 lines
2.0 KiB
Go
package houston
|
|
|
|
import (
|
|
"fmt"
|
|
"houston/entity"
|
|
"houston/pkg/postgres/query"
|
|
"strconv"
|
|
|
|
"github.com/slack-go/slack"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func BuildIncidentUpdateStatusModal(db *gorm.DB, channel slack.Channel) slack.ModalViewRequest {
|
|
titleText := slack.NewTextBlockObject("plain_text", "Set Status of Incident", false, false)
|
|
closeText := slack.NewTextBlockObject("plain_text", "Close", false, false)
|
|
submitText := slack.NewTextBlockObject("plain_text", "Submit", false, false)
|
|
|
|
headerText := slack.NewTextBlockObject("mrkdwn", "Status", false, false)
|
|
headerSection := slack.NewSectionBlock(headerText, nil, nil)
|
|
|
|
incidentStatus, _ := query.FetchAllIncidentStatus(db)
|
|
|
|
incidentStatusBlockOption := createIncidentStatusBlock(incidentStatus)
|
|
|
|
incidentStatusText := slack.NewTextBlockObject(slack.PlainTextType, "Incident Status", false, false)
|
|
incidentStatusOption := slack.NewOptionsSelectBlockElement(slack.OptTypeStatic, nil, "incident_status_modal_request", incidentStatusBlockOption...)
|
|
incidentStatusBlock := slack.NewInputBlock("incident_status_modal_request_input", incidentStatusText, nil, incidentStatusOption)
|
|
|
|
blocks := slack.Blocks{
|
|
BlockSet: []slack.Block{
|
|
headerSection,
|
|
incidentStatusBlock,
|
|
},
|
|
}
|
|
|
|
return slack.ModalViewRequest{
|
|
Type: slack.ViewType("modal"),
|
|
Title: titleText,
|
|
Close: closeText,
|
|
Submit: submitText,
|
|
Blocks: blocks,
|
|
PrivateMetadata: channel.ID,
|
|
CallbackID: "setIncidentStatus",
|
|
}
|
|
|
|
}
|
|
|
|
func createIncidentStatusBlock(options []entity.IncidentStatusEntity) []*slack.OptionBlockObject {
|
|
optionBlockObjects := make([]*slack.OptionBlockObject, 0, len(options))
|
|
for _, o := range options {
|
|
txt := fmt.Sprintf("%s - %s", o.Name, o.Description)
|
|
optionText := slack.NewTextBlockObject(slack.PlainTextType, txt, false, false)
|
|
optionBlockObjects = append(optionBlockObjects, slack.NewOptionBlockObject(strconv.FormatUint(uint64(o.ID), 10), optionText, nil))
|
|
}
|
|
return optionBlockObjects
|
|
}
|