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: Search Bar Reset #9867

Merged
merged 3 commits into from
Jan 10, 2025
Merged

Fix: Search Bar Reset #9867

merged 3 commits into from
Jan 10, 2025

Conversation

Jeffrin2005
Copy link
Contributor

@Jeffrin2005 Jeffrin2005 commented Jan 9, 2025

Proposed Changes

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

  • Performance Improvements
    • Enhanced caching mechanism for encounter list by excluding specific fields from cache.
    • Optimized query performance by preventing caching of name, encounter ID, and external identifier fields.

@Jeffrin2005 Jeffrin2005 requested a review from a team as a code owner January 9, 2025 17:54
Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

The pull request introduces a modification to the EncounterList component by updating the useFilters hook configuration. Specifically, a new cacheBlacklist property is added, which includes three keys: "name", "encounter_id", and "external_identifier". This change appears to be related to managing query parameter caching for the search functionality in the Encounters page.

Changes

File Change Summary
src/pages/Encounters/EncounterList.tsx Updated useFilters hook to include cacheBlacklist with specific keys to prevent caching of search-related parameters

Assessment against linked issues

Objective Addressed Explanation
Search Bar Reset [#9845]

Poem

🐰 A rabbit's tale of caching's might,
Where search terms dance, then take flight!
No more sticky queries to stay,
As filters clear the cached way
A hop, a skip, the search bar's free! 🔍

The poem playfully captures the essence of the cache blacklisting approach, suggesting that search terms will now be more transient and less likely to persist across different tabs or navigation actions.

Finishing Touches

  • 📝 Generate Docstrings

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 Jan 9, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit e339f6a
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67800fb70b04ec00084f138e
😎 Deploy Preview https://deploy-preview-9867--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.

@Jeffrin2005
Copy link
Contributor Author

@rithviknishad The search bar should be cleared, and the details should be shown when we switch and come back to the same tab. In this PR, it is just clearing the search fields. Just for clarification, in the screenshot, 'er' details should be shown when we switch and come back to the same tab, and 'er' in the search bar should also be cleared.
commit

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 9, 2025
@rithviknishad
Copy link
Member

The current changes solves the problem about resetting the blacklisted fields. Not sure if I understood your question right?

Do you mean when we switch between let's say, from "Name" to "Encounter ID" search, and when we switch back whether the previously searched Name should remain or disappear?

Yes, only one of "Name" XOR "Encounter ID" XOR "External ID" should be applied at any given time. Not multiple of them. Hence we can reset the ones as soon as we switch away.

@rithviknishad rithviknishad removed question Further information is requested needs-triage labels Jan 9, 2025
@Jeffrin2005
Copy link
Contributor Author

@rithviknishad
When we switch from "Name" to "Encounter ID".
Name tab: "ABC" → switch to Encounter ID → switch back → still shows "ABC" (Remain)
or
Name tab: "ABC" → switch to Encounter ID → switch back → empty/blank (Disappear)
Do we need to disappear the typed text in "Name" . Is this correct ?

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 9, 2025
@rithviknishad
Copy link
Member

rithviknishad commented Jan 9, 2025

Yup

Name tab: "ABC" → switch to Encounter ID → switch back → empty/blank (Disappear)

☝🏼 this is the desired behaviour

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/pages/Encounters/EncounterList.tsx (3)

Line range hint 316-332: Consider enhancing the search field clearing UX.

The current implementation clears all search fields at once. Consider these improvements:

  1. Add individual clear buttons for each search field
  2. Provide visual feedback when fields are cleared due to switching tabs
  3. Add a "restore previous search" option when switching back to a tab
 <Button
   variant="ghost"
   size="sm"
   className="w-full justify-start text-muted-foreground"
   onClick={() => {
     updateQuery({
       status,
       encounter_class: encounterClass,
       priority,
-      name: undefined,
-      encounter_id: undefined,
-      external_identifier: undefined,
+      [searchOptions.find(opt => opt.value)?.key]: undefined,
     });
-    clearSearch.value = true;
+    clearSearch.value = {
+      field: searchOptions.find(opt => opt.value)?.key,
+      previousValue: searchOptions.find(opt => opt.value)?.value,
+    };
   }}
 >

Line range hint 234-257: Improve search options accessibility and discoverability.

The search options include keyboard shortcuts, but they're not easily discoverable. Consider these improvements:

  1. Add tooltip to show keyboard shortcuts
  2. Include aria labels for screen readers
  3. Add visual indicators for keyboard shortcuts
 const searchOptions = [
   {
     key: "name",
     label: "Patient Name",
     type: "text" as const,
     placeholder: "Search by patient name",
     value: name || "",
     shortcutKey: "n",
+    ariaLabel: "Search by patient name, press Alt+N",
+    tooltip: "Alt+N",
   },
   {
     key: "encounter_id",
     label: "Encounter ID",
     type: "text" as const,
     placeholder: "Search by encounter ID",
     value: encounter_id || "",
     shortcutKey: "i",
+    ariaLabel: "Search by encounter ID, press Alt+I",
+    tooltip: "Alt+I",
   },
   {
     key: "external_identifier",
     label: "External ID",
     type: "text" as const,
     placeholder: "Search by external ID",
     value: external_identifier || "",
     shortcutKey: "e",
+    ariaLabel: "Search by external ID, press Alt+E",
+    tooltip: "Alt+E",
   },
 ];

Line range hint 182-196: Optimize data fetching for filter changes.

The current implementation might trigger multiple API calls when changing filters. Consider these optimizations:

  1. Debounce filter changes
  2. Add loading states for individual filters
  3. Implement request cancellation for superseded queries
 const { data: queryEncounters, isLoading } = useQuery<
   PaginatedResponse<Encounter>
 >({
   queryKey: ["encounters", facilityId, qParams],
   queryFn: query(routes.encounter.list, {
     queryParams: {
       ...buildQueryParams(status, facilityId, encounterClass, priority),
       name,
       external_identifier,
       limit: resultsPerPage,
       offset: ((qParams.page || 1) - 1) * resultsPerPage,
     },
   }),
+  staleTime: 30000, // Cache results for 30 seconds
+  keepPreviousData: true, // Show previous data while fetching
+  retry: false, // Don't retry failed requests
   enabled: !propEncounters && !encounter_id,
 });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 07bd473 and e339f6a.

📒 Files selected for processing (1)
  • src/pages/Encounters/EncounterList.tsx (1 hunks)
🔇 Additional comments (2)
src/pages/Encounters/EncounterList.tsx (2)

154-154: LGTM with suggestions for improvement.

The core change to prevent caching of search fields is implemented correctly. The suggestions above would enhance the user experience but aren't blocking issues.


154-154: Verify the implementation aligns with the discussed behavior.

The addition of cacheBlacklist prevents caching of search fields, which means they will be cleared when switching between search types. However, based on the PR discussion, there seems to be uncertainty about whether search fields should be retained or cleared when switching tabs.

Let's verify the current behavior:

✅ Verification successful

Implementation aligns with established codebase patterns

The cacheBlacklist implementation in EncounterList follows the consistent pattern used across the codebase where primary search fields are blacklisted to ensure they're cleared when switching views. This is the standard behavior implemented in other components like OrganizationFacilities, ResourceList, and FacilityUsers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any other instances of cacheBlacklist in the codebase
# to ensure consistent behavior across components
rg "cacheBlacklist" -A 5 -B 5

# Check the useFilters hook implementation to understand
# how cacheBlacklist affects the search state
ast-grep --pattern 'function useFilters($_) {
  $$$
}'

Length of output: 21316

@Jacobjeevan
Copy link
Contributor

@rithviknishad When we switch from "Name" to "Encounter ID". Name tab: "ABC" → switch to Encounter ID → switch back → still shows "ABC" (Remain) or Name tab: "ABC" → switch to Encounter ID → switch back → empty/blank (Disappear) Do we need to disappear the typed text in "Name" . Is this correct ?

#9851 is planning to address this in the SearchByMultipleFields btw.

cc: @rithviknishad

@rithviknishad
Copy link
Member

then this pr can be merged, lgtm

@rithviknishad rithviknishad removed question Further information is requested needs-triage labels Jan 10, 2025
@rithviknishad rithviknishad merged commit cf7dcc9 into ohcnetwork:develop Jan 10, 2025
22 of 23 checks passed
Copy link

@Jeffrin2005 Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search Bar Fails to Reset When Navigating Between Tabs
3 participants