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

fix: fixed issue with filter selection logic #3628

Merged
merged 3 commits into from
Jan 30, 2025

Conversation

Shriya-Chauhan
Copy link
Contributor

@Shriya-Chauhan Shriya-Chauhan commented Jan 30, 2025

Description
Fix #3627

Changes Implemented:

  • Added the ability to deselect individual filters dynamically.
  • Updated the URL query parameters to reflect filter changes in real-time.
  • Ensured that the "Clear Filters" button remains available for full reset.
  • Improved the filter selection logic to make the UI more intuitive.
2025-01-30.15-36-44.mp4

Summary by CodeRabbit

  • Bug Fixes
    • Improved filter handling by removing deselected filter options from query parameters.

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Walkthrough

The pull request modifies the Filter component in components/navigation/Filter.tsx to improve filter management. A new line of code is added to the onChange event handler, which deletes a specific filter from the query parameters when it is deselected. This change allows users to remove individual filters without clearing all filters, enhancing the filtering functionality by providing more granular control over applied filters.

Changes

File Change Summary
components/navigation/Filter.tsx Added delete newQuery[check.name]; to remove individual filters when deselected

Assessment against linked issues

Objective Addressed Explanation
Remove individual filters without clearing all [#3627]
Maintain existing filter UI [#3627]
Dynamic filter update [#3627]

Suggested labels

ready-to-merge

Suggested reviewers

  • derberg
  • magicmatatjahu
  • Mayaleeeee
  • asyncapi-bot-eve
  • akshatnema

Poem

🐰 A filter's dance, a gentle hop,
Removing one, without a stop
No more all-or-nothing plight
Each choice now feels just right!
Code hops with user's delight 🎉


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 712e86f and 28bf9cf.

📒 Files selected for processing (1)
  • components/navigation/Filter.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/navigation/Filter.tsx

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@github-actions github-actions bot left a 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.

Copy link

netlify bot commented Jan 30, 2025

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 28bf9cf
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/679b534c7b1fa600083c2ef2
😎 Deploy Preview https://deploy-preview-3628--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (59209f2) to head (28bf9cf).
Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Jan 30, 2025

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 34
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3628--asyncapi-website.netlify.app/

@Shriya-Chauhan Shriya-Chauhan changed the title Fixed issue with filter selection logic fix: fixed issue with filter selection logic Jan 30, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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:

  1. Extract URL handling logic into a custom hook
  2. Add error handling for router operations
  3. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 59209f2 and 712e86f.

📒 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.

@anshgoyalevil
Copy link
Member

@Shriya-Chauhan Thanks for the PR.
Merging this one, but please be mindful that all issues require a triage before proceeding with a PR. Read the contributing guidelines explaining the flow.

@Shriya-Chauhan
Copy link
Contributor Author

Got it! I'll make sure to go through the triage process before opening a PR next time. Thanks for the heads-up!

@anshgoyalevil
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit bca2a91 into asyncapi:master Jan 30, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Allow Deselecting Individual Filters Without Clearing All
3 participants