Debian Codegraph @

dialog_select.go

raw symbols SCIP
1 package slack
2
3 // SelectDataSource types of select datasource
4 type SelectDataSource string
5
6 const (
7 // DialogDataSourceStatic menu with static Options/OptionGroups
8 DialogDataSourceStatic SelectDataSource = "static"
9 // DialogDataSourceExternal dynamic datasource
10 DialogDataSourceExternal SelectDataSource = "external"
11 // DialogDataSourceConversations provides a list of conversations
12 DialogDataSourceConversations SelectDataSource = "conversations"
13 // DialogDataSourceChannels provides a list of channels
14 DialogDataSourceChannels SelectDataSource = "channels"
15 // DialogDataSourceUsers provides a list of users
16 DialogDataSourceUsers SelectDataSource = "users"
17 )
18
19 // DialogInputSelect dialog support for select boxes.
20 type DialogInputSelect struct {
21 DialogInput
22 Value string `json:"value,omitempty"` //Optional.
23 DataSource SelectDataSource `json:"data_source,omitempty"` //Optional. Allowed values: "users", "channels", "conversations", "external".
24 SelectedOptions []DialogSelectOption `json:"selected_options,omitempty"` //Optional. May hold at most one element, for use with "external" only.
25 Options []DialogSelectOption `json:"options,omitempty"` //One of options or option_groups is required.
26 OptionGroups []DialogOptionGroup `json:"option_groups,omitempty"` //Provide up to 100 options.
27 MinQueryLength int `json:"min_query_length,omitempty"` //Optional. minimum characters before query is sent.
28 Hint string `json:"hint,omitempty"` //Optional. Additional hint text.
29 }
30
31 // DialogSelectOption is an option for the user to select from the menu
32 type DialogSelectOption struct {
33 Label string `json:"label"`
34 Value string `json:"value"`
35 }
36
37 // DialogOptionGroup is a collection of options for creating a segmented table
38 type DialogOptionGroup struct {
39 Label string `json:"label"`
40 Options []DialogSelectOption `json:"options"`
41 }
42
43 // NewStaticSelectDialogInput constructor for a `static` datasource menu input
44 func NewStaticSelectDialogInput(name, label string, options []DialogSelectOption) *DialogInputSelect {
45 return &DialogInputSelect{
46 DialogInput: DialogInput{
47 Type: InputTypeSelect,
48 Name: name,
49 Label: label,
50 Optional: true,
51 },
52 DataSource: DialogDataSourceStatic,
53 Options: options,
54 }
55 }
56
57 // NewExternalSelectDialogInput constructor for a `external` datasource menu input
58 func NewExternalSelectDialogInput(name, label string, options []DialogSelectOption) *DialogInputSelect {
59 return &DialogInputSelect{
60 DialogInput: DialogInput{
61 Type: InputTypeSelect,
62 Name: name,
63 Label: label,
64 Optional: true,
65 },
66 DataSource: DialogDataSourceExternal,
67 Options: options,
68 }
69 }
70
71 // NewGroupedSelectDialogInput creates grouped options select input for Dialogs.
72 func NewGroupedSelectDialogInput(name, label string, options []DialogOptionGroup) *DialogInputSelect {
73 return &DialogInputSelect{
74 DialogInput: DialogInput{
75 Type: InputTypeSelect,
76 Name: name,
77 Label: label,
78 },
79 DataSource: DialogDataSourceStatic,
80 OptionGroups: options}
81 }
82
83 // NewDialogOptionGroup creates a DialogOptionGroup from several select options
84 func NewDialogOptionGroup(label string, options ...DialogSelectOption) DialogOptionGroup {
85 return DialogOptionGroup{
86 Label: label,
87 Options: options,
88 }
89 }
90
91 // NewConversationsSelect returns a `Conversations` select
92 func NewConversationsSelect(name, label string) *DialogInputSelect {
93 return newPresetSelect(name, label, DialogDataSourceConversations)
94 }
95
96 // NewChannelsSelect returns a `Channels` select
97 func NewChannelsSelect(name, label string) *DialogInputSelect {
98 return newPresetSelect(name, label, DialogDataSourceChannels)
99 }
100
101 // NewUsersSelect returns a `Users` select
102 func NewUsersSelect(name, label string) *DialogInputSelect {
103 return newPresetSelect(name, label, DialogDataSourceUsers)
104 }
105
106 func newPresetSelect(name, label string, dataSourceType SelectDataSource) *DialogInputSelect {
107 return &DialogInputSelect{
108 DialogInput: DialogInput{
109 Type: InputTypeSelect,
110 Label: label,
111 Name: name,
112 },
113 DataSource: dataSourceType,
114 }
115 }