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

Add Search Feature in Devices with name and location wise | Add Clear button in Location Search #10831

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

Rishith25
Copy link
Contributor

@Rishith25 Rishith25 commented Feb 26, 2025

Proposed Changes

Screenshots

image

image

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

    • Added a clear button in the location search component, allowing users to easily deselect a location.
    • Enhanced the devices list screen with integrated search and location filtering for more precise device queries.
  • UI Improvements

    • Updated the display message for no available locations with localized text.
    • Introduced an input field for search queries to improve user experience.
    • Streamlined the pagination layout to improve navigation through device listings.

@Rishith25 Rishith25 requested a review from a team as a code owner February 26, 2025 18:11
Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

The changes update two components. In the LocationSearch component, a clear button is added that uses new imports (CareIcon and Button) and updates the onSelect prop to accept null values. The "No locations found" message now uses the translation function. In the DevicesList component, a selectedLocation state is introduced, query keys and parameters are updated to incorporate search text and location filters, and the UI is enhanced with new Input and LocationSearch components along with updated pagination logic.

Changes

File Path Change Summary
src/components/.../LocationSearch.tsx Added imports for CareIcon and Button; updated onSelect prop signature to include null; added clear button with event propagation stop; updated "No locations found" to t() call.
src/pages/Facility/.../DevicesList.tsx Introduced selectedLocation state; modified query key and parameters to include qParams and resultsPerPage; added Input and LocationSearch components; updated pagination logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LocationSearch
    participant Parent
    User->>LocationSearch: Clicks clear button
    LocationSearch->>LocationSearch: Stops event propagation
    LocationSearch->>Parent: Calls onSelect(null)
    Parent->>Parent: Updates selectedLocation to null
    Parent->>API: Re-fetch devices with updated query parameters
Loading
sequenceDiagram
    participant User
    participant DevicesList
    participant API
    User->>DevicesList: Enters search text / selects location
    DevicesList->>DevicesList: Updates qParams and selectedLocation state
    DevicesList->>API: Fetches devices with new query parameters
Loading

Possibly related PRs

  • Fix : FacilityOrganizationSelector Displays Only First 15 Entries #10801: The changes in the main PR are related to the LocationSearch component's handling of location selection, which is directly connected to the selectedLocation state introduced in the retrieved PR's DevicesList component, as both involve managing location data.
  • Fix: Add a new list view to locations in the facility settings #10672: The changes in the main PR, specifically the modification of the onSelect prop type in the LocationSearchProps interface to accept null, are directly related to the introduction of the selectedLocation state variable in the retrieved PR, which also allows for a null value, indicating a connection in how location selection is managed.
  • Enhance LocationSearch: Use "instance" for search & Adjust Input Padding #10554: The changes in the main PR modify the onSelect prop type in the LocationSearchProps interface and enhance the LocationSearch component, while the retrieved PR also updates the LocationSearchProps interface but focuses on the mode property; thus, they are related through modifications to the same interface.

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a bunny with a code-filled heart,
Hopping through changes, a magical art.
Button clicks and queries, swift and neat,
Clearing selections with a nimble beat.
In lines of code I twirl and play,
Celebrating commits in a whimsical way!
🐇✨


📜 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 169fd58 and 550b560.

📒 Files selected for processing (1)
  • src/pages/Facility/settings/devices/DevicesList.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: Test
  • GitHub Check: OSSAR-Scan
  • GitHub Check: cypress-run (1)
🔇 Additional comments (6)
src/pages/Facility/settings/devices/DevicesList.tsx (6)

33-36: Good use of useFilters hook

Nice implementation of the useFilters hook with appropriate configuration. The cacheBlacklist for search parameters ensures that temporary search criteria don't persist in browser history.


29-31: Implementation handles location state properly

Good job maintaining both the selected location object for the UI component and updating the query parameter with just the location ID. This properly addresses the previous feedback while maintaining component requirements.

The implementation supports both setting and clearing the location filter, which provides a good user experience.

Also applies to: 71-76


59-67: Search implementation matches requirements

Well-implemented search functionality with immediate query updates. This correctly implements the single search input approach as requested in previous feedback.


57-86: Responsive design improvement

The UI layout works well on both mobile and desktop with proper stack/row adjustments. The design provides good component spacing and alignment.


108-108: Pagination simplification

Good refactoring to use the Pagination component directly without conditional rendering. This simplifies the code while maintaining the same functionality.


39-47:

❓ Verification inconclusive

Verify search and filter params are correctly handled by the API

The query parameters are correctly structured, but ensure the backend API properly handles these parameters, especially when they're undefined.


🏁 Script executed:

#!/bin/bash
# Check if the API accepts these query parameters correctly
# Look for the API handler for this endpoint

rg -A 10 "def list\(" --glob "*.py" | grep -A 3 "search_text\|current_location"

Length of output: 230


Action Required: Confirm Backend Handling of Optional Query Parameters

The query parameters in the current changeset are structured as intended, but please verify that the backend API (the device listing endpoint) correctly handles parameters like search_text and current_location, especially when they are undefined.

To assist in this verification, please run the following shell script to locate the API handler and inspect how these parameters are processed:

Once you’ve confirmed that the API properly defaults or handles these parameters when they’re undefined, please update the PR accordingly.


🏁 Script executed:

#!/bin/bash
# Locate Python files containing the device list handler and check for parameter usage.
fd -e py -x grep -H "def list(" {} \; | while read -r line; do
  file=$(echo "$line" | cut -d: -f1)
  echo "File: $file"
  rg -A 20 "def list\(" "$file" | grep -E "facility_id|search_text|current_location"
done

Length of output: 179


Action Required: Manual Verification of Backend Parameter Handling

The client-side code correctly structures the query parameters. However, our automated searches did not reveal the corresponding backend API handler details (i.e. how search_text and current_location are processed when undefined). Please manually verify that the endpoint invoked via deviceApi.list appropriately handles these optional parameters—ensuring that default values or proper filtering logic is applied when parameters are absent.

  • Confirm that the backend does not generate errors when search_text or current_location are undefined.
  • Check that any filtering related to these parameters behaves as expected.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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 Feb 26, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 550b560
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67caac95e646c60008d67515
😎 Deploy Preview https://deploy-preview-10831.preview.ohc.network
📱 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.

@Rishith25
Copy link
Contributor Author

@rithviknishad @Jacobjeevan Needed backend support care#2872

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/pages/Facility/settings/devices/DevicesList.tsx (1)

62-87: Implementation of the search and location filter UI is well executed.
The combination of Input for the device name search and LocationSearch for location filtering is straightforward, and resetting the page on search input change is a good user experience.

Consider adding a label or aria-label for the input to enhance accessibility for screen readers.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 41fc269 and b93543f.

📒 Files selected for processing (1)
  • src/pages/Facility/settings/devices/DevicesList.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: Test
  • GitHub Check: cypress-run (1)
🔇 Additional comments (7)
src/pages/Facility/settings/devices/DevicesList.tsx (7)

10-10: No issues with the new import of the Input component.
The usage is straightforward and aligns well with the UI library structure.


15-15: Importing LocationSearch appears valid and consistent.
No concerns regarding the dependency or import path.


20-20: The import of LocationList is correctly placed.
Ensuring strong typing for location data is a good practice here.


29-32: State variables for search and selected location look appropriate.
Having a nullable LocationList state helps manage scenarios where no location is selected.


37-44: Including searchQuery and selectedLocation in the queryKey is solid.
This ensures that the query automatically re-fetches and reflects changes in either state.


50-51: Neat parameter handling for registered_name and location.
Passing undefined when values are empty or null is a valid approach to avoid sending unwanted query parameters.


58-58: Well-structured layout modifications.
The updated classnames effectively maintain a responsive layout for the container.

@Rishith25
Copy link
Contributor Author

@rithviknishad @Jacobjeevan Backend PR got merged. Now this PR is Ready for review

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Feb 27, 2025
Copy link

Conflicts have been detected against the base branch. Please merge the base branch into your branch.
cc: @Rishith25

See: https://docs.ohc.network/docs/contributing#how-to-resolve-merge-conflicts

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/pages/Facility/settings/devices/DevicesList.tsx (2)

29-31: Consider storing just the location ID for improved stability.
Storing the entire LocationList object in state might lead to unnecessary re-renders or refetches whenever the object reference changes, even if the ID remains the same. Persisting only selectedLocation?.id is a simpler alternative unless the full object is needed elsewhere.


39-45: Avoid passing entire objects as query keys to prevent redundant refetches.
Keys like qParams and selectedLocation may trigger additional network requests if their references change frequently. Passing only stable representations (like qParams.page, qParams.search_text, etc., plus selectedLocation?.id) can help mitigate this.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 01960b9 and 6aca3b5.

📒 Files selected for processing (3)
  • public/locale/en.json (1 hunks)
  • src/components/Location/LocationSearch.tsx (4 hunks)
  • src/pages/Facility/settings/devices/DevicesList.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • public/locale/en.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Location/LocationSearch.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test
  • GitHub Check: cypress-run (1)
🔇 Additional comments (8)
src/pages/Facility/settings/devices/DevicesList.tsx (8)

10-10: All newly imported modules seem appropriate and consistent.
These imports appear to be correctly used later in the file. No concerns.

Also applies to: 14-14, 16-16, 21-21


33-36: Kudos on using a caching hook with a blacklist.
Using useFilters and blacklisting query params helps avoid cache key collisions. This is a neat approach to controlling unwanted caching behavior for search parameters.


59-59: Responsive layout changes look good.
This line adds helpful spacing and flex layout classes. No issues found.


63-65: Search input configuration is clean and user-friendly.
You have proper coherence with i18n for the placeholder, and onChange seamlessly updates qParams.search_text. Good job integrating with the debounced query.

Also applies to: 66-72


74-74: LocationSearch integration is straightforward and consistent.
Allowing null for onSelect effectively clears the selected location. This satisfies the requirement for single-input searching while also filtering by location when needed.

Also applies to: 75-83


86-92: "Add Device" button is well-placed and intuitive.
Linking to "/devices/create" is consistent if your routes handle facility context at or after creation. No concerns here.


114-114: Pagination usage is correctly integrated.
Connecting the total count to data?.count ensures accurate pagination. Implementation looks good.


49-52:

❓ Verification inconclusive

Confirm that offset resets to page 1 when new search filters are applied.
If qParams.page retains its previous value when search_text or current_location changes, users might land on an empty page. Verify that the pagination logic resets page to 1 on filter changes.


🏁 Script executed:

#!/bin/bash
# Searching for explicit reset of page to 1 upon search_text/current_location changes
rg -A 3 'updateQuery\(\{.*page:\s*1'

Length of output: 38


Action Required: Confirm Pagination Reset on Filter Changes

The current implementation calculates offset based on qParams.page without any explicit reset when the search filters (search_text or current_location) change. This could lead to scenarios where a user, upon updating the filters, might retain a non-first page value and consequently land on an empty result page.

  • Verify: Ensure that when search_text or current_location changes, the pagination is correctly reset by updating qParams.page to 1.
  • Review Location: Please inspect and confirm this logic in src/pages/Facility/settings/devices/DevicesList.tsx (around lines 49-52) and any related handlers or effects that might update the query parameters.

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/pages/Facility/settings/devices/DevicesList.tsx (1)

57-86: Debounce search to reduce rapid re-fetches.
Consider wrapping updateQuery with a debounce to avoid initiating frequent queries while typing, improving performance.

- onChange={(e) => {
-   updateQuery({ search_text: e.target.value });
- }}
+ onChange={debounce((e) => {
+   updateQuery({ search_text: e.target.value });
+ }, 300)}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6aca3b5 and 9d74521.

📒 Files selected for processing (1)
  • src/pages/Facility/settings/devices/DevicesList.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: Test
  • GitHub Check: OSSAR-Scan
  • GitHub Check: cypress-run (1)
🔇 Additional comments (10)
src/pages/Facility/settings/devices/DevicesList.tsx (10)

10-10: No issues with this import.
This addition is consistent with the existing UI framework usage.


14-14: LocationSearch import is valid.
No concerns here; it matches the usage below for location-based filtering.


16-16: Using useFilters.
Adopting a dedicated filtering hook is a good approach for handling pagination and query state.


21-21: Type import for LocationList.
This import is aligned with the state handling in selectedLocation.


29-31: State initialization is clear.
Initializing selectedLocation to null accommodates scenarios where no location is selected.


33-36: Proper use of useFilters.
Setting a default limit and blacklisting specific params is appropriate for this context.


39-39: Query key update.
Including all relevant parameters (facilityId, qParams, resultsPerPage) ensures consistent re-fetch.


43-46: Offset calculation.
Be mindful of edge cases if qParams.page is 0 or negative. Clamping the page to a minimum of 1 can prevent negative offsets.

- offset: (qParams.page - 1) * resultsPerPage,
+ offset: (Math.max(1, qParams.page) - 1) * resultsPerPage,

53-53: Styling adjustment.
The flex layout updates appear intentional and maintain responsiveness.


108-108: Pagination usage is correct.
Passing data?.count ?? 0 to the <Pagination> component aligns with the updated query approach.

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Feb 28, 2025
@Rishith25
Copy link
Contributor Author

@rithviknishad @Jacobjeevan Backend PR got merged can review this PR

@Rishith25 Rishith25 changed the title Add Search Feature in Devices with name and location wise Add Search Feature in Devices with name and location wise | Add Clear button in Location Search Mar 4, 2025
@Rishith25 Rishith25 requested a review from Jacobjeevan March 7, 2025 08:03
Jacobjeevan
Jacobjeevan previously approved these changes Mar 10, 2025
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.

Let's adjust the style. Right now the select looks like it's disabled (adjust the bg, maybe add a border so it looks similar to the search input).

image

Also adjust the trigger width in location search (you can look into shadcn's documentation and other examples of popover in the codebase on how to do this). Make sure to test the other components where LocationSearch is called.

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.

Add search feature for Devices | Add Clear button in Location Search
3 participants