Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert API changes for api.Message #1124

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/executor/kubectl/builder/kubectl_dropdowns.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func PreviewSection(cmd string, input api.LabelInput) []api.Section {
},
{
Buttons: api.Buttons{
btn.ForCommand(interactive.RunCommandName, cmd, api.ButtonStylePrimary),
btn.ForCommandWithoutDesc(interactive.RunCommandName, cmd, api.ButtonStylePrimary),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/executor/x/output/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (p *TableCommandParser) renderActions(msgCtx template.ParseMessage, table p

return api.Section{
Buttons: []api.Button{
btnBuilder.ForCommand("Raw output", fmt.Sprintf("x run %s %s", cmd, x.RawOutputIndicator)),
btnBuilder.ForCommandWithoutDesc("Raw output", fmt.Sprintf("x run %s %s", cmd, x.RawOutputIndicator)),
},
Selects: api.Selects{
Items: []api.Select{
Expand Down
30 changes: 22 additions & 8 deletions pkg/api/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ const (

// Button holds definition of action button.
type Button struct {
Description string
Description string

// DescriptionStyle defines the style of the button description. If not provided, the default style (ButtonDescriptionStyleCode) is used.
DescriptionStyle ButtonDescriptionStyle

Name string
Expand Down Expand Up @@ -317,8 +319,8 @@ func (b *ButtonBuilder) DescriptionURL(name, cmd string, url string, style ...Bu
}
}

// ForCommand returns button command without description.
func (b *ButtonBuilder) ForCommand(name, cmd string, style ...ButtonStyle) Button {
// ForCommandWithoutDesc returns button command without description.
func (b *ButtonBuilder) ForCommandWithoutDesc(name, cmd string, style ...ButtonStyle) Button {
bt := ButtonStyleDefault
if len(style) > 0 {
bt = style[0]
Expand All @@ -331,6 +333,17 @@ func (b *ButtonBuilder) ForCommand(name, cmd string, style ...ButtonStyle) Butto
}
}

// ForCommand returns button command with description in adaptive code block.
//
// For displaying description in bold, use ForCommandWithBoldDesc.
func (b *ButtonBuilder) ForCommand(name, cmd, desc string, style ...ButtonStyle) Button {
bt := ButtonStyleDefault
if len(style) > 0 {
bt = style[0]
}
return b.commandWithCmdDesc(name, cmd, desc, bt)
}

// ForURLWithBoldDesc returns link button with description.
func (b *ButtonBuilder) ForURLWithBoldDesc(name, desc, url string, style ...ButtonStyle) Button {
urlBtn := b.ForURL(name, url, style...)
Expand All @@ -353,6 +366,12 @@ func (b *ButtonBuilder) ForURL(name, url string, style ...ButtonStyle) Button {
Style: bt,
}
}

func (b *ButtonBuilder) commandWithCmdDesc(name, cmd, desc string, style ButtonStyle) Button {
desc = fmt.Sprintf("%s %s", MessageBotNamePlaceholder, desc)
return b.commandWithDesc(name, cmd, desc, style, ButtonDescriptionStyleCode)
}

func (b *ButtonBuilder) commandWithDesc(name, cmd, desc string, style ButtonStyle, descStyle ButtonDescriptionStyle) Button {
cmd = fmt.Sprintf("%s %s", MessageBotNamePlaceholder, cmd)
return Button{
Expand All @@ -363,8 +382,3 @@ func (b *ButtonBuilder) commandWithDesc(name, cmd, desc string, style ButtonStyl
Style: style,
}
}

func (b *ButtonBuilder) commandWithCmdDesc(name, cmd, desc string, style ButtonStyle) Button {
desc = fmt.Sprintf("%s %s", MessageBotNamePlaceholder, desc)
return b.commandWithDesc(name, cmd, desc, style, ButtonDescriptionStyleCode)
}
10 changes: 5 additions & 5 deletions pkg/bot/interactive/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func (h *HelpMessage) notificationSections() []api.Section {
},
},
Buttons: []api.Button{
h.btnBuilder.ForCommand("Enable", "enable notifications"),
h.btnBuilder.ForCommand("Disable", "disable notifications"),
h.btnBuilder.ForCommand("Get status", "status notifications"),
h.btnBuilder.ForCommandWithoutDesc("Enable", "enable notifications"),
h.btnBuilder.ForCommandWithoutDesc("Disable", "disable notifications"),
h.btnBuilder.ForCommandWithoutDesc("Get status", "status notifications"),
},
},
{
Expand Down Expand Up @@ -159,8 +159,8 @@ func (h *HelpMessage) executorSections() []api.Section {
Header: "Manage executors and aliases",
},
Buttons: []api.Button{
h.btnBuilder.ForCommand("List executors", "list executors"),
h.btnBuilder.ForCommand("List aliases", "list aliases"),
h.btnBuilder.ForCommandWithoutDesc("List executors", "list executors"),
h.btnBuilder.ForCommandWithoutDesc("List aliases", "list aliases"),
h.btnBuilder.ForURL("Executors and aliases help", "https://docs.botkube.io/usage/executor"),
},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/bot/interactive/plugin_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var pluginHelpProvider = map[string]pluginHelpProviderFn{
Header: "Run kubectl commands",
},
Buttons: []api.Button{
btnBuilder.ForCommand("Interactive kubectl", "kubectl", api.ButtonStylePrimary),
btnBuilder.ForCommand("kubectl help", "kubectl help"),
btnBuilder.ForCommandWithoutDesc("Interactive kubectl", "kubectl", api.ButtonStylePrimary),
btnBuilder.ForCommandWithoutDesc("kubectl help", "kubectl help"),
},
}
}
Expand All @@ -34,7 +34,7 @@ var pluginHelpProvider = map[string]pluginHelpProviderFn{
Header: "Run kubectl commands (if enabled)",
},
Buttons: []api.Button{
btnBuilder.ForCommand("kubectl help", "kubectl help"),
btnBuilder.ForCommandWithoutDesc("kubectl help", "kubectl help"),
},
}
},
Expand Down
7 changes: 5 additions & 2 deletions pkg/bot/slack_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,13 @@ func (b *SlackRenderer) renderButtonsWithDescription(in api.Buttons) []slack.Blo
for _, btn := range in {
desc := btn.Description
switch btn.DescriptionStyle {
case api.ButtonDescriptionStyleCode:
desc = formatx.AdaptiveCodeBlock(desc)
case api.ButtonDescriptionStyleBold:
desc = fmt.Sprintf("*%s*", desc)
case api.ButtonDescriptionStyleCode:
fallthrough
default:
// keep backward compatibility
desc = formatx.AdaptiveCodeBlock(desc)
}

out = append(out, slack.NewSectionBlock(
Expand Down