Skip to content

chore: Add user autocomplete #4210

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

Merged
merged 7 commits into from
Sep 27, 2022
Merged

chore: Add user autocomplete #4210

merged 7 commits into from
Sep 27, 2022

Conversation

BrunoQuaresma
Copy link
Collaborator

This is the component we are using for the "groups" feature. Maybe it needs to be more polished and add some stories/tests but since the stories don't work well for components with "toggle states and animations" I think it is ok. Also, tests for this kind of component can be challenging and I'm not sure if it is worth adding.

@BrunoQuaresma BrunoQuaresma requested a review from a team as a code owner September 26, 2022 19:22
@BrunoQuaresma BrunoQuaresma self-assigned this Sep 26, 2022
const query = value ? value.email : ""
sendSearch("SEARCH", { query })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have some users in v1 with 1000 ~ 2,500 users so loading them at the beginning can be heavy. I think we could only load this when the user start to type in the search box + debouce(to avoid extra loads during typing). What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

@BrunoQuaresma good point! Your solution sounds right. So we can get this out there (@kylecarbs wants to use it) how about we do something like:

  useEffect(() => {
    if (value) {
      sendSearch("SEARCH", { query: value.email })
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])

for now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good!

const query = selectedValue ? selectedValue.email : ""
sendSearch("SEARCH", { query })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedValue])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is already done in the handleFilterChange. I don't think we need the useEffect here 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this is what I'm trying to solve with this useEffect:
Kapture 2022-09-27 at 09 34 30

Is there a better way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahhh I see. So when you clear the input, you want to clear the results as well right? If it is, I would add a new event to the search machine called CLEAR_RESULTS that sets the results to undefined and do this logic in the onChange handler like:

....
// This happens when the user clears the results with the "x" button
if(option === null) {
    send("CLEAR_RESULTS")
}

Unfortunately, the MUI Autocomplete does not have an onClear 😔 that would be a better place. I like to put logic on event handlers because I think they are better to follow when they are called than useEffect but it is up to you. If you think this is not necessary feel free to merge it.

Copy link
Member

Choose a reason for hiding this comment

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

That worked well! Thanks!

@Kira-Pilot Kira-Pilot merged commit 5a449bf into main Sep 27, 2022
@Kira-Pilot Kira-Pilot deleted the bq/add-users-auto-complete branch September 27, 2022 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants