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: Clear All Filters Badge Visibility in Resource page #9557

Closed

Conversation

Mahendar0701
Copy link
Contributor

@Mahendar0701 Mahendar0701 commented Dec 24, 2024

Proposed Changes

clear.badge.mp4

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Enhanced querying mechanism for fetching facility data in the Resource Filter component.
    • Introduced a new method for date filtering within the filter utility.
  • Bug Fixes

    • Adjusted default value for the emergency filter from "--" to an empty string "".

@Mahendar0701 Mahendar0701 requested a review from a team as a code owner December 24, 2024 10:12
Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

Walkthrough

The pull request modifies the ResourceFilter.tsx component by replacing the custom query hook with the useQuery hook from the @tanstack/react-query library for fetching facility data. The import statement for the custom hook has been removed, and the loading state tracking has been updated. Additionally, the default value for the emergency filter field has been changed from "--" to an empty string. The useFilters hook has also been updated to refine the handling of filter badges and introduced a new method for date filtering.

Changes

File Change Summary
src/components/Resource/ResourceFilter.tsx - Updated import from useTanStackQueryInstead to useQuery
- Modified default emergency filter value from "--" to ""
- Changed loading state handling from loading to isLoading for multiple queries
src/hooks/useFilters.tsx - Added dateRange method to badgeUtils
- Updated return statement in badgeUtils.range method for equal values

Assessment against linked issues

Objective Addressed Explanation
Clear all filter badge visibility [#9556] Unable to definitively confirm from the current changes if the badge visibility issue is resolved

Possibly Related PRs

  • Fix Resource Board Filtering Failure #9558: The changes in this PR involve modifications to query handling in the KanbanSection component, which is relevant to the main PR's updates on query hooks and data fetching processes in ResourceFilter.tsx. Both PRs focus on improving how queries are structured and managed.

Suggested Reviewers

  • rithviknishad

Poem

🐰 A query hop, a filter's dance,
Code refactored with rabbit's glance,
From TanStack to useQuery's embrace,
Clearing filters with elegant grace,
A coding leap of pure delight! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f47cf23 and fb925cd.

📒 Files selected for processing (1)
  • src/hooks/useFilters.tsx (1 hunks)
🔇 Additional comments (2)
src/hooks/useFilters.tsx (2)

146-146: Ensure consistent behavior when min/max values are equal.

Currently, when values[0] === values[1], the code returns an array with the single paramKey: paramKeys[0]. This effectively disregards the second param key. While this might be intended for the scenario of a single-value range, confirm that ignoring the second parameter key is indeed the desired outcome when handling a range filter (e.g., does the UI or documentation reference the min/max distinction in such a case?).


151-154: Good addition of dateRange method.

Introducing a dedicated method for date-based filtering helps maintain consistency with the existing range method. For clarity, consider adding a docstring or comment describing how the paramKey_after and paramKey_before parameters are used within downstream logic to ensure future maintainers understand this filtering approach.


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

netlify bot commented Dec 24, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 397c4b0
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67728d77f8bdaf000965378e
😎 Deploy Preview https://deploy-preview-9557--care-ohc.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
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 (2)
src/components/Resource/ResourceFilter.tsx (2)

43-51: Correct the "orginFacilityLoading" naming
The variable name appears to have a minor typo. Renaming it to originFacilityLoading would improve readability and consistency across the codebase.

-  const { loading: orginFacilityLoading } = useQuery(...)
+  const { loading: originFacilityLoading } = useQuery(...)

55-63: Confirm clarity on naming
resourceFacilityLoading might be slightly ambiguous since it refers specifically to the “approving facility.” Consider using a name such as approvingFacilityLoading for consistency.

-  const { loading: resourceFacilityLoading } = useQuery(routes.getAnyFacility, {
+  const { loading: approvingFacilityLoading } = useQuery(routes.getAnyFacility, {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b8f7a4 and cdce6fa.

📒 Files selected for processing (1)
  • src/components/Resource/ResourceFilter.tsx (3 hunks)
🔇 Additional comments (3)
src/components/Resource/ResourceFilter.tsx (3)

19-19: Switched to a new query hook
The use of useQuery is aligned with the updated codebase design. This replacement ensures consistency and leverages the newer hook’s maintained features.


34-34: Removed default value for the “emergency” filter
Changing the default emergency value from "--" to "" is a good way to avoid unintended filter application.


67-75: Good facility fetch pattern
The usage of useQuery to prefetch the assigned facility data and update the local state is correct and consistent. No issues identified.

@Mahendar0701 Mahendar0701 changed the title Fix: Clear All Filters Badge Visibility Fix: Clear All Filters Badge Visibility in Resource page Dec 24, 2024
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 (1)
src/components/Resource/ResourceFilter.tsx (1)

45-97: Consider refactoring duplicate facility query implementations.

The three facility query implementations share identical patterns and could be refactored into a reusable hook for better maintainability.

Consider creating a custom hook like this:

const useFacilityQuery = (facilityId: string, type: 'origin' | 'approving' | 'assigned') => {
  const { isLoading, data } = useQuery({
    queryKey: [routes.getAnyFacility.path, facilityId],
    queryFn: () => query(routes.getAnyFacility, {
      pathParams: { id: facilityId },
    }),
    enabled: facilityId !== undefined,
  });

  useEffect(() => {
    if (data) {
      setFilterState({
        [`${type}_facility_ref`]: facilityId === "" ? "" : data,
      });
    }
  }, [data, facilityId]);

  return { isLoading, data };
};

Usage:

const { isLoading: originFacilityLoading } = useFacilityQuery(
  filter.origin_facility,
  'origin'
);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0ae0a2 and c5b42a4.

📒 Files selected for processing (1)
  • src/components/Resource/ResourceFilter.tsx (4 hunks)
🔇 Additional comments (3)
src/components/Resource/ResourceFilter.tsx (3)

1-1: LGTM: Import changes align with recommended practices.

The switch to direct TanStack Query usage aligns with the documentation and previous review feedback.

Also applies to: 21-21


36-36: LGTM: Emergency filter default value updated.

The removal of "--" as default value for emergency filter aligns with the PR objective to improve filter behavior.


1-1: Verify implementation of "Clear all filters" badge visibility.

While the emergency filter default value has been addressed, I don't see changes related to the "Clear all filters" badge visibility mentioned in the PR objectives.

Let's check if this is implemented elsewhere:

✅ Verification successful

Let me gather more information about the "Clear all filters" badge visibility implementation.


Let me check the ResourceBadges component to understand the badge visibility implementation.


Let me try to find the useFilters hook with a different approach.


Let me check the useFilters hook implementation.


"Clear all filters" badge visibility is properly implemented

The "Clear all filters" badge visibility is already implemented in the FilterBadges component within the useFilters hook. The badge is shown when:

  • There are active filters (determined by activeFilters.length > 0)
  • Or when there are children components (children prop is present)

The implementation includes:

  • Automatic tracking of active filters
  • A "Clear all filters" button that appears when filters are active
  • Proper translation support via t("clear_all_filters")
  • Correct styling and positioning with the filter badges
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for files containing "Clear all filters" text or badge-related code
rg -i "clear all filters|clearallfilters" --type tsx --type ts

# Search for FiltersSlideover component definition
fd -e tsx -e ts FiltersSlideover

Length of output: 171


Script:

#!/bin/bash
# Check the FiltersSlideover component for badge-related code
cat src/CAREUI/interactive/FiltersSlideover.tsx

# Search for badge-related code in ResourceFilter and its directory
rg -i "badge|clear.*filter" src/components/Resource/

Length of output: 3402


Script:

#!/bin/bash
# Check the ResourceBadges component implementation
cat src/components/Resource/ResourceBadges.tsx

# Check the useFilters hook implementation
fd -e ts -e tsx useFilters.ts useFilters.tsx

Length of output: 2231


Script:

#!/bin/bash
# Find useFilters hook implementation
fd useFilters src/

# Check the FilterBadges component that's being used
rg -A 5 "export.*FilterBadges" 

Length of output: 78


Script:

#!/bin/bash
# Check the useFilters hook implementation
cat src/hooks/useFilters.tsx

# Look for FilterBadges component in Common components
rg -l "FilterBadges" src/components/Common/

Length of output: 9163

Copy link
Contributor

@Jacobjeevan Jacobjeevan left a comment

Choose a reason for hiding this comment

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

Other than that, lgtm

src/components/Resource/ResourceFilter.tsx Outdated Show resolved Hide resolved
@Jacobjeevan
Copy link
Contributor

No longer relevant.

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.

Clear all filter badge is visible even after all filters are cleared in Resource page
3 participants