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

Add filter input to group members table #9102

Merged
merged 2 commits into from
Nov 20, 2024
Merged

Add filter input to group members table #9102

merged 2 commits into from
Nov 20, 2024

Conversation

robertknight
Copy link
Member

Add a search box to filter group members. The filter currently only matches the username, is applied client-side and is case-insensitive.

Filter not applied:

filter-empty

Filter applied with match:

filter-match

Filter applied with no matches:

filter-no-match

Add a search box to filter group members. The filter currently only matches the
username, is applied client-side and is case-insensitive.
@robertknight
Copy link
Member Author

In the client we have a SearchField component that has additional features compared to a plain input such as a search icon, support for focusing by pressing "/" and a "clear" button when non-empty. It might be useful to extract that into the shared library so we can use it here.

client-search-field

@acelaya
Copy link
Contributor

acelaya commented Nov 20, 2024

In the client we have a SearchField component that has additional features compared to a plain input such as a search icon, support for focusing by pressing "/" and a "clear" button when non-empty. It might be useful to extract that into the shared library so we can use it here.

client-search-field

I believe we have something similar in via's video transcript app, so it definitely makes sense to extract a component that can be reused.

@robertknight
Copy link
Member Author

The filtering and member count are currently implemented client side, but once we have pagination they will need to be implemented server-side. This means we will probably need to temporarily remove this until more critical functionality is implemented.

Copy link
Contributor

@acelaya acelaya left a comment

Choose a reason for hiding this comment

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

👍🏼

Comment on lines 80 to 92
const normalizedFilter = filter.toLowerCase();

const filteredMembers = useMemo(() => {
if (!normalizedFilter || !members) {
return members;
}
// nb. We can get away with lower-casing name and filter to do
// case-insensitive search because of the character set restrictions on
// usernames. This would be incorrect for Unicode text.
return members.filter(m =>
m.username.toLowerCase().includes(normalizedFilter),
);
}, [normalizedFilter, members]);
Copy link
Contributor

@acelaya acelaya Nov 20, 2024

Choose a reason for hiding this comment

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

Since normalizedFilter is used only inside the callback to calculate filteredMembers, maybe it's worth moving it there and make filter the dependency instead of normalizedFilter.

Suggested change
const normalizedFilter = filter.toLowerCase();
const filteredMembers = useMemo(() => {
if (!normalizedFilter || !members) {
return members;
}
// nb. We can get away with lower-casing name and filter to do
// case-insensitive search because of the character set restrictions on
// usernames. This would be incorrect for Unicode text.
return members.filter(m =>
m.username.toLowerCase().includes(normalizedFilter),
);
}, [normalizedFilter, members]);
const filteredMembers = useMemo(() => {
if (!filter || !members) {
return members;
}
// nb. We can get away with lower-casing name and filter to do
// case-insensitive search because of the character set restrictions on
// usernames. This would be incorrect for Unicode text.
const normalizedFilter = filter.toLowerCase();
return members.filter(m =>
m.username.toLowerCase().includes(normalizedFilter),
);
}, [filter, members]);

@robertknight robertknight merged commit 5e50668 into main Nov 20, 2024
9 checks passed
@robertknight robertknight deleted the members-filter branch November 20, 2024 16:50
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