-
-
Notifications
You must be signed in to change notification settings - Fork 775
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: fixed issue with filter selection logic #3628
Conversation
WalkthroughThe pull request modifies the Changes
Assessment against linked issues
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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
Documentation and Community
|
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.
Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
✅ Deploy Preview for asyncapi-website ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3628 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 20 20
Lines 732 732
=========================================
Hits 732 732 ☔ View full report in Codecov by Sentry. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-3628--asyncapi-website.netlify.app/ |
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
🧹 Nitpick comments (3)
components/navigation/Filter.tsx (3)
69-70
: Consider adding type safety checks.While the deselection logic works, it could benefit from more explicit type handling.
} else { - delete newQuery[check.name]; // Remove filter if deselected + if (check.name in newQuery) { + delete newQuery[check.name]; // Remove filter if deselected + } }
Line range hint
72-79
: Enhance URL parameter handling robustness.The URL parameter construction could be more resilient to edge cases.
- if (newQuery) { + if (newQuery && Object.keys(newQuery).length > 0) { const queryParams = new URLSearchParams(newQuery as { [key: string]: string }).toString(); + const finalUrl = `${route.pathname}${queryParams ? '?' + queryParams : ''}`; - route.push(`${route.pathname}?${queryParams}`, undefined, { + route.push(finalUrl, undefined, { shallow: true }); + } else { + route.push(route.pathname, undefined, { shallow: true }); }
Line range hint
1-85
: Consider architectural improvements for maintainability.A few suggestions to enhance the component's architecture:
- Extract URL handling logic into a custom hook
- Add error handling for router operations
- Strengthen TypeScript types
Example implementation of a custom hook:
// hooks/useFilterUrl.ts interface UseFilterUrlProps { pathname: string; initialQuery?: Record<string, string>; } interface UseFilterUrlReturn { updateFilterUrl: (name: string, value: string | null) => Promise<void>; clearFilters: () => Promise<void>; currentQuery: Record<string, string>; } export function useFilterUrl({ pathname, initialQuery = {} }: UseFilterUrlProps): UseFilterUrlReturn { const router = useRouter(); const [query, setQuery] = useState(initialQuery); const updateFilterUrl = async (name: string, value: string | null) => { try { const newQuery = { ...query }; if (value) { newQuery[name] = value; } else { delete newQuery[name]; } const queryParams = new URLSearchParams(newQuery).toString(); const url = `${pathname}${queryParams ? '?' + queryParams : ''}`; await router.push(url, undefined, { shallow: true }); setQuery(newQuery); } catch (error) { console.error('Failed to update filter URL:', error); // Handle error appropriately } }; const clearFilters = async () => { try { await router.push(pathname, undefined, { shallow: true }); setQuery({}); } catch (error) { console.error('Failed to clear filters:', error); // Handle error appropriately } }; return { updateFilterUrl, clearFilters, currentQuery: query }; }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
components/navigation/Filter.tsx
(1 hunks)
🔇 Additional comments (1)
components/navigation/Filter.tsx (1)
69-70
: LGTM! Filter deselection logic is correctly implemented.The new code properly removes the filter from query parameters when deselected, which aligns with the PR objective of allowing users to dynamically deselect individual filters.
@Shriya-Chauhan Thanks for the PR. |
Got it! I'll make sure to go through the triage process before opening a PR next time. Thanks for the heads-up! |
/rtm |
Description
Fix #3627
Changes Implemented:
2025-01-30.15-36-44.mp4
Summary by CodeRabbit