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: Redesign the User view of Department/Teams #10568

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

Conversation

abhimanyurajeesh
Copy link
Contributor

@abhimanyurajeesh abhimanyurajeesh commented Feb 12, 2025

Required Backend

Proposed Changes

Current Design

image

Requested Design

image

Changed Design

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

Summary by CodeRabbit

  • New Features

    • Expanded localization with additional translations for department/team and organization management interfaces.
    • Introduced a search functionality to filter user listings by name for improved navigation.
    • Enhanced internationalization of the organization creation interface with localized strings for buttons, titles, and messages.
    • Improved layout organization for user information display in the user listing component.
  • Bug Fixes

    • Adjusted button styling in the Add User Sheet for better visual alignment.

@abhimanyurajeesh abhimanyurajeesh requested a review from a team as a code owner February 12, 2025 06:55
Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request adds several localization keys in the English locale JSON file to support department/team and organization functionalities. It also introduces a search feature within the FacilityOrganizationUsers component to filter user listings and updates the UI with a skeleton loader during data fetching. Additionally, the CreateFacilityOrganizationSheet component now leverages i18next for internationalizing user interface strings, updating messages, button texts, and placeholders accordingly.

Changes

File(s) Change Summary
public/locale/en.json Added multiple localization keys for department/team and organization management, including keys for creation, search, descriptions, and details.
src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx Implemented a search feature by adding a searchQuery state, updating the query parameters, filtering the user list, and refining the layout with a skeleton loader.
src/pages/Facility/settings/organizations/components/CreateFacilityOrganizationSheet.tsx Integrated i18next to localize user-facing strings, replacing hardcoded messages with localized ones for buttons, titles, placeholders, and toast notifications.
src/pages/Organization/components/AddUserSheet.tsx Modified the Button component's className by removing the "ml-3" class, affecting its margin-left spacing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant API

    User->>UI: Enter search query
    UI->>UI: Update search state (`searchQuery`)
    UI->>API: Fetch users with query parameter (search)
    API-->>UI: Return filtered users data
    UI->>User: Render updated user list with skeleton loader until data loads
Loading

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • Jacobjeevan
  • rithviknishad

Poem

I'm a bunny on the code trail,
Hopping past keys without fail.
New strings and search make me cheer,
Localization magic is here!
With carrots 🥕 and code so bright,
I celebrate changes day and night!


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 Feb 12, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit f4842f9
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67af541617eb6b0008618e96
😎 Deploy Preview https://deploy-preview-10568.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.

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 (4)
src/pages/Facility/settings/organizations/components/CreateFacilityOrganizationSheet.tsx (1)

66-66: Verify error message consistency.

The success and error messages use different translation key patterns:

  • Success: organization_created_successfully
  • Error: please_enter_organization_name

Consider standardizing the naming pattern for translation keys to improve maintainability.

Also applies to: 82-82

src/pages/Facility/settings/organizations/components/FacilityOrganizationLayout.tsx (1)

159-170: Consider accessibility improvements for tab navigation.

The tab navigation could benefit from ARIA attributes for better screen reader support.

 <TabsList className="w-full justify-start border-b border-gray-300 bg-transparent p-0 h-auto rounded-none">
+  <div role="tablist" aria-label={t("navigation_tabs")}>
   {navItems.map((item) => (
     <Link key={item.path} href={item.path}>
       <TabsTrigger
         value={item.value}
+        role="tab"
+        aria-selected={currentTab === item.value}
+        aria-controls={`${item.value}-panel`}
         className="border-b-2 border-transparent px-2 py-2 text-gray-600 hover:text-gray-900 data-[state=active]:text-primary-800  data-[state=active]:border-primary-700 data-[state=active]:bg-transparent data-[state=active]:shadow-none rounded-none"
       >
         {item.title}
       </TabsTrigger>
     </Link>
   ))}
+  </div>
 </TabsList>
src/pages/Facility/settings/organizations/FacilityOrganizationView.tsx (1)

46-52: Consider implementing debounce for search input.

The search input directly updates the state without debouncing, which could trigger unnecessary API calls.

+import { useDebounce } from '@/hooks/useDebounce';

 const [searchQuery, setSearchQuery] = useState("");
+const debouncedSearch = useDebounce(searchQuery, 300);

-const filteredUsers = users?.results?.filter((userRole) => {
+const filteredUsers = users?.results?.filter((userRole) => {
-  if (!searchQuery) return true;
+  if (!debouncedSearch) return true;

-  const searchLower = searchQuery.toLowerCase();
+  const searchLower = debouncedSearch.toLowerCase();
   const fullName = ...

Also applies to: 53-63

src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (1)

122-129: Consider adding lazy loading for avatars.

For better performance, especially with many users, consider implementing lazy loading for avatar images.

 <Avatar
   name={`${userRole.user.first_name} ${userRole.user.last_name}`}
   imageUrl={userRole.user.profile_picture_url}
+  loading="lazy"
   className="h-12 w-12 sm:h-14 sm:w-14 text-xl sm:text-2xl flex-shrink-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 98286c6 and 42f8454.

📒 Files selected for processing (5)
  • public/locale/en.json (10 hunks)
  • src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (3 hunks)
  • src/pages/Facility/settings/organizations/FacilityOrganizationView.tsx (5 hunks)
  • src/pages/Facility/settings/organizations/components/CreateFacilityOrganizationSheet.tsx (7 hunks)
  • src/pages/Facility/settings/organizations/components/FacilityOrganizationLayout.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • 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)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: CodeQL-Build
🔇 Additional comments (8)
src/pages/Facility/settings/organizations/components/CreateFacilityOrganizationSheet.tsx (1)

99-152: LGTM! Comprehensive internationalization implementation.

All user-facing strings have been properly internationalized using the translation function. The implementation is consistent and follows best practices.

src/pages/Facility/settings/organizations/components/FacilityOrganizationLayout.tsx (1)

36-40: LGTM! Interface simplification.

The NavItem interface has been simplified by replacing the icon property with value, making it more focused and maintainable.

src/pages/Facility/settings/organizations/FacilityOrganizationView.tsx (1)

28-33: LGTM! Well-defined interface.

The Organization interface clearly defines the structure of organization objects with appropriate types and optional fields.

public/locale/en.json (5)

293-293: LGTM! Department/Team related keys are well-structured.

The keys for department/team management follow a consistent naming pattern and provide clear, user-friendly messages:

  • add_department_team
  • create_department_team and its description
  • enter_department_team_name and description

Also applies to: 640-641, 934-935


1002-1005: LGTM! Organization type keys follow a consistent pattern.

The organization type keys are well-organized with clear, descriptive values:

  • facility_organization_type__dept
  • facility_organization_type__other
  • facility_organization_type__root
  • facility_organization_type__team

648-648: LGTM! Organization creation keys are clear and consistent.

The keys for organization creation provide appropriate feedback:

  • create_organization
  • organization_created_successfully

Also applies to: 1510-1510


1898-1898: LGTM! Search key is descriptive.

The search key search_by_department_team_name clearly indicates its purpose.


1928-1928: LGTM! Action key is concise.

The action key see_details is simple and clear.

Copy link

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

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

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Feb 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

♻️ Duplicate comments (1)
src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (1)

65-74: ⚠️ Potential issue

Optimize search filtering logic.

The current implementation performs redundant client-side filtering after the server has already filtered the results based on the search query.

-const filteredUsers = users?.results?.filter((userRole) => {
-  if (!searchQuery) return true;
-
-  const searchLower = searchQuery.toLowerCase();
-  const fullName =
-    `${userRole.user.first_name} ${userRole.user.last_name}`.toLowerCase();
-  const username = userRole.user.username.toLowerCase();
-
-  return fullName.includes(searchLower) || username.includes(searchLower);
-});
+// Remove client-side filtering as search is already handled by the API
+const filteredUsers = users?.results;
🧹 Nitpick comments (3)
src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (3)

37-39: Consider making the pagination limit configurable.

The pagination limit is hardcoded to 12. Consider making it configurable through props or environment variables for better flexibility.

-  const { qParams, Pagination, resultsPerPage } = useFilters({
-    limit: 12,
-  });
+  const { qParams, Pagination, resultsPerPage } = useFilters({
+    limit: props.itemsPerPage ?? 12,
+  });

46-63: Enhance query configuration for better error handling and resilience.

Consider adding error handling and retry configuration to improve the query's robustness.

 const { data: users, isLoading: isLoadingUsers } = useQuery({
   queryKey: [
     "facilityOrganizationUsers",
     facilityId,
     id,
     searchQuery,
     qParams,
   ],
   queryFn: query.debounced(routes.facilityOrganization.listUsers, {
     pathParams: { facilityId, organizationId: id },
     queryParams: {
       search: searchQuery || undefined,
       limit: resultsPerPage,
       offset: ((qParams.page || 1) - 1) * resultsPerPage,
     },
   }),
   enabled: !!id,
+  retry: 3,
+  onError: (error) => {
+    console.error('Failed to fetch users:', error);
+    // Add error handling logic here
+  },
 });

84-97: Enhance accessibility and error handling in the UI.

Consider the following improvements:

  1. Add proper ARIA labels and roles for better accessibility
  2. Add error state handling in the UI
 <div className="relative">
   <CareIcon
     icon="l-search"
     className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 h-4 w-4"
+    aria-hidden="true"
   />
   <Input
     placeholder={t("search_by_user_name")}
     value={searchQuery}
     onChange={(e) => {
       setSearchQuery(e.target.value);
     }}
     className="w-full pl-8"
+    aria-label={t("search_by_user_name")}
   />
 </div>

 {isLoadingUsers ? (
   <div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-2 gap-4">
     <CardGridSkeleton count={6} />
   </div>
+) : error ? (
+  <Card className="col-span-full">
+    <CardContent className="p-6 text-center text-red-500">
+      {t("error_loading_users")}
+    </CardContent>
+  </Card>
 ) : (
   <div className="space-y-4">
     <div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-2 gap-4">

Also applies to: 120-133

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 42f8454 and c080d53.

📒 Files selected for processing (1)
  • src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (2 hunks)

Copy link
Contributor Author

@abhimanyurajeesh abhimanyurajeesh left a comment

Choose a reason for hiding this comment

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

need to update with the latest

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Feb 13, 2025
@rithviknishad rithviknishad marked this pull request as draft February 13, 2025 12:42
…mprove clarity and conditionally apply limits based on search query
@abhimanyurajeesh abhimanyurajeesh marked this pull request as ready for review February 13, 2025 14:38
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)
public/locale/en.json (1)

2177-2177: Consider using a more specific key name for "type".

The key "type" is very generic and could lead to confusion or conflicts. Consider using a more context-specific key name that clearly indicates its usage.

Example alternatives:

-  "type": "Type",
+  "organization_type_label": "Type",

or

-  "type": "Type",
+  "department_type_label": "Type",

depending on the context where it's used.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c5ebdb and 6fb9d62.

📒 Files selected for processing (2)
  • public/locale/en.json (8 hunks)
  • src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx
🔇 Additional comments (2)
public/locale/en.json (2)

293-294: Well-structured department/team localization keys!

The new department/team related keys follow consistent naming conventions and provide clear, user-friendly messages.

Also applies to: 644-645, 945-946


653-653: Well-structured organization localization keys!

The new organization related keys maintain consistency with existing patterns and provide clear feedback messages.

Also applies to: 1531-1531, 1659-1659, 1986-1986

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/organizations/FacilityOrganizationUsers.tsx (1)

151-153: Consider alternative layout for truncated fields.

Based on the previous discussion, the truncation of role and phone number fields might not be the best approach. Consider:

  1. Utilizing the available white space horizontally
  2. Adjusting the layout for mobile view to prevent truncation
-              <div className="font-medium truncate">
+              <div className="font-medium break-words">
                 {userRole.role.name}
               </div>
-              <div className="font-medium truncate">
+              <div className="font-medium break-words">
                 {userRole.user.phone_number}
               </div>

Also applies to: 159-161

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb9d62 and db64b36.

📒 Files selected for processing (1)
  • src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#10568
File: src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx:69-78
Timestamp: 2025-02-13T19:11:07.106Z
Learning: Avoid implementing redundant client-side filtering when the API already supports search functionality, especially with paginated data, as it can lead to incorrect results and unnecessary performance overhead.
⏰ 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: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (4)
src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (4)

3-3: LGTM! Well-structured component setup.

The component setup is clean and follows React best practices. The imports are appropriate, and the filter configuration with a default limit of 12 items per page is reasonable for this use case.

Also applies to: 10-10, 13-13, 16-16, 37-40


46-63: LGTM! Proper implementation of server-side search.

The query configuration correctly implements server-side search by:

  • Including searchQuery in the queryKey for proper cache invalidation
  • Using search_text parameter for server-side filtering
  • Implementing proper pagination parameters

72-86: LGTM! Well-implemented search UI with proper accessibility.

The search input implementation is clean with:

  • Proper icon positioning
  • Responsive layout
  • Internationalization support
  • Accessible input field

185-191: LGTM! Proper pagination implementation.

The pagination is correctly implemented with:

  • Proper conditional rendering
  • Appropriate total count handling
  • Integration with the useFilters hook

@abhimanyurajeesh
Copy link
Contributor Author

Actionable comments posted: 0
🧹 Nitpick comments (1)

src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (1)> 151-153: Consider alternative layout for truncated fields.

Based on the previous discussion, the truncation of role and phone number fields might not be the best approach. Consider:

  1. Utilizing the available white space horizontally
  2. Adjusting the layout for mobile view to prevent truncation
-              <div className="font-medium truncate">
+              <div className="font-medium break-words">
                 {userRole.role.name}
               </div>
-              <div className="font-medium truncate">
+              <div className="font-medium break-words">
                 {userRole.user.phone_number}
               </div>

Also applies to: 159-161

📜 Review details

its fix by changing the layout size.

…heet components for improved responsiveness and consistency
…se local state instead of query parameters for sheet handling
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/organizations/FacilityOrganizationUsers.tsx (1)

2-2: Remove commented import.

The commented import useQueryParams should be removed if it's no longer needed.

-//import { useQueryParams } from "raviger";
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cd25dc7 and f4842f9.

📒 Files selected for processing (1)
  • src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#10568
File: src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx:69-78
Timestamp: 2025-02-13T19:11:07.106Z
Learning: Avoid implementing redundant client-side filtering when the API already supports search functionality, especially with paginated data, as it can lead to incorrect results and unnecessary performance overhead.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test
  • GitHub Check: OSSAR-Scan
  • GitHub Check: cypress-run (1)
🔇 Additional comments (4)
src/pages/Facility/settings/organizations/FacilityOrganizationUsers.tsx (4)

51-68: LGTM! Proper implementation of server-side search.

The search implementation correctly utilizes the backend API by passing the search query as a parameter, avoiding redundant client-side filtering. This is the right approach for paginated data.


77-91: LGTM! Well-implemented search UI with proper accessibility.

The search input implementation includes:

  • Clear visual hierarchy with the search icon
  • Proper responsive layout
  • Accessible input with placeholder text

156-166: Reconsider field truncation approach.

Based on previous discussions, truncating role and phone number fields may not be the best approach. Consider utilizing the available horizontal space more effectively.

Apply this diff to improve field visibility:

-              <div className="font-medium truncate">
+              <div className="font-medium break-words">
                {userRole.role.name}
               </div>
             </div>
             <div>
               <div className="text-gray-500">
                 {t("phone_number")}
               </div>
-              <div className="font-medium truncate">
+              <div className="font-medium break-words">
                {userRole.user.phone_number}
               </div>

190-196: LGTM! Well-implemented pagination.

The pagination implementation correctly:

  • Checks for results existence
  • Verifies count threshold
  • Centers the pagination controls

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.

Redesign the Open view of Department/Teams
5 participants