Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
hirenko-v authored Sep 19, 2024
1 parent 06bc3f9 commit 2b012c3
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions cmd/msg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ func (MsgExecutor) Execute(_ context.Context, in executor.ExecuteInput) (executo
}, nil
}

// Check if command is to select the job
if strings.HasPrefix(in.Command, "select job") {
selectedJob := strings.TrimPrefix(in.Command, "select job ")
return showParametersForJob(selectedJob), nil
}

if strings.TrimSpace(in.Command) == pluginName {
return initialMessages(), nil
return initialJobSelection(), nil
}

msg := fmt.Sprintf("Plain command: %s", in.Command)
Expand All @@ -49,8 +55,8 @@ func (MsgExecutor) Execute(_ context.Context, in executor.ExecuteInput) (executo
}, nil
}

func initialMessages() executor.ExecuteOutput {
btnBuilder := api.NewMessageButtonBuilder()
// initialJobSelection shows only the job dropdown
func initialJobSelection() executor.ExecuteOutput {
cmdPrefix := func(cmd string) string {
return fmt.Sprintf("%s %s %s", api.MessageBotNamePlaceholder, pluginName, cmd)
}
Expand All @@ -62,17 +68,10 @@ func initialMessages() executor.ExecuteOutput {
{Name: "Job3", Value: "job3"},
}

// Define a list of parameters
params := []api.OptionItem{
{Name: "Param1", Value: "param1"},
{Name: "Param2", Value: "param2"},
{Name: "Param3", Value: "param3"},
}

return executor.ExecuteOutput{
Message: api.Message{
BaseBody: api.Body{
Plaintext: "Select a job and parameters, then click run:",
Plaintext: "Select a job:",
},
Sections: []api.Section{
{
Expand All @@ -93,13 +92,40 @@ func initialMessages() executor.ExecuteOutput {
},
},
},
},
OnlyVisibleForYou: true,
ReplaceOriginal: false,
},
}
}

// showParametersForJob displays parameters dropdown after job selection
func showParametersForJob(job string) executor.ExecuteOutput {
btnBuilder := api.NewMessageButtonBuilder()
cmdPrefix := func(cmd string) string {
return fmt.Sprintf("%s %s %s", api.MessageBotNamePlaceholder, pluginName, cmd)
}

// Define a list of parameters based on job selection (for simplicity, we'll use the same params for all jobs)
params := []api.OptionItem{
{Name: "Param1", Value: "param1"},
{Name: "Param2", Value: "param2"},
{Name: "Param3", Value: "param3"},
}

return executor.ExecuteOutput{
Message: api.Message{
BaseBody: api.Body{
Plaintext: fmt.Sprintf("You selected job: %s. Now select parameters and click run:", job),
},
Sections: []api.Section{
{
Selects: api.Selects{
ID: "param-dropdown",
Items: []api.Select{
{
Name: "Select Parameters",
Command: cmdPrefix("select param"),
Command: cmdPrefix(fmt.Sprintf("select param for job %s", job)),
OptionGroups: []api.OptionGroup{
{
Name: "Parameters",
Expand All @@ -113,10 +139,9 @@ func initialMessages() executor.ExecuteOutput {
},
{
Buttons: []api.Button{
btnBuilder.ForCommandWithDescCmd("Run po", fmt.Sprintf("%s po", "kubectl get"), api.ButtonStylePrimary),
btnBuilder.ForCommandWithoutDesc(
"Run",
fmt.Sprintf("kubectl run job ${job} ${param}"), // Command to be executed
fmt.Sprintf("kubectl run job %s ${param}", job), // Command to be executed
),
},
},
Expand Down

0 comments on commit 2b012c3

Please sign in to comment.