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: Facility Organization Dropdown #10104

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

Conversation

Jeffrin2005
Copy link
Contributor

@Jeffrin2005 Jeffrin2005 commented Jan 22, 2025

Proposed Changes

v23.mp4

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

Summary by CodeRabbit

  • UI/UX Improvements

    • Enhanced organization selector with a more visually structured display.
    • Added Building icon to organization selection.
    • Refined layout and spacing of organization hierarchy.
    • Updated placeholder text for better context.
    • Streamlined visual presentation of sub-department information.
    • Improved clarity and usability in organization selection logic.
    • Simplified handling of selected options in the autocomplete component.
  • Localization Enhancements

    • Added new messages for improved user prompts and clarity, including indications for sub-departments and file archiving.

@Jeffrin2005 Jeffrin2005 requested a review from a team as a code owner January 22, 2025 16:40
Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request enhances the FacilityOrganizationSelector component by restructuring its layout and improving the user interface. Key modifications include the addition of a Building icon, a refined organization hierarchy display, and updated placeholder text for the autocomplete input. Additionally, the logic for handling organization selection has been streamlined, promoting a more intuitive user experience. The changes aim to clarify the presentation of selected organizations and their sub-departments while cleaning up the codebase by removing inline comments.

Changes

File Change Summary
src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx - Added Building icon import from lucide-react
- Restructured organization display with icon and improved styling
- Modified organization hierarchy layout
- Updated placeholder text
- Removed inline code comments
src/components/ui/autocomplete.tsx - Introduced selectedOption variable for selected option handling
- Simplified button title and label logic
- Updated onSelect handler for clarity
public/locale/en.json - Added localization entries: has_sub_departments, not_found, proceed, state_reason_for_archiving

Assessment against linked issues

Objective Addressed Explanation
Enhance Facility Organization Dropdown Experience [#10060]
Improve User-Friendliness of Organization Selector [#10060]

Possibly related PRs

Suggested labels

needs review, changes required

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🏢 A Rabbit's Ode to Organization Selection 🐰
With icons bright and layout clean,
Our selector now is quite serene.
Buildings stand where badges once did dwell,
A dropdown tale, we now shall tell!
Clarity springs from each design,
Making choices simply divine! 🌟


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 40abd27 and 91951d8.

📒 Files selected for processing (2)
  • public/locale/en.json (5 hunks)
  • src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx
🔇 Additional comments (1)
public/locale/en.json (1)

1112-1112: LGTM! The new translations are clear and well-formatted.

The added translations follow proper case formatting conventions and provide clear messages for their respective use cases.

Also applies to: 1463-1463, 1692-1692, 2018-2018


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jan 22, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 91951d8
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6794667dd84a9c00084a654f
😎 Deploy Preview https://deploy-preview-10104--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: 1

🧹 Nitpick comments (1)
src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx (1)

115-126: Consider adding ARIA attributes for better accessibility.

The new organization display looks great with the Building icon and clear visual hierarchy. Consider these accessibility improvements:

-          <div className="flex items-center gap-3 rounded-md border border-sky-100 bg-sky-50/50 p-2.5">
+          <div 
+            className="flex items-center gap-3 rounded-md border border-sky-100 bg-sky-50/50 p-2.5"
+            role="status"
+            aria-label={`Selected organization: ${selectedOrganization.name}`}
+          >
             <Building className="h-4 w-4 text-sky-600 flex-shrink-0" aria-hidden="true" />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 39caada and 2331940.

📒 Files selected for processing (1)
  • src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx (2 hunks)
🔇 Additional comments (2)
src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx (2)

2-2: LGTM! Good choice of icon library.

The addition of the Building icon from lucide-react aligns with the PR objectives and follows good practices.


172-176: LGTM! Well-implemented dynamic placeholder with i18n support.

The placeholder text implementation provides clear context and properly supports internationalization.

Comment on lines 131 to 150
<div key={org.id} className="flex items-center gap-1.5">
<div className="flex items-center gap-1.5 flex-1">
{index > 0 && (
<CareIcon
icon="l-arrow-right"
className="h-3.5 w-3.5 text-gray-400 flex-shrink-0"
/>
)}
<div
className="flex items-center justify-between flex-1 rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-sm shadow-sm cursor-pointer hover:bg-gray-50"
onClick={() => handleEdit(index)}
>
<span className="truncate">{org.name}</span>
<CareIcon
icon="l-angle-down"
className="h-3.5 w-3.5 ml-2 flex-shrink-0 text-gray-400"
/>
</div>
</div>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance keyboard accessibility for interactive elements.

The hierarchical display looks clean, but needs accessibility improvements for keyboard users:

               <div
-                  className="flex items-center justify-between flex-1 rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-sm shadow-sm cursor-pointer hover:bg-gray-50"
+                  className="flex items-center justify-between flex-1 rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-sm shadow-sm cursor-pointer hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-sky-500 focus:ring-offset-2"
+                  role="button"
+                  tabIndex={0}
                   onClick={() => handleEdit(index)}
+                  onKeyDown={(e) => e.key === 'Enter' && handleEdit(index)}
+                  aria-label={`Edit ${org.name} level`}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div key={org.id} className="flex items-center gap-1.5">
<div className="flex items-center gap-1.5 flex-1">
{index > 0 && (
<CareIcon
icon="l-arrow-right"
className="h-3.5 w-3.5 text-gray-400 flex-shrink-0"
/>
)}
<div
className="flex items-center justify-between flex-1 rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-sm shadow-sm cursor-pointer hover:bg-gray-50"
onClick={() => handleEdit(index)}
>
<span className="truncate">{org.name}</span>
<CareIcon
icon="l-angle-down"
className="h-3.5 w-3.5 ml-2 flex-shrink-0 text-gray-400"
/>
</div>
</div>
</div>
<div key={org.id} className="flex items-center gap-1.5">
<div className="flex items-center gap-1.5 flex-1">
{index > 0 && (
<CareIcon
icon="l-arrow-right"
className="h-3.5 w-3.5 text-gray-400 flex-shrink-0"
/>
)}
<div
className="flex items-center justify-between flex-1 rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-sm shadow-sm cursor-pointer hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-sky-500 focus:ring-offset-2"
role="button"
tabIndex={0}
onClick={() => handleEdit(index)}
onKeyDown={(e) => e.key === 'Enter' && handleEdit(index)}
aria-label={`Edit ${org.name} level`}
>
<span className="truncate">{org.name}</span>
<CareIcon
icon="l-angle-down"
className="h-3.5 w-3.5 ml-2 flex-shrink-0 text-gray-400"
/>
</div>
</div>
</div>

@nihal467
Copy link
Member

nihal467 commented Jan 23, 2025

image

When you click on the dropdown that already has a value selected, the expected behavior is for the dropdown options to be displayed. Instead, the current behavior is that it closes the entire dropdown and reset it to its initial state, as if no value was previously selected.

@Jeffrin2005 https://www.loom.com/share/8cb97e50e22a45f98702f155c1ae9685?sid=6d2cc770-b044-409c-9801-2e665845b678

@Jeffrin2005
Copy link
Contributor Author

@nihal467

v23.mp4

Any Changes required ?

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 23, 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: 2

🧹 Nitpick comments (1)
src/components/ui/autocomplete.tsx (1)

Line range hint 33-47: Consider adding controlled open state prop.

To provide more flexibility and better control over the dropdown's behavior, consider making the open state controllable from the parent component.

Add an optional prop for controlled open state:

 interface AutocompleteProps {
   options: AutoCompleteOption[];
   value: string;
   onChange: (value: string) => void;
   onSearch?: (value: string) => void;
   placeholder?: string;
   noOptionsMessage?: string;
   disabled?: boolean;
   align?: "start" | "center" | "end";
   popoverClassName?: string;
   "data-cy"?: string;
+  open?: boolean;
+  onOpenChange?: (open: boolean) => void;
 }

This would allow parent components to have full control over the dropdown's open state when needed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2331940 and 7e0f0f2.

📒 Files selected for processing (2)
  • src/components/ui/autocomplete.tsx (2 hunks)
  • src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx
🔇 Additional comments (2)
src/components/ui/autocomplete.tsx (2)

52-52: LGTM! Good optimization.

The introduction of selectedOption improves code readability and reduces repeated lookups.


67-73: LGTM! Clean implementation.

The label display logic is well-structured with good separation of styling and content.

Comment on lines +102 to 104
onChange(currentValue);
setOpen(false);
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Optimize onSelect handler to prevent unnecessary updates.

The current implementation doesn't check if the selected value is different from the current value, which could lead to unnecessary re-renders and might contribute to the reported dropdown behavior issues.

Apply this optimization:

-  onChange(currentValue);
-  setOpen(false);
+  if (currentValue !== value) {
+    onChange(currentValue);
+    setOpen(false);
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onChange(currentValue);
setOpen(false);
}}
if (currentValue !== value) {
onChange(currentValue);
setOpen(false);
}

Comment on lines +58 to +65
title={selectedOption?.label}
variant="outline"
role="combobox"
aria-expanded={open}
className="w-full justify-between"
disabled={disabled}
data-cy={dataCy}
onClick={() => setOpen(true)}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix dropdown toggle behavior.

The current onClick implementation doesn't properly handle the toggle case, which explains the reported issue where "dropdown closes when clicked with a value selected". The dropdown should toggle between open/closed states.

Apply this fix:

-  onClick={() => setOpen(true)}
+  onClick={() => setOpen(!open)}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
title={selectedOption?.label}
variant="outline"
role="combobox"
aria-expanded={open}
className="w-full justify-between"
disabled={disabled}
data-cy={dataCy}
onClick={() => setOpen(true)}
title={selectedOption?.label}
variant="outline"
role="combobox"
aria-expanded={open}
className="w-full justify-between"
disabled={disabled}
data-cy={dataCy}
onClick={() => setOpen(!open)}

<span
className={cn(
"truncate",
!selectedOption && "text-muted-foreground",
Copy link
Member

Choose a reason for hiding this comment

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

are you sure this is a valid tailwind class?

{selectedOrganization.has_children && (
<Badge variant="outline">Has Sub-departments</Badge>
<p className="text-xs text-sky-600">
{t("Has Sub Departments")}
Copy link
Member

Choose a reason for hiding this comment

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

refer translations guidelines in README. this is not how i18n should be done.

if (level < selectedLevels.length) {
return selectedLevels[level].name;
}
return level === 0 ? t("select_department") : t("select sub department");
Copy link
Member

Choose a reason for hiding this comment

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

please check all translations

@rithviknishad rithviknishad added invalid This doesn't seem right and removed question Further information is requested needs-triage labels Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right test failed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance Facility Organization Dropdown Experience
4 participants