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

Avatar in UserAutoComplete #8967

Merged

Conversation

Jacobjeevan
Copy link
Contributor

@Jacobjeevan Jacobjeevan commented Oct 30, 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

  • New Features

    • Enhanced user autocomplete functionality with profile picture display in dropdown options.
    • Improved layout of options in the autocomplete component to include images alongside labels.
    • Introduced tests for patient file uploads, including audio and document handling.
  • Bug Fixes

    • Refined error handling for no results in the linked facility users component, improving user feedback.
  • Style

    • Updated layout and styling for better alignment and presentation of autocomplete options.
  • Chores

    • Reorganized import statements across various test files for improved clarity and structure.

Co-authored-by: noufalrahim <noufalrahim6784@gmail.com>
Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for care-ohc failed.

Name Link
🔨 Latest commit 406620a
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/672bdc3aba21070008451a58

@nihal467
Copy link
Member

nihal467 commented Nov 4, 2024

image

@Jacobjeevan the avatar is not available in the users dropdown

@Jacobjeevan
Copy link
Contributor Author

Jacobjeevan commented Nov 5, 2024

image

@Jacobjeevan the avatar is not available in the users dropdown

Opened a PR on Backend 👍 Right now, it only works onQuery (provided user has an avatar). Adding the change to allow for cover image url available to treating_physician_object.

Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes involve enhancements to the UserAutocompleteFormField and Autocomplete components, primarily by adding an optionImage property to display user avatars in the autocomplete dropdown. Additionally, error handling logic in the LinkedFacilityUsers component has been refined to improve user feedback when no results are found. The rendering of options has been updated to include an avatar alongside the label, enhancing the overall visual presentation of user options.

Changes

File Path Change Summary
src/components/Common/UserAutocompleteFormField.tsx Added optionImage property to Autocomplete for displaying user profile pictures. Refined noResultError handling in LinkedFacilityUsers.
src/components/Form/FormFields/Autocomplete.tsx Added optionImage property to AutocompleteProps and AutocompleteFormFieldProps. Updated rendering logic to include Avatar component for images. Adjusted layout for better styling.

Assessment against linked issues

Objective Addressed Explanation
Show the avatar of the user in each of the options for UserAutocompleteFormField (#8869)
Show the avatar of the users in the Users list page (#8869) Changes do not address the Users list page.

🐰 In the garden where bunnies play,
Avatars now brighten the user display.
With images clear, they hop with glee,
Finding their friends, as easy as can be!
A sprinkle of joy in every search,
User profiles shine, no need to perch! 🌼


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

🧹 Outside diff range and nitpick comments (2)
src/components/Common/UserAutocompleteFormField.tsx (1)

Line range hint 1-1: Add documentation about avatar availability conditions.

Since avatars are only available when certain conditions are met (as mentioned in PR comments), consider adding JSDoc comments to document these limitations for future maintainers.

+/**
+ * UserAutocomplete component that displays user information with avatars.
+ * Note: Avatars are only displayed when:
+ * 1. The user has an avatar configured
+ * 2. The backend provides the read_profile_picture_url
+ */
 export default function UserAutocomplete(props: UserSearchProps) {
src/components/Form/FormFields/Autocomplete.tsx (1)

245-272: Consider UI improvements for better accessibility and visual balance.

While the implementation works, there are several opportunities for improvement:

  1. The avatar size (h-11 w-11) seems large for a dropdown item. Consider reducing it for better visual balance.
  2. Add aria-label to improve accessibility for screen readers.
  3. Consider adjusting focus styles for better contrast when avatars are present.

Here's a suggested improvement:

-                      <div className="flex flex-row gap-2">
+                      <div className="flex flex-row gap-2" aria-label={`User option: ${option.label}`}>
                         {option?.image && (
                           <Avatar
-                            className="h-11 w-11 rounded-full"
+                            className="h-8 w-8 rounded-full"
                             name={option.label}
                             imageUrl={option.image}
                           />
                         )}
                         <div className="flex flex-grow flex-col">
                           <div className="flex justify-between">
-                            <span>{option.label}</span>
+                            <span className="font-medium">{option.label}</span>
                             <span>{option.icon}</span>
                           </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a0e6e62 and d190c86.

📒 Files selected for processing (2)
  • src/components/Common/UserAutocompleteFormField.tsx (1 hunks)
  • src/components/Form/FormFields/Autocomplete.tsx (7 hunks)
🔇 Additional comments (6)
src/components/Common/UserAutocompleteFormField.tsx (2)

Line range hint 82-87: Well-structured integration of the avatar feature.

The avatar integration follows the established patterns and maintains clean separation of concerns alongside other option properties.


83-83: Verify avatar URL handling in the Autocomplete component.

The implementation correctly passes the profile picture URL, but we should ensure proper handling of undefined URLs in the Autocomplete component.

✅ Verification successful

Avatar handling is properly implemented in the Autocomplete component

The implementation correctly handles undefined image URLs:

  • The Autocomplete component uses the Avatar component which safely handles both defined and undefined image URLs
  • The optionImage prop is properly typed as OptionCallback<T, string | undefined>
  • The Avatar component is only rendered when option?.image exists
  • The component provides a fallback by using the user's name when the image URL is undefined
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the Autocomplete component handles undefined image URLs
ast-grep --pattern 'optionImage={$_} $$$' src/components/Form/FormFields/Autocomplete.tsx

Length of output: 91


Script:

#!/bin/bash
# Let's first check if the file exists and see its content
fd "Autocomplete.tsx" --type f

# Then let's examine the implementation details
rg -l "optionImage" --type typescript

Length of output: 254


Script:

#!/bin/bash
# Let's examine the Autocomplete component implementation
cat src/components/Form/FormFields/Autocomplete.tsx

# Also check the usage in UserAutocompleteFormField
cat src/components/Common/UserAutocompleteFormField.tsx

Length of output: 14152

src/components/Form/FormFields/Autocomplete.tsx (4)

17-17: LGTM: Clean type definitions for avatar support.

The new optionImage property follows the established pattern of option callbacks and properly handles cases where images might not be available.

Also applies to: 28-28, 55-55, 80-80


126-126: LGTM: Consistent option mapping implementation.

The image property is correctly mapped from the optionImage callback, maintaining consistency with other option properties.


146-146: LGTM: Proper handling of raw input options.

Correctly initializes image as undefined for raw input options, ensuring consistent behavior when users type custom values.


245-251: Verify avatar handling with backend integration.

Based on the PR comments mentioning that "avatar functionality currently only works on query", we should verify that this implementation properly handles cases where avatars might not be immediately available.

✅ Verification successful

Let me gather more information about the Avatar component implementation to verify the handling of optional images.


Based on the gathered information, I can now provide the final response:

Avatar handling implementation is properly designed and safe

The implementation correctly handles cases where avatars might not be available:

  • The Avatar component has proper null handling with optional imageUrl prop
  • It gracefully falls back to showing initials when no image is provided
  • UserAutocomplete safely passes the optional read_profile_picture_url to the Avatar component
  • The conditional rendering in the Autocomplete component (option?.image) provides an additional safety layer
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for proper null handling of avatar/profile picture URLs across the codebase

# Look for profile picture URL handling patterns
echo "Checking profile picture URL handling patterns..."
rg "profile_picture_url|avatar_url" -A 3

# Look for Avatar component usage patterns
echo "Checking Avatar component usage patterns..."
ast-grep --pattern 'Avatar {
  $$$
  imageUrl={$_}
  $$$
}'

Length of output: 2717


Script:

#!/bin/bash
# Check Avatar component implementation
echo "Checking Avatar component implementation..."
fd Avatar.tsx --exec cat {}

# Check for conditional rendering patterns around Avatar
echo "Checking conditional Avatar rendering patterns..."
ast-grep --pattern 'Avatar
  $$$
  {$_?.image && (
    $$$
  )}'

# Check UserAutocomplete implementation
echo "Checking UserAutocomplete implementation..."
fd UserAutocomplete --exec cat {}

Length of output: 7127

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

🧹 Outside diff range and nitpick comments (1)
src/components/Form/FormFields/Autocomplete.tsx (1)

245-272: Consider UI refinements for better visual harmony.

While the implementation is functionally correct and naturally handles the initials fallback through the Avatar component, consider these refinements:

  1. The avatar size (h-11 w-11) might be too large for a dropdown option. Consider using a smaller size like h-8 w-8 for better visual balance.
  2. Add vertical alignment to ensure the avatar aligns properly with the text.
-                      <div className="flex flex-row gap-2">
+                      <div className="flex flex-row items-center gap-2">
                         {(option?.image || props.avatar) && (
                           <Avatar
-                            className="h-11 w-11 rounded-full"
+                            className="h-8 w-8 rounded-full"
                             name={option.label}
                             imageUrl={option.image}
                           />
                         )}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d190c86 and c93b3e2.

📒 Files selected for processing (2)
  • src/components/Common/UserAutocompleteFormField.tsx (1 hunks)
  • src/components/Form/FormFields/Autocomplete.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Common/UserAutocompleteFormField.tsx
🔇 Additional comments (4)
src/components/Form/FormFields/Autocomplete.tsx (4)

17-17: LGTM! Type definitions are well-structured.

The addition of the optionImage prop follows the existing pattern of option callbacks and is consistently implemented across both AutocompleteFormFieldProps and AutocompleteProps.

Also applies to: 28-28, 55-55, 80-80


126-126: LGTM! Option mapping is consistent.

The image mapping follows the same pattern as other option properties, maintaining consistency in the codebase.


146-146: LGTM! Raw input handling is appropriate.

Setting image: undefined for raw input options is correct as these represent user-typed values without associated images.


246-251: Verify avatar visibility in dropdown.

Based on the PR comments mentioning that "avatar functionality currently only works on query", we should verify that avatars are consistently visible in the dropdown, not just during query operations.

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Nov 6, 2024
Copy link

github-actions bot commented Nov 6, 2024

👋 Hi, @Jacobjeevan,
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.

@nihal467
Copy link
Member

nihal467 commented Nov 6, 2024

@Jacobjeevan PR looks good to me, can you clear the conflicts

@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Nov 6, 2024
@bodhish
Copy link
Member

bodhish commented Nov 9, 2024

@Jacobjeevan Do we need the changes in /cypress/ folder?

@rithviknishad
Copy link
Member

@bodhish It looks like pre-commit is sorting imports from cypress/* too, after the recent change in adding support for sorting imports. Merging this should solve it for other PRs too having the same issue.

@bodhish
Copy link
Member

bodhish commented Nov 9, 2024

Let's get it merged

@rithviknishad rithviknishad merged commit cc368a9 into ohcnetwork:develop Nov 9, 2024
17 of 22 checks passed
Copy link

github-actions bot commented Nov 9, 2024

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

@Jacobjeevan Jacobjeevan deleted the issues/8869-autocomplete-user branch December 10, 2024 04:45
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.

Show user avatar in User Autocomplete and User list page
4 participants