diff --git a/cmd/msg/main.go b/cmd/msg/main.go index 81d5695..f692726 100644 --- a/cmd/msg/main.go +++ b/cmd/msg/main.go @@ -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) @@ -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) } @@ -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{ { @@ -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", @@ -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 ), }, },