Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Remove "select all" option from Multiselect #393

Closed
ces131 opened this issue Dec 8, 2021 · 4 comments
Closed

Remove "select all" option from Multiselect #393

ces131 opened this issue Dec 8, 2021 · 4 comments
Labels

Comments

@ces131
Copy link
Contributor

ces131 commented Dec 8, 2021

Hi there!

For our use case, we want to prevent users from being able to select "all options" (using right right arrow) for Mulitselect. It seems like this could be easily done by adding a field to the PromptConfig struct that defaults to still give the "Select All" option, but can be toggled to turn it off (and the template can be updated accordingly as well)

I was going to patch the package but thought that this may be a valid use case for other users as well. I can put up a pull request for it, but wanted to see whether this was of interest :)

Thanks!!

@ces131 ces131 added the Question label Dec 8, 2021
@mislav
Copy link
Collaborator

mislav commented Dec 8, 2021

I'm interested. Thank you for the feature idea! How would you envision this to be configured?

@ces131
Copy link
Contributor Author

ces131 commented Dec 8, 2021

I think it falls sort of in the same category as the KeepFilter config (I noticed it also only applies to MulitSelect also) and could be implemented in pretty much the same way - I chose RemoveSelectAll for my patch, but we could just make this SelectAll or something and set the default to true (just wouldn't follow the "configs being false by default" pattern that's there is so far):

type PromptConfig struct {
	PageSize     int
	Icons        IconSet
	HelpInput    string
	SuggestInput string
	Filter       func(filter string, option string, index int) bool
	KeepFilter   bool
	ShowCursor   bool
	RemoveSelectAll bool
}
// WithRemoveSelectAll - removes the "select all" option in Multiselect
func WithRemoveSelectAll(RemoveSelectAll bool) AskOpt {
	return func(options *AskOptions) error {
		// set the page size
		options.PromptConfig.RemoveSelectAll = RemoveSelectAll

		// nothing went wrong
		return nil
	}
}

(and set the default to false in the defaultAskOptions)

Then in multiselect, we can just skip the KeyRight binding with:

} else if !config.RemoveSelectAll && key == terminal.KeyArrowRight {
		for _, v := range options {
			m.checked[v.Index] = true
		}
		if !config.KeepFilter {
			m.filter = ""
		}

and remove it from the template with:

... space to select, {{- if not .Config.RemoveSelectAll }}<right> to all,{{end}} <left> to none, ...

@mislav
Copy link
Collaborator

mislav commented Dec 14, 2021

That sounds like a great plan. I would encourage you to submit a PR, since you've already identified all the places that need the change 👍

@AlecAivazis
Copy link
Owner

Closing this since #439 has been merged

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants