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: Loses focus on User Search in users tab #9500

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

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Dec 19, 2024

Proposed Changes

@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

Summary by CodeRabbit

  • New Features

    • Enhanced user interface with a search functionality for filtering users by username.
    • Introduced a tabbed interface allowing users to switch between Card and List views.
    • Improved loading state handling in the Manage Users and Facility Users components.
    • Added new components: Tabs, TabsList, TabsTrigger, and TabsContent for better navigation.
  • Bug Fixes

    • Ensured the pagination component receives a valid number when user data is unavailable.
    • Streamlined the UserListView component by removing unnecessary props and functionality.

@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner December 19, 2024 17:48
Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces modifications to the ManageUsers, FacilityUsers, and UserListView components. Key changes include enhancements to loading state handling, the addition of search functionality, and a tabbed interface for user views. The variable usersList is conditionally assigned based on loading states, and the pagination component is updated to ensure valid counts. The UserListView component is streamlined by removing search and tab handling, focusing solely on displaying user data.

Changes

File Change Summary
src/components/Users/ManageUsers.tsx - Enhanced loading state handling with conditional usersList assignment
- Updated Pagination component's totalCount prop
- Added SearchByMultipleFields and Tabs components for user filtering and view toggling
src/components/Facility/FacilityUsers.tsx - Added CareIcon, Loading, Tabs, and SearchByMultipleFields imports
- Improved loading state management for usersList variable
- Introduced layout changes with SearchByMultipleFields and Tabs for user interaction
src/components/Users/UserListAndCard.tsx - Removed onSearch, searchValue, and onTabChange props from UserListViewProps
- Simplified component by eliminating SearchInput and Tabs from rendering
package.json - Added dependency @radix-ui/react-tabs version ^1.1.2
src/components/ui/tabs.tsx - Introduced new tab interface components: Tabs, TabsList, TabsTrigger, and TabsContent

Assessment against linked issues

Objective Addressed Explanation
Maintain search bar focus during screen rebuilds [#9398] The provided changes do not clarify if the search bar maintains focus after screen rebuilds.

Possibly related PRs

  • Fixed Add a better search UI for patients index page #8691 #8834: The main PR enhances the user interface and search functionality in the ManageUsers component, which is related to the introduction of the SearchByMultipleFields component in the FacilityUsers component, indicating a shared focus on improving search capabilities across user management interfaces.
  • Update for List View in Shifting from Gird LayOut to List Layout #8882: The changes in the main PR regarding the ManageUsers component's search functionality and UI enhancements are relevant to the updates made in the UserListView component, which also involves modifications to search and display logic.
  • Fix : Advanced Filters Autofilling on Revisit to Patient Tab #9251: The main PR's updates to the ManagePatients component, particularly in handling phone numbers and filter management, relate to the changes made in the PatientFilter component, which also focuses on improving filter functionality and user experience.
  • Search UI for discharge patients #9320: The main PR's introduction of the SearchByMultipleFields component for improved search functionality in the DischargedPatientsList component aligns with the enhancements made in the FacilityList component, which also incorporates the new search UI.
  • New Patient Search and Register UI #9400: The main PR's focus on enhancing the patient registration UI and search functionality connects with the updates made in the PatientRegistration component, which also aims to improve user interaction and data handling.

Suggested labels

needs review, tested, good to merge

Suggested reviewers

  • rithviknishad
  • Jacobjeevan
  • nihal467

Poem

🐰 Hopping through code with glee,
Loading states now dance so free!
Pagination's count, no longer null,
Our Users page, no longer dull!
Rabbit's magic makes UI shine bright! 🌟


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 19, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 05048de
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/676ad7aba99cce00080d1a3f
😎 Deploy Preview https://deploy-preview-9500--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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 213e114 and d97b99c.

📒 Files selected for processing (1)
  • src/components/Users/UserListAndCard.tsx (2 hunks)
🔇 Additional comments (1)
src/components/Users/UserListAndCard.tsx (1)

3-3: LGTM: Clean import addition

The useEffect import is properly placed with other React imports.

src/components/Users/UserListAndCard.tsx Outdated Show resolved Hide resolved
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 (4)
src/components/Form/SearchInput.tsx (4)

26-36: Add JSDoc documentation for the component.

The component's props and behavior should be documented for better maintainability. Consider adding JSDoc comments explaining the purpose of each prop, especially secondary and hotkey related props.

+/**
+ * A search input component with debounce, keyboard shortcuts, and focus management.
+ * @param props.debouncePeriod - Delay in ms before triggering onChange (default: 500)
+ * @param props.secondary - When true, disables global keyboard shortcuts
+ * @param props.hotkey - Custom keyboard shortcut keys
+ * @param props.hotkeyIcon - Custom keyboard shortcut icon
+ */
const SearchInput = forwardRef<HTMLInputElement, SearchInputProps>(

37-48: Use optional chaining for the onChange callback.

The onChange callback should use optional chaining for better safety.

-          () => onChange && onChange({ name, value: value || "" }),
+          () => onChange?.({ name, value: value || "" }),
🧰 Tools
🪛 Biome (1.9.4)

[error] 43-43: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


68-80: Consider extracting keyboard shortcuts into constants.

For better maintainability and reusability, consider extracting the keyboard shortcuts into named constants.

+const KEYBOARD_SHORTCUTS = {
+  CLEAR: ["Escape"],
+  FOCUS: {
+    MAC: ["Meta", "K"],
+    WINDOWS: ["Control", "K"]
+  }
+} as const;

useKeyboardShortcut(
-  ["Escape"],
+  KEYBOARD_SHORTCUTS.CLEAR,
  () => {

106-112: Fix the closing tag indentation.

There's a minor formatting issue with the closing tag of the trailing focused element.

         <div className="absolute inset-y-0 right-0 hidden gap-1 py-1.5 pr-1.5 md:flex">
           <kbd className="inline-flex items-center rounded border border-secondary-200 bg-white px-2 font-sans text-sm font-medium text-secondary-500">
             Esc
           </kbd>
-          </div>
+        </div>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d97b99c and ba602c0.

📒 Files selected for processing (2)
  • src/components/Form/SearchInput.tsx (2 hunks)
  • src/components/Users/UserListAndCard.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Users/UserListAndCard.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/Form/SearchInput.tsx

[error] 43-43: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (3)
src/components/Form/SearchInput.tsx (3)

49-55: LGTM! Focus management is well-implemented.

The focus management implementation properly handles:

  • Both forwarded and internal refs
  • Platform-specific keyboard shortcuts (Meta for Mac, Control for Windows)
  • Secondary mode to disable global shortcuts

57-66: LGTM! Keyboard shortcut UI is accessible and platform-aware.

The implementation properly handles:

  • Platform-specific shortcut display
  • Semantic HTML with kbd elements
  • Consistent styling

26-36: Verify the focus retention in the User Search.

The implementation looks correct for fixing the focus loss issue. The component now properly handles ref forwarding and focus management. Please verify that:

  1. Focus is retained when the search value changes
  2. Focus works correctly with keyboard shortcuts
  3. Focus behavior is consistent across different browsers

Also applies to: 89-89

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/Form/SearchInput.tsx (3)

46-46: Consider optional chaining for cleaner code.

Static analysis suggests using optional chaining instead of “onChange && onChange(…)”. This yields slightly cleaner, more idiomatic TypeScript.

Proposed change for line 46:

- onChange && onChange({ name, value: value || "" });
+ onChange?.({ name, value: value || "" });
🧰 Tools
🪛 Biome (1.9.4)

[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 eslint

[error] 46-46: Delete ··

(prettier/prettier)


93-101: Extract repeated keyboard shortcut UI.

You are displaying the hotkey with a similar inline “kbd” element. Consider extracting a small, reusable keyboard shortcut UI or component to ensure consistency throughout the codebase and reduce duplication.

🧰 Tools
🪛 eslint

[error] 93-93: Delete ··

(prettier/prettier)


[error] 94-94: Replace ············ with ··········

(prettier/prettier)


[error] 95-95: Delete ··

(prettier/prettier)


[error] 96-96: Delete ··

(prettier/prettier)


[error] 97-97: Replace ·················· with ················

(prettier/prettier)


[error] 98-98: Delete ··

(prettier/prettier)


[error] 99-99: Delete ··

(prettier/prettier)


[error] 100-100: Replace ············ with ··········

(prettier/prettier)


[error] 101-101: Delete ··

(prettier/prettier)


26-116: Address lint warnings regarding indentation.

A large number of “prettier/prettier” errors were flagged, mostly related to indentation. Please format the code consistently to adhere to Prettier rules, ensuring a cleaner diff and consistency across the codebase.

🧰 Tools
🪛 Biome (1.9.4)

[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 eslint

[error] 26-26: Delete ··

(prettier/prettier)


[error] 27-27: Delete ··

(prettier/prettier)


[error] 28-28: Delete ··

(prettier/prettier)


[error] 29-29: Delete ··

(prettier/prettier)


[error] 30-30: Delete ··

(prettier/prettier)


[error] 31-31: Delete ··

(prettier/prettier)


[error] 32-32: Delete ··

(prettier/prettier)


[error] 33-33: Delete ··

(prettier/prettier)


[error] 34-34: Delete ··

(prettier/prettier)


[error] 35-35: Delete ··

(prettier/prettier)


[error] 36-36: Replace ···· with ··

(prettier/prettier)


[error] 37-37: Replace ······ with ····

(prettier/prettier)


[error] 38-38: Delete ··

(prettier/prettier)


[error] 39-39: Replace ··const·internalRef·=·useRef<HTMLInputElement>(null);· with const·internalRef·=·useRef<HTMLInputElement>(null);

(prettier/prettier)


[error] 40-40: Delete ··

(prettier/prettier)


[error] 41-41: Delete ··

(prettier/prettier)


[error] 42-42: Delete ··

(prettier/prettier)


[error] 43-43: Delete ··

(prettier/prettier)


[error] 44-44: Delete ··

(prettier/prettier)


[error] 45-45: Delete ··

(prettier/prettier)


[error] 46-46: Delete ··

(prettier/prettier)


[error] 47-47: Delete ··

(prettier/prettier)


[error] 48-48: Delete ··

(prettier/prettier)


[error] 49-49: Delete ··

(prettier/prettier)


[error] 50-50: Delete ··

(prettier/prettier)


[error] 51-51: Replace ······ with ····

(prettier/prettier)


[error] 52-52: Delete ··

(prettier/prettier)


[error] 53-53: Delete ··

(prettier/prettier)


[error] 54-54: Replace ······ with ····

(prettier/prettier)


[error] 55-55: Delete ··

(prettier/prettier)


[error] 56-56: Delete ··

(prettier/prettier)


[error] 57-57: Replace ·········· with ········

(prettier/prettier)


[error] 58-58: Delete ··

(prettier/prettier)


[error] 59-59: Delete ··

(prettier/prettier)


[error] 60-60: Delete ··

(prettier/prettier)


[error] 61-61: Delete ··

(prettier/prettier)


[error] 62-62: Delete ··

(prettier/prettier)


[error] 63-63: Delete ··

(prettier/prettier)


[error] 64-64: Delete ··

(prettier/prettier)


[error] 65-65: Delete ··

(prettier/prettier)


[error] 66-66: Delete ··

(prettier/prettier)


[error] 67-67: Delete ··

(prettier/prettier)


[error] 68-68: Delete ··

(prettier/prettier)


[error] 69-69: Delete ··

(prettier/prettier)


[error] 70-70: Delete ··

(prettier/prettier)


[error] 71-71: Replace ·········· with ········

(prettier/prettier)


[error] 72-72: Delete ··

(prettier/prettier)


[error] 73-73: Delete ··

(prettier/prettier)


[error] 74-74: Replace ·········· with ········

(prettier/prettier)


[error] 75-75: Delete ··

(prettier/prettier)


[error] 76-76: Replace ······ with ····

(prettier/prettier)


[error] 77-77: Delete ··

(prettier/prettier)


[error] 78-78: Delete ··

(prettier/prettier)


[error] 79-79: Delete ··

(prettier/prettier)


[error] 80-80: Replace ·········· with ········

(prettier/prettier)


[error] 81-81: Delete ··

(prettier/prettier)


[error] 82-82: Delete ··

(prettier/prettier)


[error] 83-83: Delete ··

(prettier/prettier)


[error] 84-84: Delete ··

(prettier/prettier)


[error] 85-85: Delete ··

(prettier/prettier)


[error] 86-86: Delete ··

(prettier/prettier)


[error] 87-87: Delete ··

(prettier/prettier)


[error] 88-88: Delete ··

(prettier/prettier)


[error] 89-89: Delete ··

(prettier/prettier)


[error] 90-90: Delete ··

(prettier/prettier)


[error] 91-91: Delete ··

(prettier/prettier)


[error] 92-92: Replace ·········· with ········

(prettier/prettier)


[error] 93-93: Delete ··

(prettier/prettier)


[error] 94-94: Replace ············ with ··········

(prettier/prettier)


[error] 95-95: Delete ··

(prettier/prettier)


[error] 96-96: Delete ··

(prettier/prettier)


[error] 97-97: Replace ·················· with ················

(prettier/prettier)


[error] 98-98: Delete ··

(prettier/prettier)


[error] 99-99: Delete ··

(prettier/prettier)


[error] 100-100: Replace ············ with ··········

(prettier/prettier)


[error] 101-101: Delete ··

(prettier/prettier)


[error] 102-102: Delete ··

(prettier/prettier)


[error] 103-103: Delete ··

(prettier/prettier)


[error] 104-104: Delete ··

(prettier/prettier)


[error] 105-105: Delete ··

(prettier/prettier)


[error] 106-106: Delete ··

(prettier/prettier)


[error] 107-107: Delete ··

(prettier/prettier)


[error] 108-108: Delete ··

(prettier/prettier)


[error] 109-109: Delete ··

(prettier/prettier)


[error] 110-110: Delete ··

(prettier/prettier)


[error] 111-111: Replace ········ with ······

(prettier/prettier)


[error] 112-112: Delete ··

(prettier/prettier)


[error] 113-113: Delete ··

(prettier/prettier)


[error] 114-114: Delete ··

(prettier/prettier)


[error] 115-115: Delete ··

(prettier/prettier)


[error] 116-116: Delete ··

(prettier/prettier)

🪛 GitHub Check: lint

[failure] 26-26:
Delete ··


[failure] 27-27:
Delete ··


[failure] 28-28:
Delete ··


[failure] 29-29:
Delete ··


[failure] 30-30:
Delete ··


[failure] 31-31:
Delete ··


[failure] 32-32:
Delete ··


[failure] 33-33:
Delete ··


[failure] 34-34:
Delete ··


[failure] 35-35:
Delete ··

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba602c0 and 84181ec.

📒 Files selected for processing (1)
  • src/components/Form/SearchInput.tsx (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/Form/SearchInput.tsx

[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 eslint
src/components/Form/SearchInput.tsx

[error] 26-26: Delete ··

(prettier/prettier)


[error] 27-27: Delete ··

(prettier/prettier)


[error] 28-28: Delete ··

(prettier/prettier)


[error] 29-29: Delete ··

(prettier/prettier)


[error] 30-30: Delete ··

(prettier/prettier)


[error] 31-31: Delete ··

(prettier/prettier)


[error] 32-32: Delete ··

(prettier/prettier)


[error] 33-33: Delete ··

(prettier/prettier)


[error] 34-34: Delete ··

(prettier/prettier)


[error] 35-35: Delete ··

(prettier/prettier)


[error] 36-36: Replace ···· with ··

(prettier/prettier)


[error] 37-37: Replace ······ with ····

(prettier/prettier)


[error] 38-38: Delete ··

(prettier/prettier)


[error] 39-39: Replace ··const·internalRef·=·useRef<HTMLInputElement>(null);· with const·internalRef·=·useRef<HTMLInputElement>(null);

(prettier/prettier)


[error] 40-40: Delete ··

(prettier/prettier)


[error] 41-41: Delete ··

(prettier/prettier)


[error] 42-42: Delete ··

(prettier/prettier)


[error] 43-43: Delete ··

(prettier/prettier)


[error] 44-44: Delete ··

(prettier/prettier)


[error] 45-45: Delete ··

(prettier/prettier)


[error] 46-46: Delete ··

(prettier/prettier)


[error] 47-47: Delete ··

(prettier/prettier)


[error] 48-48: Delete ··

(prettier/prettier)


[error] 49-49: Delete ··

(prettier/prettier)


[error] 50-50: Delete ··

(prettier/prettier)


[error] 51-51: Replace ······ with ····

(prettier/prettier)


[error] 52-52: Delete ··

(prettier/prettier)


[error] 53-53: Delete ··

(prettier/prettier)


[error] 54-54: Replace ······ with ····

(prettier/prettier)


[error] 55-55: Delete ··

(prettier/prettier)


[error] 56-56: Delete ··

(prettier/prettier)


[error] 57-57: Replace ·········· with ········

(prettier/prettier)


[error] 58-58: Delete ··

(prettier/prettier)


[error] 59-59: Delete ··

(prettier/prettier)


[error] 60-60: Delete ··

(prettier/prettier)


[error] 61-61: Delete ··

(prettier/prettier)


[error] 62-62: Delete ··

(prettier/prettier)


[error] 63-63: Delete ··

(prettier/prettier)


[error] 64-64: Delete ··

(prettier/prettier)


[error] 65-65: Delete ··

(prettier/prettier)


[error] 66-66: Delete ··

(prettier/prettier)


[error] 67-67: Delete ··

(prettier/prettier)


[error] 68-68: Delete ··

(prettier/prettier)


[error] 69-69: Delete ··

(prettier/prettier)


[error] 70-70: Delete ··

(prettier/prettier)


[error] 71-71: Replace ·········· with ········

(prettier/prettier)


[error] 72-72: Delete ··

(prettier/prettier)


[error] 73-73: Delete ··

(prettier/prettier)


[error] 74-74: Replace ·········· with ········

(prettier/prettier)


[error] 75-75: Delete ··

(prettier/prettier)


[error] 76-76: Replace ······ with ····

(prettier/prettier)


[error] 77-77: Delete ··

(prettier/prettier)


[error] 78-78: Delete ··

(prettier/prettier)


[error] 79-79: Delete ··

(prettier/prettier)


[error] 80-80: Replace ·········· with ········

(prettier/prettier)


[error] 81-81: Delete ··

(prettier/prettier)


[error] 82-82: Delete ··

(prettier/prettier)


[error] 83-83: Delete ··

(prettier/prettier)


[error] 84-84: Delete ··

(prettier/prettier)


[error] 85-85: Delete ··

(prettier/prettier)


[error] 86-86: Delete ··

(prettier/prettier)


[error] 87-87: Delete ··

(prettier/prettier)


[error] 88-88: Delete ··

(prettier/prettier)


[error] 89-89: Delete ··

(prettier/prettier)


[error] 90-90: Delete ··

(prettier/prettier)


[error] 91-91: Delete ··

(prettier/prettier)


[error] 92-92: Replace ·········· with ········

(prettier/prettier)


[error] 93-93: Delete ··

(prettier/prettier)


[error] 94-94: Replace ············ with ··········

(prettier/prettier)


[error] 95-95: Delete ··

(prettier/prettier)


[error] 96-96: Delete ··

(prettier/prettier)


[error] 97-97: Replace ·················· with ················

(prettier/prettier)


[error] 98-98: Delete ··

(prettier/prettier)


[error] 99-99: Delete ··

(prettier/prettier)


[error] 100-100: Replace ············ with ··········

(prettier/prettier)


[error] 101-101: Delete ··

(prettier/prettier)


[error] 102-102: Delete ··

(prettier/prettier)


[error] 103-103: Delete ··

(prettier/prettier)


[error] 104-104: Delete ··

(prettier/prettier)


[error] 105-105: Delete ··

(prettier/prettier)


[error] 106-106: Delete ··

(prettier/prettier)


[error] 107-107: Delete ··

(prettier/prettier)


[error] 108-108: Delete ··

(prettier/prettier)


[error] 109-109: Delete ··

(prettier/prettier)


[error] 110-110: Delete ··

(prettier/prettier)


[error] 111-111: Replace ········ with ······

(prettier/prettier)


[error] 112-112: Delete ··

(prettier/prettier)


[error] 113-113: Delete ··

(prettier/prettier)


[error] 114-114: Delete ··

(prettier/prettier)


[error] 115-115: Delete ··

(prettier/prettier)


[error] 116-116: Delete ··

(prettier/prettier)

🪛 GitHub Check: lint
src/components/Form/SearchInput.tsx

[failure] 26-26:
Delete ··


[failure] 27-27:
Delete ··


[failure] 28-28:
Delete ··


[failure] 29-29:
Delete ··


[failure] 30-30:
Delete ··


[failure] 31-31:
Delete ··


[failure] 32-32:
Delete ··


[failure] 33-33:
Delete ··


[failure] 34-34:
Delete ··


[failure] 35-35:
Delete ··

🔇 Additional comments (4)
src/components/Form/SearchInput.tsx (4)

26-36: Good use of forwardRef for improved focus handling.

Forwarding the ref allows external components to focus the input directly and effectively addresses the focus loss issues. This is aligned with React’s recommended approach and should help maintain focus on re-renders.

🧰 Tools
🪛 eslint

[error] 26-26: Delete ··

(prettier/prettier)


[error] 27-27: Delete ··

(prettier/prettier)


[error] 28-28: Delete ··

(prettier/prettier)


[error] 29-29: Delete ··

(prettier/prettier)


[error] 30-30: Delete ··

(prettier/prettier)


[error] 31-31: Delete ··

(prettier/prettier)


[error] 32-32: Delete ··

(prettier/prettier)


[error] 33-33: Delete ··

(prettier/prettier)


[error] 34-34: Delete ··

(prettier/prettier)


[error] 35-35: Delete ··

(prettier/prettier)


[error] 36-36: Replace ···· with ··

(prettier/prettier)

🪛 GitHub Check: lint

[failure] 26-26:
Delete ··


[failure] 27-27:
Delete ··


[failure] 28-28:
Delete ··


[failure] 29-29:
Delete ··


[failure] 30-30:
Delete ··


[failure] 31-31:
Delete ··


[failure] 32-32:
Delete ··


[failure] 33-33:
Delete ··


[failure] 34-34:
Delete ··


[failure] 35-35:
Delete ··


39-40: Clarify merged references.

Using the expression "(ref || internalRef)" seamlessly merges any external ref passed in with your internal ref handling. Just be sure to confirm that no code depends on the presence of the one that is not used. Otherwise, this logic and type assertion are correct.

🧰 Tools
🪛 eslint

[error] 39-39: Replace ··const·internalRef·=·useRef<HTMLInputElement>(null);· with const·internalRef·=·useRef<HTMLInputElement>(null);

(prettier/prettier)


[error] 40-40: Delete ··

(prettier/prettier)


53-63: Focus shortcut handling is appropriate.

The hotkey logic effectively focuses the input. Ensure that the "overrideSystem" option behaves as intended across various browsers, so system-level shortcuts (e.g. Ctrl+K to open a new tab in some contexts) do not conflict.

🧰 Tools
🪛 eslint

[error] 53-53: Delete ··

(prettier/prettier)


[error] 54-54: Replace ······ with ····

(prettier/prettier)


[error] 55-55: Delete ··

(prettier/prettier)


[error] 56-56: Delete ··

(prettier/prettier)


[error] 57-57: Replace ·········· with ········

(prettier/prettier)


[error] 58-58: Delete ··

(prettier/prettier)


[error] 59-59: Delete ··

(prettier/prettier)


[error] 60-60: Delete ··

(prettier/prettier)


[error] 61-61: Delete ··

(prettier/prettier)


[error] 62-62: Delete ··

(prettier/prettier)


[error] 63-63: Delete ··

(prettier/prettier)


64-76: Nice handling of the Escape key.

Clearing the input and blurring on Escape is a neat, user-friendly addition. Verify that losing focus on Escape aligns with typical user expectations.

🧰 Tools
🪛 eslint

[error] 64-64: Delete ··

(prettier/prettier)


[error] 65-65: Delete ··

(prettier/prettier)


[error] 66-66: Delete ··

(prettier/prettier)


[error] 67-67: Delete ··

(prettier/prettier)


[error] 68-68: Delete ··

(prettier/prettier)


[error] 69-69: Delete ··

(prettier/prettier)


[error] 70-70: Delete ··

(prettier/prettier)


[error] 71-71: Replace ·········· with ········

(prettier/prettier)


[error] 72-72: Delete ··

(prettier/prettier)


[error] 73-73: Delete ··

(prettier/prettier)


[error] 74-74: Replace ·········· with ········

(prettier/prettier)


[error] 75-75: Delete ··

(prettier/prettier)


[error] 76-76: Replace ······ with ····

(prettier/prettier)

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/Form/SearchInput.tsx (3)

26-36: Add component documentation and display name

The refactor to use forwardRef is good. Consider adding:

  1. JSDoc documentation to describe the component's purpose and ref usage
  2. A display name for better debugging
+/**
+ * A search input component with debounce and keyboard shortcut support.
+ * Forwards ref to the underlying input element for focus management.
+ */
 const SearchInput = forwardRef<HTMLInputElement, SearchInputProps>(
   ({
     debouncePeriod = 500,
     className = "w-full md:max-w-sm",
     onChange,
     name = "search",
     ...props
   }: SearchInputProps,
   ref,
 ) => {
 );
+SearchInput.displayName = 'SearchInput';
 
 export default SearchInput;

43-51: Enhance debounce implementation

The debounce logic works correctly, but can be improved for better maintainability.

 useEffect(() => {
   if (value !== props.value) {
     const timeoutId = setTimeout(() => {
-      onChange && onChange({ name, value: value || "" });
+      onChange?.({ name, value: value || "" });
     }, debouncePeriod);
 
-    return () => clearTimeout(timeoutId);
+    return () => {
+      clearTimeout(timeoutId);
+    };
   }
 }, [value, debouncePeriod, name, onChange, props.value]);
🧰 Tools
🪛 Biome (1.9.4)

[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


95-98: Enhance keyboard shortcut accessibility

Consider adding ARIA labels to the keyboard shortcut indicators for better screen reader support.

 <kbd className="inline-flex items-center rounded border border-secondary-200 bg-white px-2 font-sans text-sm font-medium text-secondary-500 focus:opacity-0"
+    aria-label="Search shortcut"
 >
   {props.hotkeyIcon || (isAppleDevice ? "⌘K" : "Ctrl+K")}
 </kbd>

 // ... and for the Escape key
 <kbd className="inline-flex items-center rounded border border-secondary-200 bg-white px-2 font-sans text-sm font-medium text-secondary-500"
+    aria-label="Clear search shortcut"
 >
   Esc
 </kbd>

Also applies to: 103-105

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 84181ec and 7e073ed.

📒 Files selected for processing (1)
  • src/components/Form/SearchInput.tsx (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/Form/SearchInput.tsx

[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (3)
src/components/Form/SearchInput.tsx (3)

37-41: LGTM: Clean ref management implementation

The implementation properly handles both external and internal refs, with good state initialization from props.


54-76: LGTM: Robust keyboard shortcut implementation

The keyboard shortcuts implementation is well thought out:

  • Proper platform-specific shortcuts (⌘K vs Ctrl+K)
  • Escape handling for clearing and blur
  • Secondary mode prevention for nested contexts

Line range hint 1-114: Verify focus management in the users tab

The implementation looks solid for fixing the focus loss issue. To ensure complete resolution:

✅ Verification successful

Focus management implementation is correctly used in the users tab

The SearchInput component is properly implemented in UserListView with:

  • Correct ref forwarding using useRef
  • Proper focus management through searchInputRef
  • Automatic focus when search value is present via useEffect
  • Keyboard shortcuts inherited from the SearchInput component
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for proper usage of the SearchInput component in the users tab
rg -A 5 "SearchInput.*ref" src/components/Users/

Length of output: 50


Script:

#!/bin/bash
# Let's first check for any usage of SearchInput in the Users directory
rg "SearchInput" src/components/Users/

# Also check for any imports from the Form directory in Users
rg "from.*Form" src/components/Users/

# Let's also check the actual implementation of SearchInput in any user-related components
ast-grep --pattern 'const $_ = () => {
  $$$
  <SearchInput
    $$$
  />
  $$$
}'

Length of output: 3888


Script:

#!/bin/bash
# Let's check the specific implementation in UserListAndCard.tsx
cat src/components/Users/UserListAndCard.tsx

Length of output: 13165

🧰 Tools
🪛 Biome (1.9.4)

[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

@AdityaJ2305
Copy link
Contributor Author

I don’t think the Cypress tests failed due to the changes in this PR.

@rithviknishad rithviknishad added changes required invalid This doesn't seem right and removed invalid This doesn't seem right labels Dec 20, 2024
src/components/Users/ManageUsers.tsx Outdated Show resolved Hide resolved
src/components/Users/ManageUsers.tsx Outdated Show resolved Hide resolved
@rithviknishad rithviknishad added the invalid This doesn't seem right label Dec 21, 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 (2)
src/components/Users/UserListAndCard.tsx (1)

351-353: Remove debugging console.log statement

The console.log statement for debugging re-renders should be removed before merging.

- useEffect(() => {
-   console.log("re-rednerd");
- }, []);
src/components/Users/ManageUsers.tsx (1)

108-119: Simplify loading state handling

The current implementation assigns <Loading /> to manageUsers and then immediately reassigns it in the else block. This can be simplified.

- if (userListLoading || districtDataLoading || !userListData) {
-   manageUsers = <Loading />;
- } else {
-   manageUsers = (
+ manageUsers = userListLoading || districtDataLoading || !userListData ? (
+   <Loading />
+ ) : (
      <div>
        <UserListView
          users={userListData?.results ?? []}
          activeTab={activeTab}
        />
        <Pagination totalCount={userListData.count} />
      </div>
    );
- }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee9293f and 77e4170.

📒 Files selected for processing (3)
  • src/components/Facility/FacilityUsers.tsx (4 hunks)
  • src/components/Users/ManageUsers.tsx (3 hunks)
  • src/components/Users/UserListAndCard.tsx (2 hunks)
🧰 Additional context used
🪛 eslint
src/components/Users/UserListAndCard.tsx

[error] 350-350: 't' is assigned a value but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)

🪛 GitHub Check: lint
src/components/Users/UserListAndCard.tsx

[failure] 350-350:
't' is assigned a value but never used. Allowed unused vars must match /^_/u

🔇 Additional comments (4)
src/components/Users/UserListAndCard.tsx (1)

349-349: LGTM: Props interface simplification

Moving search functionality out of this component is a good approach to prevent unnecessary re-renders that were causing focus loss issues.

src/components/Facility/FacilityUsers.tsx (1)

81-90: LGTM: SearchInput implementation

The SearchInput component is correctly implemented with proper id and onChange handler. This matches the pattern used in ManageUsers and helps fix the focus management issue.

src/components/Users/ManageUsers.tsx (2)

181-190: LGTM: SearchInput implementation

The SearchInput implementation matches the pattern in FacilityUsers and helps resolve the focus management issue by preventing unnecessary re-renders of the UserListView component.


183-189: Verify focus retention across components

The implementation looks good, with search functionality consistently implemented in both ManageUsers and FacilityUsers components. This should resolve the focus loss issue by preventing unnecessary re-renders.

Also applies to: 83-89

✅ Verification successful

Focus management implementation verified across components

The search functionality is consistently implemented in both ManageUsers and FacilityUsers components, using the same pattern:

  • Both use SearchInput with identical props structure
  • Both handle state updates through updateQuery
  • Both maintain username in qParams state

This consistent implementation confirms that the focus management fix has been properly applied across all relevant components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent SearchInput implementation across components

# Check for any other instances of SearchInput that might need similar updates
rg --type tsx --type ts "SearchInput.*username.*onChange"

Length of output: 87


Script:

#!/bin/bash
# Search for SearchInput components with onChange handlers
rg -t ts -t typescript -t tsx "SearchInput.*onChange"

# Also check for any other instances of username-related search functionality
rg -t ts -t typescript -t tsx "search.*username|username.*search" -A 2 -B 2

Length of output: 203


Script:

#!/bin/bash
# Find all TypeScript/React files first
fd "\.(ts|tsx)$" src/components

# Then use these file patterns with ripgrep
rg "SearchInput.*onChange" $(fd "\.(ts|tsx)$" src/components)

# Search for username-related search functionality
rg "search.*username|username.*search" -A 2 -B 2 $(fd "\.(ts|tsx)$" src/components)

Length of output: 58633

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: 1

♻️ Duplicate comments (1)
src/components/Facility/FacilityUsers.tsx (1)

83-97: ⚠️ Potential issue

Add keyboard focus management for search input.

To address the focus loss issue mentioned in the PR objectives, implement keyboard shortcut handling for the search input.

Add keyboard focus management with the following changes:

+import { useRef, useEffect } from "react";
+
 export default function FacilityUsers(props: { facilityId: number }) {
   const { t } = useTranslation();
+  const searchInputRef = useRef<HTMLInputElement>(null);
+
+  useEffect(() => {
+    const handleKeyDown = (e: KeyboardEvent) => {
+      if ((e.metaKey || e.ctrlKey) && e.key === "k") {
+        e.preventDefault();
+        searchInputRef.current?.focus();
+      }
+    };
+    window.addEventListener("keydown", handleKeyDown);
+    return () => window.removeEventListener("keydown", handleKeyDown);
+  }, []);

   // ... existing code ...

   <SearchByMultipleFields
     id="search-by-username"
     className="w-full"
+    ref={searchInputRef}
     onSearch={(key, value) => updateQuery({ username: value })}
     options={[
       // ... existing options ...
     ]}
   />
🧹 Nitpick comments (1)
src/components/Facility/FacilityUsers.tsx (1)

5-18: Fix import statement ordering and formatting.

The import statements need to be properly ordered and formatted according to the static analysis hints.

Apply this diff to fix the import ordering:

 import CountBlock from "@/CAREUI/display/Count";
 import CareIcon from "@/CAREUI/icons/CareIcon";
-
 import Loading from "@/components/Common/Loading";
 import Page from "@/components/Common/Page";
+import SearchByMultipleFields from "@/components/Common/SearchByMultipleFields";
 import Tabs from "@/components/Common/Tabs";
 import UserListView from "@/components/Users/UserListAndCard";

 import useFilters from "@/hooks/useFilters";

 import routes from "@/Utils/request/api";
 import useTanStackQueryInstead from "@/Utils/request/useQuery";
-
-import SearchByMultipleFields from "@/components/Common/SearchByMultipleFields";
🧰 Tools
🪛 eslint

[error] 9-9: Insert SearchByMultipleFields·from·"@/components/Common/SearchByMultipleFields";⏎import·

(prettier/prettier)


[error] 15-17: Delete ";⏎⏎import·SearchByMultipleFields·from·"@/components/Common/SearchByMultipleFields

(prettier/prettier)

🪛 GitHub Check: lint

[failure] 9-9:
Insert SearchByMultipleFields·from·"@/components/Common/SearchByMultipleFields";⏎import·


[failure] 15-15:
Delete ";⏎⏎import·SearchByMultipleFields·from·"@/components/Common/SearchByMultipleFields

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2ffc677 and e3abd7d.

📒 Files selected for processing (1)
  • src/components/Facility/FacilityUsers.tsx (3 hunks)
🧰 Additional context used
🪛 eslint
src/components/Facility/FacilityUsers.tsx

[error] 9-9: Insert SearchByMultipleFields·from·"@/components/Common/SearchByMultipleFields";⏎import·

(prettier/prettier)


[error] 15-17: Delete ";⏎⏎import·SearchByMultipleFields·from·"@/components/Common/SearchByMultipleFields

(prettier/prettier)

🪛 GitHub Check: lint
src/components/Facility/FacilityUsers.tsx

[failure] 9-9:
Insert SearchByMultipleFields·from·"@/components/Common/SearchByMultipleFields";⏎import·


[failure] 15-15:
Delete ";⏎⏎import·SearchByMultipleFields·from·"@/components/Common/SearchByMultipleFields

🔇 Additional comments (2)
src/components/Facility/FacilityUsers.tsx (2)

Line range hint 22-66: LGTM: Clean implementation of loading states and user list handling.

The implementation properly handles loading states and gracefully renders the user list with pagination.


81-126: LGTM: Clean and responsive layout implementation.

The layout implementation is well-structured with:

  • Proper responsive design using Tailwind classes
  • Clean tab implementation for switching views
  • Good use of flex layout for alignment

src/components/Facility/FacilityUsers.tsx Outdated Show resolved Hide resolved
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Dec 23, 2024
Copy link

👋 Hi, @AdityaJ2305,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

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

♻️ Duplicate comments (1)
src/components/Facility/FacilityUsers.tsx (1)

80-97: 🛠️ Refactor suggestion

Improve focus management for search input

To address the focus loss issue mentioned in the PR objectives and maintain consistency with previous review suggestions:

  1. Add keyboard shortcut (cmd+k) support
  2. Maintain focus when switching tabs
+import { useRef, useEffect } from "react";
+
 export default function FacilityUsers(props: { facilityId: number }) {
   const { t } = useTranslation();
+  const searchInputRef = useRef<HTMLInputElement>(null);
+
+  useEffect(() => {
+    const handleKeyDown = (e: KeyboardEvent) => {
+      if ((e.metaKey || e.ctrlKey) && e.key === "k") {
+        e.preventDefault();
+        searchInputRef.current?.focus();
+      }
+    };
+    window.addEventListener("keydown", handleKeyDown);
+    return () => window.removeEventListener("keydown", handleKeyDown);
+  }, []);

   // ... existing code ...

   <SearchByMultipleFields
     id="search-by-username"
     className="w-full"
+    ref={searchInputRef}
+    autoFocus
     onSearch={(key, value) => updateQuery({ username: value })}
     options={[...]}
   />
🧹 Nitpick comments (2)
src/components/Facility/FacilityUsers.tsx (2)

21-21: Add type annotation for usersList

The usersList variable would benefit from an explicit type annotation for better type safety.

-let usersList: JSX.Element = <></>;
+const usersList: JSX.Element = <></>;

98-124: Enhance tab accessibility

The tabs implementation should include proper ARIA attributes and keyboard navigation.

 <Tabs
   tabs={[
     {
       text: (
-        <div className="flex items-center gap-2">
+        <div className="flex items-center gap-2" role="presentation">
           <CareIcon icon="l-credit-card" className="text-lg" />
           <span>Card</span>
         </div>
       ),
       value: 0,
       id: "user-card-view",
     },
     {
       text: (
-        <div className="flex items-center gap-2">
+        <div className="flex items-center gap-2" role="presentation">
           <CareIcon icon="l-list-ul" className="text-lg" />
           <span>List</span>
         </div>
       ),
       value: 1,
       id: "user-list-view",
     },
   ]}
   currentTab={activeTab}
-  onTabChange={(tab) => setActiveTab(tab as number)}
+  onTabChange={(tab) => {
+    setActiveTab(tab as number);
+    // Restore focus to search input after tab switch
+    searchInputRef.current?.focus();
+  }}
   className="float-right"
+  aria-label={t("view_options")}
 />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e3abd7d and 95fc767.

📒 Files selected for processing (1)
  • src/components/Facility/FacilityUsers.tsx (4 hunks)
🔇 Additional comments (1)
src/components/Facility/FacilityUsers.tsx (1)

80-126: Verify focus retention after implementation

Please verify that the focus management improvements resolve the focus loss issue in these scenarios:

  1. When switching between tabs
  2. When performing a search
  3. When using keyboard shortcuts (cmd+k and 'u')
✅ Verification successful

Focus management implementation is properly handled

The code review reveals that focus management is comprehensively implemented in the SearchByMultipleFields component:

  1. Focus is maintained after tab switches through useEffect hook that focuses the input when selectedOptionIndex changes
  2. Keyboard shortcuts are properly handled with focus restoration:
    • The search input is focused after using the '/' shortcut
    • Focus returns to input after using 'Escape' key
    • Focus is maintained after using option-specific shortcuts
  3. Focus is preserved during search operations through the clearSearch functionality

The implementation includes all necessary focus management features for the scenarios mentioned in the review comment, making it a robust solution for maintaining focus across user interactions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent focus management implementation across the codebase

# Search for other instances of SearchByMultipleFields to ensure consistent behavior
echo "Checking other SearchByMultipleFields implementations..."
rg "SearchByMultipleFields" -A 5 -g "*.tsx"

# Look for existing keyboard shortcut implementations
echo "Checking keyboard shortcut patterns..."
rg "useEffect.*handleKeyDown" -A 10 -g "*.tsx"

Length of output: 6295


Script:

#!/bin/bash
# Let's check the SearchByMultipleFields component implementation for focus management

# Check the SearchByMultipleFields component implementation
echo "Checking SearchByMultipleFields implementation..."
cat src/components/Common/SearchByMultipleFields.tsx

# Check for keyboard shortcut handling in the component
echo "Checking keyboard shortcut implementations..."
rg "shortcutKey" -A 5 -B 5 -g "*.tsx"

# Check for focus management related code
echo "Checking focus management..."
rg "useRef|focus\(\)|onFocus|onBlur" -A 3 -B 3 -g "src/components/Common/SearchByMultipleFields.tsx"

Length of output: 26510

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/Users/ManageUsers.tsx (2)

12-16: Remove unused imports

The following imports are not used in this file and should be removed:

  • Pagination (note: different from the one used from useFilters)
  • FacilityModel
  • UnlinkFacilityDialog
-import Pagination from "@/components/Common/Pagination";
import SearchByMultipleFields from "@/components/Common/SearchByMultipleFields";
import Tabs from "@/components/Common/Tabs";
-import { FacilityModel } from "@/components/Facility/models";
-import UnlinkFacilityDialog from "@/components/Users/UnlinkFacilityDialog";
🧰 Tools
🪛 eslint

[error] 12-12: 'Pagination' is defined but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)


[error] 15-15: 'FacilityModel' is defined but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)


[error] 16-16: 'UnlinkFacilityDialog' is defined but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)

🪛 GitHub Check: lint

[failure] 12-12:
'Pagination' is defined but never used. Allowed unused vars must match /^_/u


[failure] 15-15:
'FacilityModel' is defined but never used. Allowed unused vars must match /^_/u


[failure] 16-16:
'UnlinkFacilityDialog' is defined but never used. Allowed unused vars must match /^_/u


42-42: Remove unnecessary initialization

The empty JSX fragment initialization is redundant as it's immediately overwritten in the conditional blocks below.

-let usersList: JSX.Element = <></>;
+let usersList: JSX.Element;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 95fc767 and ab82beb.

📒 Files selected for processing (1)
  • src/components/Users/ManageUsers.tsx (4 hunks)
🧰 Additional context used
🪛 eslint
src/components/Users/ManageUsers.tsx

[error] 12-12: 'Pagination' is defined but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)


[error] 15-15: 'FacilityModel' is defined but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)


[error] 16-16: 'UnlinkFacilityDialog' is defined but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)

🪛 GitHub Check: lint
src/components/Users/ManageUsers.tsx

[failure] 12-12:
'Pagination' is defined but never used. Allowed unused vars must match /^_/u


[failure] 15-15:
'FacilityModel' is defined but never used. Allowed unused vars must match /^_/u


[failure] 16-16:
'UnlinkFacilityDialog' is defined but never used. Allowed unused vars must match /^_/u

🔇 Additional comments (3)
src/components/Users/ManageUsers.tsx (3)

103-114: Extract loading and list rendering logic into a shared component

This loading and list rendering logic appears to be a common pattern that could be shared with other components like FacilityUsers.


176-222: Consider using Shadcn's Tabs component

As suggested in previous reviews, using Shadcn's Tabs component would provide a more consistent UI experience.

Extract search and tabs UI into a shared component

This UI pattern appears to be shared with FacilityUsers. Consider extracting it into a reusable component.


178-193: Focus handling implementation looks good

The SearchByMultipleFields implementation properly addresses the focus loss issue by:

  • Moving search to component level
  • Using controlled component pattern with value prop
  • Implementing proper clear functionality

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label 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: 2

🧹 Nitpick comments (8)
src/components/ui/tabs.tsx (2)

8-20: Use more descriptive names or JSDoc for clarity
Consider adding inline documentation or a JSDoc comment to clarify the component’s usage and props, especially since TabsList is a wrapper around Radix’s primitive. This helps your teammates and future maintainers.


38-51: Consistent theming support
The TabsContent uses class names for styling but doesn’t expose additional theming props. If theming is a requirement, consider exposing a custom className prefix or theming props for consistent styling across the application.

src/components/Facility/FacilityUsers.tsx (5)

11-12: Remove commented-out import
The line // import Tabs from "@/components/Common/Tabs"; is no longer needed and can cause confusion.

-// import Tabs from "@/components/Common/Tabs";

22-23: Avoid default to empty fragments
Using an empty fragment <></> for the initial usersList is fine. Alternatively, consider using null to avoid rendering extra nodes.

-let usersList: JSX.Element = <></>;
+let usersList: JSX.Element | null = null;

29-29: Maintain descriptive naming
Renaming activeTab to something like viewMode or selectedView could further clarify the component’s intent.


68-68: Use meaningful wrapper
Wrapping {usersList} in an additional <div> is functional, but consider merging it into your main layout for a more streamlined DOM.


82-99: Leverage unify search approach
The SearchByMultipleFields component effectively updates queries. If more search parameters appear, consider an event-based or context-based approach to keep queries centralized.

src/components/Users/UserListAndCard.tsx (1)

348-348: Removed unused props
By reducing props (onSearch, searchValue, onTabChange) and focusing solely on users and activeTab, the component is more cohesive and has a clearer responsibility.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ab82beb and 2112dd1.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • package.json (1 hunks)
  • src/components/Facility/FacilityUsers.tsx (4 hunks)
  • src/components/Users/ManageUsers.tsx (4 hunks)
  • src/components/Users/UserListAndCard.tsx (1 hunks)
  • src/components/ui/tabs.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Users/ManageUsers.tsx
🔇 Additional comments (10)
src/components/ui/tabs.tsx (2)

23-36: Forward ref usage looks good
Your approach of forwarding refs is correct and ensures that parent components can manage focus or measure the DOM node.


1-2: Ensure minimal imports for performance
The new file imports from "@radix-ui/react-tabs" and React. Since this is a new UI component, verify that no extra modules are imported that might bloat the bundle.

✅ Verification successful

Imports are minimal and properly utilized
The imports in the file are minimal and each imported module is actively used:

  • @radix-ui/react-tabs: All imported primitives (Root, List, Trigger, Content) are used to build the component
  • react: Used for forwardRef and type definitions
  • @/lib/utils: The cn utility is used for className composition

The imports are essential for the component's functionality and there's no unnecessary bloat.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for excessive imports in tabs.tsx
rg --type tsx --json "import .* from \"@radix-ui/react-tabs\""

Length of output: 90


Script:

#!/bin/bash
# Check the content of tabs.tsx to analyze imports and their usage
cat src/components/ui/tabs.tsx

Length of output: 2138

src/components/Facility/FacilityUsers.tsx (5)

5-5: Good use of icons via CareIcon
Importing the CareIcon improves readability by naming icons based on domain concepts.


7-8: Appropriate usage of Radix Tabs
The newly imported Tabs, TabsList, and TabsTrigger from @/components/ui/tabs align with the new tab layout. This maintains consistency and leverages well-tested abstractions.


9-9: Loading component usage
Using a shared Loading component helps maintain consistent loading indicators across the codebase. Good reusability practice.


58-66: Ensure pagination updates apply
When userListData is loaded, Pagination is rendered with userListData.count. Confirm that offset calculations and result updates have been tested.


117-117: Container usage
Wrapping usersList inside a container <div> helps keep the structure consistent. If you require advanced layout, consider common layout components.

package.json (1)

68-68: Dependency addition
The addition of @radix-ui/react-tabs is consistent with the new tab UI. Double-check compatibility and license compliance.

✅ Verification successful

@radix-ui/react-tabs has MIT license - compatible for use

The package uses the MIT license which is permissive and compatible with most software projects. No license compliance issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Checking license type for @radix-ui/react-tabs
npm info @radix-ui/react-tabs license

Length of output: 43

src/components/Users/UserListAndCard.tsx (2)

345-345: Switched to string-based tab state
Changing activeTab from numeric to string-based ("cardView" or "listView") is more descriptive. This is a good improvement for clarity.


353-353: Conditional rendering for grid vs. list
Using activeTab === "cardView" determines which layout to display. Just ensure upstream code handles validation so unexpected values don’t break the UI.

✅ Verification successful

Let me verify the upstream handling of activeTab with additional checks.


Let me check the specific implementation of the Tabs component being used in ManageUsers.


Let me check the implementation of the UI Tabs component being used.


Validation is properly handled for tab values
The implementation is safe. The activeTab state is controlled through Radix UI's Tabs component which enforces the value to match the defined TabsTrigger values ("cardView" and "listView"). The component handles the validation internally and the UI cannot break from unexpected values.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check references to 'activeTab' to confirm enforced string values
rg 'activeTab'

Length of output: 1269


Script:

#!/bin/bash
# Check Tabs component usage and type definitions
ast-grep --pattern 'interface $_ {
  $$$
  value: $_
  $$$
}'

# Look for Tabs component definition
rg -A 5 'export.*Tabs'

Length of output: 9680


Script:

#!/bin/bash
# Check the Tabs component import and its usage in ManageUsers
rg -A 3 'import.*Tabs.*from' src/components/Users/ManageUsers.tsx

# Check the specific Tabs implementation
ast-grep --pattern 'Tabs value={$_} onValueChange={$_}'

Length of output: 469


Script:

#!/bin/bash
# Check the UI Tabs component implementation
cat src/components/ui/tabs.tsx

# Also check the TabsTrigger usage in ManageUsers for the specific values
rg -B 2 -A 5 'TabsTrigger' src/components/Users/ManageUsers.tsx

Length of output: 3333

src/components/Facility/FacilityUsers.tsx Outdated Show resolved Hide resolved
src/components/Facility/FacilityUsers.tsx Show resolved Hide resolved
@github-actions github-actions bot added Deploy-Failed Deplyment is not showing preview merge conflict pull requests with merge conflict labels Dec 24, 2024
Copy link

👋 Hi, @AdityaJ2305,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@AdityaJ2305 AdityaJ2305 force-pushed the issue/9398/search_bar_loses_focus branch from 3c5156a to 55196d3 Compare December 24, 2024 14:44
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 (4)
src/components/Facility/FacilityUsers.tsx (2)

22-24: Initialize user list elements more cleanly.
Using let usersList = <></>; and useState("cardView") for activeTab is fine. However, consider consolidating your state initialization for clarity, especially if you anticipate future expansions for loading states or multi-tab logic.

Also applies to: 29-29


55-67: Check error handling before rendering the user list.
Currently, you render <Loading /> until userListData becomes available. In scenarios where API calls fail, there is no fallback UI for errors. Add an error state to avoid indefinite loading.

src/components/Users/ManageUsers.tsx (2)

102-113: Add an error fallback for user/district data.
Similar to the feedback in FacilityUsers.tsx, consider adding an error state to prevent indefinite loading in edge cases where data fetching fails.


203-204: Avoid duplicating IDs.
The <div> with id="user-list-view" is nested inside the <TabsTrigger> block that also uses the same id. Verify whether both references are needed or if one can be removed to prevent ambiguous selectors or potential flakiness in tests.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3c5156a and 8cb506d.

📒 Files selected for processing (4)
  • cypress/pageobject/Users/UserSearch.ts (1 hunks)
  • package.json (1 hunks)
  • src/components/Facility/FacilityUsers.tsx (4 hunks)
  • src/components/Users/ManageUsers.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🔇 Additional comments (5)
cypress/pageobject/Users/UserSearch.ts (1)

86-86: Confirm correct attribute usage for the active tab.
The switch from checking for a class to verifying "data-state"="active" is acceptable. Ensure that the corresponding element (id="user-list-view") is indeed updated when switching tabs so that this test consistently passes.

src/components/Facility/FacilityUsers.tsx (2)

5-12: Validate new imports and removed references.
You replaced old references with CareIcon, Loading, Tabs, and SearchByMultipleFields. Ensure redundant imports were removed and that these new components are fully integrated without leftover console warnings or code references to removed imports (e.g., old Tabs import).


82-116: Ensure the search input and tab switches address the focus issue (#9398).
Providing SearchByMultipleFields and Tabs is the right approach for consistent UI. Verify that switching tabs or performing a search does not cause focus to be lost on the input field if that’s a desired behavior from the PR objectives.

src/components/Users/ManageUsers.tsx (2)

9-15: New UI dependencies and reusable logic.
The new imports for Tabs, SearchByMultipleFields, and the shift to let usersList: JSX.Element = <></>; align well with the approach used in FacilityUsers.tsx. This maintains consistency across components, simplifying future maintenance.

Also applies to: 36-36, 41-41, 47-47


175-210: Centralize search and tab focus handling to address #9398.
The usage of SearchByMultipleFields and Tabs is a step toward resolving the user search focus issue. Confirm that the component retains focus appropriately when switching between Card and List views, or when the search input changes, in order to fully meet the PR objective of preventing focus loss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required Deploy-Failed Deplyment is not showing preview merge conflict pull requests with merge conflict
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search bar loses focus after screen rebuild in Users section
4 participants