Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
hirenko-v authored Sep 22, 2024
1 parent 6e901e6 commit ad2f249
Showing 1 changed file with 46 additions and 55 deletions.
101 changes: 46 additions & 55 deletions cmd/msg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Option struct {
Description string `json:"description"`
Values []string `json:"values,omitempty"`
Default string `json:"default,omitempty"`
Type string `json:"type"`
}

type ScriptOutput struct {
Expand Down Expand Up @@ -175,29 +176,6 @@ func initialMessages() executor.ExecuteOutput {
},
},
},
TextFields: api.TextFields{
{
Key: "Kind",
Value: "pod",
},
{
Key: "Namespace",
Value: "botkube",
},
{
Key: "Name",
Value: "webapp-server-68c5c57f6f",
},
{
Key: "Reason",
Value: "BackOff",
},
},
Context: api.ContextItems{
api.ContextItem{
Text: "To learn more about `kubectl` RBAC visit https://docs.botkube.io/configuration/executor/kubectl.",
},
},
},
},
OnlyVisibleForYou: true,
Expand Down Expand Up @@ -255,44 +233,57 @@ func showBothSelects(state map[string]string) executor.ExecuteOutput {
continue
}

var dropdownOptions []api.OptionItem
for _, value := range option.Values {
dropdownOptions = append(dropdownOptions, api.OptionItem{
Name: value,
Value: fmt.Sprintf("%s %s", option.Flags[0], value),
})
}
if option.Type == "bool" || option.Type == "dropdown" {

// Construct the flag key for the state
flagKey := fmt.Sprintf("%s-%s", state["first"], option.Flags[0])
var dropdownOptions []api.OptionItem
for _, value := range option.Values {
dropdownOptions = append(dropdownOptions, api.OptionItem{
Name: value,
Value: fmt.Sprintf("%s %s", option.Flags[0], value),
})
}

// Check if there's an InitialOption and update the state if it’s not already set
if _, exists := state[flagKey]; !exists && option.Default != "" {
state[flagKey] = fmt.Sprintf("%s %s", option.Flags[0], option.Default)
}
// Construct the flag key for the state
flagKey := fmt.Sprintf("%s-%s", state["first"], option.Flags[0])

var initialOption *api.OptionItem
if option.Default != "" {
initialOption = &api.OptionItem{
Name: option.Default,
Value: fmt.Sprintf("%s %s", option.Flags[0], option.Default),
// Check if there's an InitialOption and update the state if it’s not already set
if _, exists := state[flagKey]; !exists && option.Default != "" {
state[flagKey] = fmt.Sprintf("%s %s", option.Flags[0], option.Default)
}
} else {
initialOption = nil // Set to nil if Default is not set
}

// Add the dropdown with the InitialOption if available
sections[0].Selects.Items = append(sections[0].Selects.Items, api.Select{
Name: option.Description, // Adjust name based on flags
Command: cmdPrefix(fmt.Sprintf("select_dynamic %s", flagKey)), // Handle dynamic dropdown
OptionGroups: []api.OptionGroup{
{
Name: option.Description,
Options: dropdownOptions,
var initialOption *api.OptionItem
if option.Default != "" {
initialOption = &api.OptionItem{
Name: option.Default,
Value: fmt.Sprintf("%s %s", option.Flags[0], option.Default),
}
} else {
initialOption = nil // Set to nil if Default is not set
}

// Add the dropdown with the InitialOption if available
sections[0].Selects.Items = append(sections[0].Selects.Items, api.Select{
Name: option.Description, // Adjust name based on flags
Command: cmdPrefix(fmt.Sprintf("select_dynamic %s", flagKey)), // Handle dynamic dropdown
OptionGroups: []api.OptionGroup{
{
Name: option.Description,
Options: dropdownOptions,
},
},
},
InitialOption: initialOption,
})
InitialOption: initialOption,
})
}
if option.Type == "text" {
sections[0].Selects.Items = append(sections[0], PlaintextInputs: api.LabelInputs{
api.LabelInput{
// Command: "@BKTesting kubectl @builder --filter-query ",
DispatchedAction: api.DispatchInputActionOnCharacter,
Text: "Filter output",
Placeholder: "Filter output by string (optional)",
},
})
}
}

// If all selections are made, show the run button
Expand Down

0 comments on commit ad2f249

Please sign in to comment.