-
Notifications
You must be signed in to change notification settings - Fork 5
fix: search ref problem #1602
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
fix: search ref problem #1602
Conversation
WalkthroughThe pull request introduces a new function, Changes
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 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: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- packages/extension-polkagate/src/fullscreen/governance/SearchBox.tsx (6 hunks)
🧰 Additional context used
🔇 Additional comments (3)
packages/extension-polkagate/src/fullscreen/governance/SearchBox.tsx (3)
93-94
: LGTM! Good separation of concernsThe simplified
onSearch
function now properly focuses on state management, while delegating filtering logic toapplySearchFilter
.
Line range hint
177-186
: LGTM! Clean formatting changesThe Grid component adjustments improve code readability while maintaining the same functionality.
Also applies to: 233-236
63-72
: Verify the search reference fixLet's verify that the search reference problem is properly fixed by checking the actual behavior.
Also applies to: 125-128
✅ Verification successful
Let me gather more information about the search functionality implementation to verify the fix.
The previous attempt with file type
tsx
failed, so I've modified the search to use glob patterns instead. This will help us understand:
- How SearchBox is used across the codebase
- If there are any existing tests for the search functionality
- Related filter implementations that might affect the search behavior
Let me gather one more piece of information to understand the filter implementation better.
This will help us understand:
- How the filter state is structured and used
- The type definitions for the filter object to verify the implementation matches the intended behavior
Based on the gathered information, I can now provide a final response about the search reference fix.
Search functionality implementation is correct and properly fixed
The implementation properly handles the search reference problem through:
- Correct string comparison for reference index:
String(r.post_id) === keyword
- Proper case-insensitive search for titles and methods:
.toLowerCase().includes(keyword.toLowerCase())
- Exact match for proposer addresses:
r.proposer === keyword
- Clear separation of filter logic with proper dependency tracking in
useCallback
- Consistent filter application order with proper state management
The search functionality is implemented as a composable filter system where:
- Advanced filters (refIndex, titles, methods, proposers) are properly toggled
- Status filters are correctly applied
- Search keyword filtering is applied after other filters
- Duplicates are properly handled via Set
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any test files or specs that verify the search functionality rg -t tsx -t ts "describe.*SearchBox" --glob "!node_modules" # Look for any related issue discussions gh issue view 1601Length of output: 249
Script:
#!/bin/bash # Search for SearchBox component usage and related tests rg -g "*.{ts,tsx,test.ts,test.tsx}" "SearchBox" -A 5 # Look for any test files containing "search" related tests rg -g "*.{test.ts,test.tsx,spec.ts,spec.tsx}" "test|describe|it.*search" -i # Check for any related components or utilities that might be testing the search functionality rg -g "*.{ts,tsx}" "applySearchFilter|filterReferenda" -A 5Length of output: 9844
Script:
#!/bin/bash # Check the filter state and implementation rg -g "*.{ts,tsx}" "filter\.(advanced|status)" -B 3 -A 3 # Look for any related filter type definitions ast-grep --pattern 'interface $_ { advanced?: $$$ }'Length of output: 7815
if (searchKeyword) { | ||
filtered = applySearchFilter(filtered, searchKeyword); | ||
} | ||
|
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.
🛠️ Refactor suggestion
Consider optimizing Set conversion
The current implementation correctly handles search filtering, but the Set conversion for removing duplicates could be optimized.
- // to remove duplicates
- const uniqueFiltered = [...new Set(filtered)];
+ // to remove duplicates using post_id as unique identifier
+ const uniqueFiltered = Array.from(
+ new Map(filtered.map(item => [item.post_id, item])).values()
+ );
This approach is more efficient as it:
- Uses a specific unique identifier (post_id)
- Avoids potential reference comparison issues
Also applies to: 132-132
const applySearchFilter = useCallback((referendaToFilter: LatestReferenda[], keyword: string) => { | ||
const filtered = referendaToFilter.filter((r) => | ||
(filter.advanced.refIndex && String(r.post_id) === keyword) || | ||
(filter.advanced.titles && r.title && r.title.toLowerCase().includes(keyword.toLowerCase())) || | ||
(filter.advanced.methods && r.method && r.method.toLowerCase().includes(keyword.toLowerCase())) || | ||
(filter.advanced.proposers && r.proposer === keyword) | ||
); | ||
|
||
return filtered; | ||
}, [filter.advanced.methods, filter.advanced.proposers, filter.advanced.refIndex, filter.advanced.titles]); |
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.
🛠️ Refactor suggestion
Improve search filter robustness
The filtering logic could be made more robust with the following improvements:
- Convert ref_id to string for comparison to handle potential type mismatches
- Consider case-insensitive comparison for proposer addresses
const applySearchFilter = useCallback((referendaToFilter: LatestReferenda[], keyword: string) => {
const filtered = referendaToFilter.filter((r) =>
- (filter.advanced.refIndex && String(r.post_id) === keyword) ||
+ (filter.advanced.refIndex && String(r.post_id) === String(keyword)) ||
(filter.advanced.titles && r.title && r.title.toLowerCase().includes(keyword.toLowerCase())) ||
(filter.advanced.methods && r.method && r.method.toLowerCase().includes(keyword.toLowerCase())) ||
- (filter.advanced.proposers && r.proposer === keyword)
+ (filter.advanced.proposers && r.proposer.toLowerCase() === keyword.toLowerCase())
);
return filtered;
}, [filter.advanced.methods, filter.advanced.proposers, filter.advanced.refIndex, filter.advanced.titles]);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const applySearchFilter = useCallback((referendaToFilter: LatestReferenda[], keyword: string) => { | |
const filtered = referendaToFilter.filter((r) => | |
(filter.advanced.refIndex && String(r.post_id) === keyword) || | |
(filter.advanced.titles && r.title && r.title.toLowerCase().includes(keyword.toLowerCase())) || | |
(filter.advanced.methods && r.method && r.method.toLowerCase().includes(keyword.toLowerCase())) || | |
(filter.advanced.proposers && r.proposer === keyword) | |
); | |
return filtered; | |
}, [filter.advanced.methods, filter.advanced.proposers, filter.advanced.refIndex, filter.advanced.titles]); | |
const applySearchFilter = useCallback((referendaToFilter: LatestReferenda[], keyword: string) => { | |
const filtered = referendaToFilter.filter((r) => | |
(filter.advanced.refIndex && String(r.post_id) === String(keyword)) || | |
(filter.advanced.titles && r.title && r.title.toLowerCase().includes(keyword.toLowerCase())) || | |
(filter.advanced.methods && r.method && r.method.toLowerCase().includes(keyword.toLowerCase())) || | |
(filter.advanced.proposers && r.proposer.toLowerCase() === keyword.toLowerCase()) | |
); | |
return filtered; | |
}, [filter.advanced.methods, filter.advanced.proposers, filter.advanced.refIndex, filter.advanced.titles]); |
## [0.19.5](v0.19.4...v0.19.5) (2024-10-23) ### Bug Fixes * search ref problem ([#1602](#1602)) ([a43adba](a43adba))
close #1601
Summary by CodeRabbit
New Features
Improvements