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 20 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.
    • Added a selection option for search type (name or location) to refine device searches.
    • Streamlined the pagination layout to improve navigation through device listings.
    • Improved styling options in the location search component for better visual consistency.

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

Possibly related PRs

  • Location search fix #10450: The changes in the main PR enhance the LocationSearch component's functionality, while the retrieved PR modifies the query parameters within the same component, indicating a direct relationship at the code level.
  • Enhance LocationSearch: Use "instance" for search & Adjust Input Padding #10554: The changes in the main PR are related to the LocationSearch component's props and functionality, while the retrieved PR also modifies the LocationSearchProps interface, specifically the mode property, indicating a direct connection at the code level.
  • Fix: Duplicate network requests in Patient Details page #9297: The changes in the main PR regarding the LocationSearch component, specifically the updates to the onSelect prop type and the introduction of the selectedLocation state in the DevicesList component, indicate a direct relationship as both involve handling location selection logic.

Suggested labels

needs review, needs testing

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!
🐇✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ 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 484f3de
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67d5a6b8954f600008e1e6fb
😎 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

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.

@nihal467
Copy link
Member

nihal467 commented Mar 10, 2025

image
image

  • Keeping the name as a searchable text box and the location as a dropdown selector is not consistent with our platform's design. We should combine them into one search area
  • Align it with the encounter page search, where users type to filter data and select name or location from badges within the search component.

@Rishith25 when working on elements commonly used across the platform, ensure UI consistency

can you share the ETD to get this done

@nihal467 nihal467 added question Further information is requested changes required and removed needs testing needs review labels Mar 10, 2025
@Rishith25
Copy link
Contributor Author

image image

  • Keeping the name as a searchable text box and the location as a dropdown selector is not consistent with our platform's design. We should combine them into one search area
  • Align it with the encounter page search, where users type to filter data and select name or location from badges within the search component.

@Rishith25 when working on elements commonly used across the platform, ensure UI consistency

can you share the ETD to get this done

Hey @nihal467
On using SearchByMultipleField Component we cant show location list to select a location. If we use SearchByMultipleField component then we have to add a location_id as field becz we have to pass location_id as queryparam in api call.

Should i add location_id as search filed ??

cc: @rithviknishad @Jacobjeevan

@rithviknishad
Copy link
Member

@Rishith25 could you rethink the design? 🤔 i don't think this looks good enough to be merged;

@rithviknishad rithviknishad removed question Further information is requested needs-triage labels Mar 10, 2025
@Rishith25
Copy link
Contributor Author

Rishith25 commented Mar 12, 2025

@rithviknishad This is the design given by @vivekrajuv18.
Could you please confirm to proceed with or not

image

image
image

@github-actions github-actions bot added needs-triage question Further information is requested labels Mar 12, 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 (2)
src/components/Location/LocationSearch.tsx (1)

68-82: Consider adding an accessibility label for the clear button.
Invoking onSelect(null) to clear the selection is correct, and using stopPropagation prevents unintended parent event triggers. However, adding an aria-label (e.g., aria-label="Clear location") to the button would improve accessibility for screen readers.

 <Button
   onClick={(e) => {
     e.stopPropagation();
     onSelect(null);
   }}
+  aria-label="Clear location"
   variant="ghost"
   className="hover:bg-transparent"
>
   <CareIcon icon="l-times" className="h-4 w-4" />
</Button>
src/pages/Facility/settings/devices/DevicesList.tsx (1)

62-84: Dropdown approach for switching search modes.
Toggling between "name" and "location" effectively zeroes out the other field in updateQuery. This is straightforward, though it discards the user’s prior input. If that’s intended, it’s fine. Otherwise, consider caching text inputs separately for a smoother user experience when switching back and forth.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 010199f and 1ab30ea.

📒 Files selected for processing (2)
  • src/components/Location/LocationSearch.tsx (4 hunks)
  • src/pages/Facility/settings/devices/DevicesList.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test
  • GitHub Check: cypress-run (1)
🔇 Additional comments (17)
src/components/Location/LocationSearch.tsx (4)

3-9: Additional imports look good.
These newly added imports for useTranslation, cn, CareIcon, and Button are well-structured and serve the updated functionality cleanly.


31-35: Flexible onSelect signature and new className prop.
Allowing null in the onSelect callback properly supports a “clear selected location” action. The added className prop is beneficial for layout customization.


43-45: Correct integration of i18n.
Using useTranslation with the t function is consistent and ensures all user-facing text can be localized.


61-64: Use of cn utility for class management.
This is a good approach to handle conditional classes and keep the code expressive and maintainable.

src/pages/Facility/settings/devices/DevicesList.tsx (13)

10-17: Good choice of UI components.
Importing Input and Select from the ui library helps maintain a consistent design system.


21-21: Integration of LocationSearch.
Bringing in the LocationSearch component is aligned with the new location-based search requirement.


23-23: Custom hook usage is appreciated.
useFilters is an elegant way to manage query parameters, improving code modularity.


28-28: Location type import.
Importing LocationList ensures strong typing for the selectedLocation state and related logic.


36-39: Well-defined states for search.
Separating searchType and selectedLocation is logical, supporting either a name or location-based query.


41-44: useFilters configuration looks solid.
Providing a cache blacklist for search_text and current_location prevents stale query states.


47-47: Enhanced queryKey usage.
Including qParams and resultsPerPage in the query key ensures consistent caching and re-fetch behavior.


51-55: Refined query parameters.
Passing search_text, current_location, and search_type to the API is clear. Resetting offset to (page - 1) * resultsPerPage is typical for pagination.


86-113: Conditional rendering between Input and LocationSearch.
This is a clean approach to adapt the form to the current search type. Good job resetting the complementary field in updateQuery to prevent conflicting search params.


114-121: "Add Device" button logic.
Linking to the device creation page is consistent with the usual workflow. No issues here.


130-130: Responsive grid layout.
Updating the className ensures the devices are presented in a crisp, grid-based approach.


136-137: User feedback on empty device list.
Adding this fallback Card with a clear message helps inform users that no devices are available.


143-143: Pagination usage is well-integrated.
Passing totalCount from the fetched data ensures correct pagination, with minimal overhead.

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)
src/components/Location/LocationSearch.tsx (1)

70-81: Consider improving button accessibility

The clear button implementation looks good, but consider adding an aria-label to improve accessibility.

<Button
  onClick={(e) => {
    e.stopPropagation();
    onSelect(null);
  }}
  variant="ghost"
  className="hover:bg-transparent"
+ aria-label="Clear location selection"
>
  <CareIcon icon="l-times" className="h-4 w-4" />
</Button>
src/pages/Facility/settings/devices/DevicesList.tsx (2)

87-115: Consider extracting common styling to reduce duplication

The search input and location search components have similar styling. Consider extracting common styles to reduce duplication.

// At the top of the component
+ const searchInputClass = "w-full border border-gray-300 rounded-lg px-3 py-2 text-sm sm:text-base shadow-sm focus:ring-2 focus:ring-primary focus:border-primary rounded-l-none";

// Then in the render
<Input
  placeholder={t("search_by_name")}
  value={qParams.search_text || ""}
  onChange={(e) => {
    updateQuery({
      search_text: e.target.value,
      current_location: "",
    });
    setSelectedLocation(null);
  }}
- className="w-full h-9 border border-gray-300 rounded-lg px-3 py-2 text-sm sm:text-base shadow-sm focus:ring-2 focus:ring-primary focus:border-primary rounded-l-none"
+ className={`h-9 ${searchInputClass}`}
/>

// And
<LocationSearch
  facilityId={facilityId}
  onSelect={(location: LocationList | null) => {
    updateQuery({
      current_location: location?.id || "",
      search_text: "",
    });
    setSelectedLocation(location);
  }}
  value={selectedLocation}
- className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm sm:text-base shadow-sm focus:ring-2 focus:ring-primary focus:border-primary rounded-l-none"
+ className={searchInputClass}
/>

138-138: Make existence check more explicit

Consider making the array existence check more explicit for better readability.

- {data?.results?.length ? (
+ {data?.results?.length > 0 ? (
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ab30ea and 484f3de.

📒 Files selected for processing (2)
  • src/components/Location/LocationSearch.tsx (4 hunks)
  • src/pages/Facility/settings/devices/DevicesList.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (10)
src/components/Location/LocationSearch.tsx (5)

5-9: Great addition of clear button functionality!

The imports for cn, CareIcon, and Button support the new clear button feature, improving usability by allowing users to reset their location selection.


31-34: Good type definition updates

Updating the onSelect function to accept null enables the clear functionality, and adding the optional className prop improves component reusability.


60-63: Improved styling with cn utility

Using the cn utility for class composition is a good practice, allowing flexible styling and component customization while maintaining readability.


84-84: Good PopoverContent width constraints

Setting min and max widths on the PopoverContent improves the user experience by ensuring the dropdown is neither too narrow nor too wide.


92-92: Proper internationalization for empty state message

Using the translation function for the "No locations found" message is a good practice for maintaining consistent internationalization across the application.

src/pages/Facility/settings/devices/DevicesList.tsx (5)

36-44: Good implementation of search type and location filtering

The state management for search type and location filtering is well-implemented. Using useFilters hook with appropriate caching configuration addresses the previous feedback about page reset when searching.


47-58: Comprehensive query parameters for search functionality

The query parameters now correctly include search text, location, and search type, enabling the backend to filter results appropriately. Including these parameters in the query key ensures proper cache invalidation when search criteria change.


69-86: Well-implemented search type selector

The search type selector is well-implemented with proper state management. When switching between search types, it correctly clears the other search parameter and resets the location selection.


132-151: Improved layout and pagination

The grid layout provides a good responsive experience, and the simplified pagination logic using the Pagination component from useFilters is clean and maintainable.


104-110:

❓ Verification inconclusive

Verify API behavior with empty location

Ensure the backend API correctly handles an empty string for current_location when clearing the location selection.


🏁 Script executed:

#!/bin/bash
# Check how the API handles empty location parameter
rg "current_location.*=.*\"\"" -g "*.ts*" -g "*.js*" -A 5 -B 5

Length of output: 62


Manual Verification Required: Confirm API Handling for Empty current_location

The code in src/pages/Facility/settings/devices/DevicesList.tsx now sends an empty string ("") for current_location when no location is selected. Our automated search for references confirming the backend's handling of this empty value did not return any conclusive evidence.

Please ensure that:

  • The backend API correctly interprets an empty string for current_location (e.g., treats it as a clear or unset state).
  • There is either an automated test or manual confirmation verifying that the API does not return errors or unexpected behavior when receiving an empty current_location.

Current snippet for review:

onSelect={(location: LocationList | null) => {
  updateQuery({
    current_location: location?.id || "",
    search_text: "",
  });
  setSelectedLocation(location);
}}

Kindly perform manual verification of the API behavior if automated tests are lacking.

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
4 participants