-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat(Picker): remain group headers in the list while filtering #1449
Conversation
WalkthroughThe changes in this pull request modify the Changes
Assessment against linked issues
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
packages/react-components/src/components/Picker/hooks/usePickerItems.ts (2)
84-97
: Optimize search performance and handle empty groupsThe filtering logic can be improved for better performance and user experience.
Consider these improvements:
items = items .filter((item) => { + const search = searchPhrase.toLowerCase(); + if (item.groupHeader) { - return true; + // Only show group headers if they have matching children + return items.some(child => + !child.groupHeader && + child.groupId === item.key && + (child.name.toLowerCase().includes(search) || + child.secondaryText?.toLowerCase().includes(search)) + ); } - const search = searchPhrase.toLowerCase(); const itemName = item.name.toLowerCase(); - const itemSecondaryText = item.secondaryText?.toLowerCase(); - - return ( - itemName.includes(search) || itemSecondaryText?.includes(search) - ); + return itemName.includes(search) || + (item.secondaryText?.toLowerCase() || '').includes(search); })
98-104
: Improve readability of group header cleanup logicThe consecutive group header removal logic is correct but could be more expressive.
Consider this more readable approach:
- .filter( - (item, index, array) => - !( - item.groupHeader && - (array[index + 1]?.groupHeader || index === array.length - 1) - ) - ); + .filter((item, index, array) => { + if (!item.groupHeader) return true; + + const isLastItem = index === array.length - 1; + const nextItemIsHeader = array[index + 1]?.groupHeader; + + return !(isLastItem || nextItemIsHeader); + });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/react-components/src/components/Picker/hooks/usePickerItems.ts
(1 hunks)
🔇 Additional comments (1)
packages/react-components/src/components/Picker/hooks/usePickerItems.ts (1)
84-104
: Verify group header visibility behavior
The implementation keeps group headers visible but might show empty groups. Let's verify the expected behavior.
✅ Verification successful
Group header behavior is correctly implemented
The implementation is verified through test cases that explicitly handle group headers:
- Test case demonstrates proper group header handling with "Group A title header" and "Group B title header"
- Headers remain visible while filtering disabled items
- The filter implementation correctly preserves group structure
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Find related test files and component usage
echo "Looking for related test files..."
fd -e test.ts -e test.tsx . | grep -i "picker"
echo "Finding component usage examples..."
rg -l "usePickerItems" --type ts --type tsx
Length of output: 276
Script:
#!/bin/bash
# Search for test files with improved pattern
fd "picker.*\.(test|spec)\.(ts|tsx)$" .
# Search for component usage with correct ripgrep syntax
echo "Finding component usage..."
rg -t typescript -t javascriptreact -t typescriptreact "usePickerItems"
# Look for picker-related test cases
echo "Searching for picker test cases..."
rg -t typescript -t typescriptreact "describe.*Picker|test.*Picker" -A 2
# Check implementation details
echo "Checking implementation details..."
rg -t typescript -t typescriptreact "groupHeader.*filter" -A 5 -B 5
Length of output: 1056
Script:
#!/bin/bash
# Check test cases for group header behavior
cat ./packages/react-components/src/components/Picker/Picker.spec.tsx
# Check implementation in PickerList
cat ./packages/react-components/src/components/Picker/components/PickerList.spec.tsx
# Look for usePickerItems implementation and tests
echo "Searching for usePickerItems tests..."
find . -type f -name "*.spec.tsx" -o -name "*.test.tsx" | xargs grep -l "usePickerItems"
Length of output: 12408
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coderabbit has a point, we could make these filters more readable, but that's fine
Resolves: https://livechatinc.atlassian.net/browse/HD-4644
Description
Make group headers visible in the option list while filtering with search phrase.
Storybook
https://feature-HD-4644--613a8e945a5665003a05113b.chromatic.com
Checklist
Obligatory:
Summary by CodeRabbit
New Features
groupHeader
items in search results.groupHeader
items from appearing in the results.Bug Fixes