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

Allow creating new items by inserting comma in MultiAutocomplete #42824

Merged
merged 34 commits into from
May 28, 2024

Conversation

romeovs
Copy link
Contributor

@romeovs romeovs commented May 17, 2024

Closes #42783

Description

Allows creating new filter items by pressing the comma (,) key without having to blur the input.

How to verify

Describe the steps to verify that the changes are working as expected.

  1. Browse data -> Sample data -> Accounts
  2. Add a filter to the First name header
  3. Play around with the filter value input: add new items, type a name and press ,, paste a list of names, add quote-delimited values like "foo, bar", ...

Demo

Metabase.-.17.May.2024.mp4

Checklist

  • Tests have been added/updated to cover changes in this PR

Copy link

github-actions bot commented May 17, 2024

Codenotify: Notifying subscribers in CODENOTIFY files for diff 80687b8...6e9b253.

Notify File(s)
@kdoh frontend/src/metabase/ui/components/inputs/MultiAutocomplete/MultiAutocomplete.module.css
frontend/src/metabase/ui/components/inputs/MultiAutocomplete/MultiAutocomplete.tsx
frontend/src/metabase/ui/components/inputs/MultiAutocomplete/MultiAutocomplete.unit.spec.tsx
frontend/src/metabase/ui/components/inputs/MultiAutocomplete/utils.ts
frontend/src/metabase/ui/components/inputs/MultiAutocomplete/utils.unit.spec.ts

Copy link

replay-io bot commented May 17, 2024

Status Complete ↗︎
Commit 6e9b253
Results
⚠️ 2 Flaky
2569 Passed

@romeovs romeovs added the no-backport Do not backport this PR to any branch label May 17, 2024
@romeovs romeovs changed the title comma in multiselect Allow creating new items by inserting comma in MultiAutocomplete May 17, 2024
setSelectedValues(newSelectedValues);
setLastSelectedValues(newSelectedValues);
}
const text = event.clipboardData.getData("text");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Text was breaking the test, and both Text and text work in my browsers.

@romeovs romeovs requested review from nemanjaglumac and ranquild and removed request for ranquild and nemanjaglumac May 17, 2024 14:42
@romeovs romeovs force-pushed the 42783-comma-in-multiselect branch from 83318af to c97430c Compare May 21, 2024 10:40
@romeovs romeovs force-pushed the 42783-comma-in-multiselect branch from c97430c to b96beea Compare May 21, 2024 11:38
@romeovs romeovs requested a review from a team May 22, 2024 06:47
Copy link
Contributor

@kamilmielnik kamilmielnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well 👍


This change obviously makes it difficult to filters/search for strings that include comma character - please make sure that we have product team approval for this.

(for example in our Sample Database there is a person with this address: 5509-5501,5500-5508 McKinley Avenue - now it won't be possible to just paste this value into the filter input)

@romeovs
Copy link
Contributor Author

romeovs commented May 22, 2024

@kamilmielnik there is a follow up to add escaping for the comma character.

@romeovs
Copy link
Contributor Author

romeovs commented May 24, 2024

@kamilmielnik re:

This change obviously makes it difficult to filters/search for strings that include comma character - please make sure that we have product team approval for this.

I've added those follow up changes here, since they were small and it doesn't make sense to merge this in the "broken" state. Please have another look.

Copy link
Contributor

@kamilmielnik kamilmielnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works really well 👍

I think it's ready to go once we address "Case 3".

setSearchValue("");

if (values.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values aren't used in this if/else block - is this correct?

Two more occurrences of this below.

Suggested change
if (values.length > 0) {
if (validValues.length > 0) {

@romeovs romeovs force-pushed the 42783-comma-in-multiselect branch from 805099e to b783140 Compare May 27, 2024 08:34
@romeovs romeovs force-pushed the 42783-comma-in-multiselect branch from b783140 to bcd93bc Compare May 27, 2024 09:35
@mngr
Copy link

mngr commented May 27, 2024

Captura de ecrã 2024-05-27, às 17 56 36 When I'm trying to enter quote embraced string like "Gizmo, Widget" it is inserted as 2 separate values


if (newSearchValue !== "") {
const values = parseValues(newSearchValue);
if (values.length === 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if values.length > 1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@romeovs romeovs merged commit b6bb9d1 into master May 28, 2024
108 checks passed
@romeovs romeovs deleted the 42783-comma-in-multiselect branch May 28, 2024 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/QueryingComponents
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Press comma to enter a value (this was previously only possible with Tab)
4 participants