Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
hirenko-v committed Sep 29, 2024
1 parent c31933d commit 234bdb8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cmd/job/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func (MsgExecutor) Metadata(context.Context) (api.MetadataOutput, error) {

// Execute returns a given command as a response.
func (e *MsgExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (executor.ExecuteOutput, error) {
slackState := in.Context.SlackState
slackStateJSON, err := json.MarshalIndent(slackState, "", " ")
if err != nil {
return executor.ExecuteOutput{
Message: api.NewCodeBlockMessage(fmt.Sprintf("Failed to MarshalIndent %s", err), true),
}, nil
}
// else {
// return executor.ExecuteOutput{
// Message: api.NewCodeBlockMessage(fmt.Sprintf("%s", string(slackStateJSON)), true),
// }, nil
// }

// Kubernetes client setup
kubeConfigPath, deleteFn, err := plugin.PersistKubeConfig(ctx, in.Context.KubeConfig)
Expand Down Expand Up @@ -132,13 +144,13 @@ func (e *MsgExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (ex

// Store the selection from the first dropdown
e.state[e.sessionID]["first"] = value
return showBothSelects(ctx, envs, e.state[e.sessionID], e.sessionID), nil
return showBothSelects(ctx, envs, e.state[e.sessionID], slackStateJSON), nil

case "select_dynamic":
// Store dynamic dropdown selections (flag is passed in the command)
flag := strings.Fields(value)[0]
e.state[e.sessionID][flag] = strings.TrimPrefix(value, flag+" ")
return showBothSelects(ctx, envs, e.state[e.sessionID], e.sessionID), nil
return showBothSelects(ctx, envs, e.state[e.sessionID], slackStateJSON), nil

case "run":
fields := strings.Fields(value)
Expand Down Expand Up @@ -280,7 +292,7 @@ func initialMessages(ctx context.Context, envs map[string]string, e *MsgExecutor
}

// showBothSelects dynamically generates dropdowns based on the selected options.
func showBothSelects(ctx context.Context, envs map[string]string, state map[string]string, sessionID string) executor.ExecuteOutput {
func showBothSelects(ctx context.Context, envs map[string]string, state map[string]string, slackStateJSON []byte) executor.ExecuteOutput {
var jobList []api.OptionItem
jobs := getBotkubeJobs(ctx, envs)
for _, job := range jobs {
Expand Down Expand Up @@ -392,7 +404,7 @@ func showBothSelects(ctx context.Context, envs map[string]string, state map[stri
return executor.ExecuteOutput{
Message: api.Message{
BaseBody: api.Body{
Plaintext: fmt.Sprintf("Please select the Job parameters for %s. Session ID is: %s", state["first"], sessionID),
Plaintext: fmt.Sprintf("Please select the Job parameters for %s. Session ID is: %s", state["first"], slackStateJSON),
},
Sections: sections,
OnlyVisibleForYou: true,
Expand Down

0 comments on commit 234bdb8

Please sign in to comment.