-
Notifications
You must be signed in to change notification settings - Fork 104
Add multisearch
prompt
#58
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
Conversation
Nice work, @irobin591! I've played with this locally and am not 100% sold on the behaviour though. If you select an option and then change the filter, it will hide the selected option, so it's unclear which options have been selected unless you go back and delete the search text. It's tricky because there isn't a native HTML form element to base the UX on that people would be used to. The most common UI I've seen adds the selected options to the search input like this: But this would be quite complicated to implement on the command line - especially allowing users to remove selections! I wonder whether the selected options should always appear regardless of the search filter. Perhaps all together at the top or bottom of the dropdown, with any selected options filtered from the unselected results to prevent appearing twice. What do you think? |
Thanks for your feedback! As you have noticed, I have implemented displaying all selected items when the search term is empty. But I see why this might not be the best solution, especially if there is no other indicator for this behaviour. I like your idea of adding all selected options at the top or bottom of the dropdown, but it might be cumbersome if many options are selected (i.e. via the default parameter) and the user wants to deselect a specific option. As all selected options are displayed and not affected by the search, this can become difficult to navigate. If we want to always display all selected options, we can add another box either on top or below with all selected options, while still showing the filtered and potentially selected options in the search dropdown. |
I like the "X items selected" idea. Or perhaps it could say "+X additional items" only when there are hidden items. It could be integrated into the bottom border. E.g:
|
Maybe even a combination of both as the amount of visible selected items might not be apparent as some might be not in view?
I'll work on these variants this weekend and see how it feels |
33319f5
to
8c9fc22
Compare
Nice! I think I prefer the second one, where it only shows the hidden count when there are hidden items. Feels a bit cleaner and ties in better with the With the |
Just pushed a few changes, most notably to adopt the changes merged in #60. I dig the |
With the A use case I'm thinking of would be for $files = multisearch(
label: "Which provider or tag's files would you like to publish?",
placeholder: 'Search...',
options: fn ($value) => collect([
'Foo\ServiceProvider' => '<fg=gray>Provider:</> Foo\ServiceProvider',
'Bar\ServiceProvider' => '<fg=gray>Provider:</> Bar\ServiceProvider',
'foo-assets' => '<fg=gray>Tag:</> foo-assets',
'foo-config' => '<fg=gray>Tag:</> foo-config',
'bar-assets' => '<fg=gray>Tag:</> bar-assets',
'bar-config' => '<fg=gray>Tag:</> bar-config',
])->when(
strlen($value),
fn ($vendor) => $vendor->filter(fn ($label) => str_contains(strtolower($label), strtolower($value)))
)->all(),
); |
To summarise my thoughts:
In a separate PR, either of us could look at adding a |
2869c27
to
c7f1d85
Compare
I've implemented the above requests. I'd appreciate your thoughts on the implementation, UX, and whether this still solves your use case. |
Thanks for your review and implementation of your requests!
I like your change adding the selected items on top when nothing has been selected! This way, the user can see all selected entries independent of what the developer has returned. I just had the idea, whether we can provide the callable
If it should be implemented like you described, it should be made clear to the developers, that an empty search value does not need to return all possible items, but at least the default items. Returning all possible items might cause issues with >1000 entries in the database. If we force the developer to load all entries from the database initially, there is no real difference between the
This change is for consistency with the
This might happen when the list is fetched from the database with the index as key and the index starts at 0. This case should not be a common occurrence (MySQL starts auto-incrementing indexes at 1 by default, so no issue here), but should be something to consider as the developer has no control on whether indexes, values, or a mix of both are returned.
The Other than that, everything looks fine to me. What are your thoughts on my comments? |
Interesting idea! But I'm a little worried about the UI inconsistencies it might lead to. Could always be implemented in a custom prompt.
Yeah, it would need some documentation if we add that.
Yeah, that could be a bit of a foot gun. If you're working with a list, you'd need to make sure to always return a list after filtering (i.e.
Cool. Let's try a PR for that once this is merged. |
I'll fix the conflict once #70 is merged as it will conflict too. |
If this is merged, we'll need to PR a Windows fallback to I imagine it would be almost the same as the |
Hi there,
We have been using this package a lot at work, but we've run into one issue: sometimes we need to combine a
search
and amultiselect
prompt.Imagine the following scenario: The role association for a user is currently handled via console commands and consists of two steps: First one needs to search for a domain for which roles should be attached to a user, afterward one has to select none, one, or multiple roles related to the domain to attach to a user.
This results into the following prompts:
search
prompt for selecting the user that should be modifiedsearch
prompt for a domainmultiselect
prompt for specific roles within that domain with preselected roles that have already been given to the userThe
search
for a domain and themultiselect
for roles might also be in a while loop, as one might want to add multiple roles on different domains.Introducing: the
multisearch
prompt. This prompt allows searching for entries and selecting multiple of them, confirming everything withenter
. When no search prompt has been entered, all currently selected entries are shown and can be deselected.While working on the prompt, I noticed a bug which I have addressed in a separate commit: The scroll position is not being changed when updating a search. This might cause the list of entries to seem empty, if the list of entries is smaller than the current first visible index. You can still scroll, but it seems unintuitive.