Skip to content

Conversation

@priscilladeroode
Copy link
Contributor

@priscilladeroode priscilladeroode commented Feb 28, 2025

move statics from packages/components/modules/navigations/Header/AccountMenu/AccountPopover/_storybook_/static/profile-1.png to packages/components/.storybook/statics

improve packages/components/modules/navigations/Header/AccountMenu/AccountPopover/tests/AccountPopover.cy.tsx tests

duplicated test descriptions (we should probably merge it into one)

replace cy.contains with findByText

instead of querying within cy.findByLabelText('List of available profiles') we could've used findByAltText using the AvatarWithPlaceholder's alt ("Profile avatar")

at packages/components/modules/navigations/Header/AccountMenu/AccountPopover/index.tsx, AddProfileMenuItem should not be children of LogoutItem since they have no logic relation. Let's render both separately (an outside container may be needed)

at packages/components/modules/profiles/ProfilePopover/ProfilesList/ProfileMenuItem/index.tsx, double check if we want to keep using readInlineData

evaluate if we can move and use more granular configs like tsconfig.eslint.json, and tsconfig.jest.json to the tsconfig package to make it available to other packages

Refactor AccountPopover component to improve readability.

Approvd
https://app.approvd.io/projects/BA/stories/36373

Summary by CodeRabbit

  • New Features
    • Introduced a new CurrentProfileMenu component for enhanced user profile management.
  • Refactor
    • Consolidated rendering logic in the AccountPopover component for improved clarity and structure.
    • Simplified the LogoutItem component by removing unnecessary wrapper elements.
    • Updated the AccountPopoverProps interface to streamline properties.
  • Tests
    • Enhanced test cases for user-related elements, improving efficiency and reducing redundancy.
  • Chores
    • Updated version number to 1.0.23 in the package.

@changeset-bot
Copy link

changeset-bot bot commented Feb 28, 2025

⚠️ No Changeset found

Latest commit: 4c3e352

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2025

Walkthrough

The pull request introduces a new React component, CurrentProfileMenu, along with its associated TypeScript interface to consolidate profile and user rendering logic. The LogoutItem component and its types have been simplified by removing unnecessary wrappers and children props. Additionally, the AccountPopover component now imports and utilizes the new CurrentProfileMenu, while its props interface is updated to omit deprecated properties. Test files have been refactored for more efficient assertions using cy.findByText and streamlined attribute checks for profile avatars.

Changes

File(s) Change Summary
packages/.../CurrentProfileMenu/(index.tsx, types.ts) Added new React functional component CurrentProfileMenu using the useCurrentProfile hook; defined associated prop types in CurrentProfileMenuProps.
packages/.../LogoutItem/(index.tsx, types.ts) Removed the Box wrapper and children prop; updated LogoutItemProps by removing the PropsWithChildren extension.
packages/.../__tests__/AccountPopover.cy.tsx Refactored tests by replacing cy.contains with cy.findByText, consolidating assertions and streamlining checks for profile avatar attributes.
packages/.../AccountPopover/(index.tsx, types.ts) Updated AccountPopover to integrate CurrentProfileMenu, restructured the layout with a Box wrapper for logout and add-profile items, and revised the prop interface by removing deprecated properties and adding LogoutItemProps.
packages/components/CHANGELOG.md Added a new version entry 1.0.23 documenting the refactor of the AccountPopover component and improvements to related tests.
packages/components/package.json Updated package version from 1.0.22 to 1.0.23.

Possibly related PRs

  • BA-hotfix: current profile fixes #152: Updates involving the useCurrentProfile hook and handling of user profile data, which relate to the introduction of the CurrentProfileMenu component.
  • BA-hotfix: remove listener #153: Modifications in the useCurrentProfile hook that enhance the handling of user profile data, connected to the new CurrentProfileMenu component.

Suggested reviewers

  • deboracosilveira
  • anicioalexandre

Poem

Hoppity hops and code so neat,
I’ve crafted menus that are hard to beat.
Profiles and logouts now dance in cheer,
A tidy popover shining bright and clear.
From a rabbit’s heart, I celebrate this feat! 🐇✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 3feec2f and 4c3e352.

📒 Files selected for processing (2)
  • packages/components/CHANGELOG.md (1 hunks)
  • packages/components/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/components/package.json
  • packages/components/CHANGELOG.md

🪧 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.
  • @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

@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 comments (2)
packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/index.tsx (1)

41-41: 🛠️ Refactor suggestion

Review unnecessary currentProfile fetching

Since you've refactored to use CurrentProfileMenu which already fetches the current profile, this line seems redundant. The profile is only used for the avatar image, so consider passing just that property down from the existing hook call in CurrentProfileMenu.

packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/types.ts (1)

19-25: 💡 Verification agent

🧩 Analysis chain

Consider removing unused interfaces

The SectionController and ComponentItems types don't appear to be used in the reviewed files. If they're not used elsewhere, consider removing them to keep the types file focused.


🏁 Script executed:

#!/bin/bash
# Search for usages of SectionController and ComponentItems
echo "Searching for SectionController usage:"
rg "SectionController" --type ts
echo "Searching for ComponentItems usage:"
rg "ComponentItems" --type ts

Length of output: 609


Unused type definitions found

Our search confirms that both SectionController and ComponentItems are only referenced within AccountPopover/types.ts (lines 19-25) and do not appear in any other part of the codebase. If these types aren’t intended for future use, please consider removing them to streamline the types file.

🧹 Nitpick comments (4)
packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/__tests__/AccountPopover.cy.tsx (1)

41-42: Good use of findByText over contains

Using cy.findByText instead of cy.contains improves test reliability and follows Testing Library best practices for querying elements in a way that mirrors how users interact with the application.

packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/index.tsx (2)

32-54: Clean rendering with appropriate conditional checks

The component render logic is clean and readable, correctly handling the conditional rendering of different parts based on the component state and provided props. The pattern of using Boolean() checks for rendering conditions is consistent throughout the component.

One suggestion: consider extracting the MenuItems rendering into a separate function component to further simplify the main component's render method.


3-3: Consider using more specific imports from authentication package

Instead of importing the entire hook, you could import only what you need to minimize bundle size.

-import { useCurrentProfile } from '@baseapp-frontend/authentication'
+import { useCurrentProfile } from '@baseapp-frontend/authentication/hooks'

Note: This assumes the package has this structure. If not, the current import is fine.

packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/index.tsx (1)

5-5: Consider removing unused import after refactoring

Now that you're using the CurrentProfileMenu component which internally uses useCurrentProfile, this import appears to be redundant in the parent component.

-import { useCurrentProfile } from '@baseapp-frontend/authentication'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0835b4d and ea72da9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/index.tsx (1 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/types.ts (1 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/LogoutItem/index.tsx (1 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/LogoutItem/types.ts (1 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/__tests__/AccountPopover.cy.tsx (3 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/index.tsx (3 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/types.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (13)
packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/LogoutItem/index.tsx (1)

15-27: Simplified component structure looks great!

The removal of the wrapper Box component creates a cleaner, more focused implementation. The component now directly returns a MenuItem with proper accessibility attributes (tabIndex) and styling.

packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/LogoutItem/types.ts (1)

1-4: Improved type definition looks good

Removing the PropsWithChildren extension makes the interface more explicit about what props are accepted, which aligns well with the component implementation changes.

packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/types.ts (1)

6-15: Well-designed interface with good composition pattern

This interface follows good component composition practices by:

  1. Using dependency injection pattern with optional component props
  2. Supporting partial props for customization
  3. Clearly defining required callback functions

This approach provides flexibility while maintaining type safety.

packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/__tests__/AccountPopover.cy.tsx (2)

58-59: Good consistent use of findByText in profile tests

Consistent use of cy.findByText for profile text validation improves test readability and maintains a uniform approach to element queries.


171-177: Improved avatar testing approach

The refactored approach to testing profile avatars is more direct and efficient:

  1. Using findAllByAltText targets elements semantically
  2. Checking attributes on the parent element is more precise
  3. Reduced complexity by eliminating the need to filter visible elements

This approach is both more maintainable and more in line with accessibility testing best practices.

packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/index.tsx (2)

1-14: Well-organized imports with clear purpose

The imports are well-structured, with React core imports at the top, followed by auth hooks, Material UI components, and finally the local components and types. This organization makes it easy to understand the dependencies.


15-31: Good implementation of component with sensible defaults

The component uses default values for props effectively, making the component more flexible and reusable. The conditional logic for determining what to render is clear and follows good practices by using Boolean() for explicit type conversion.

packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/index.tsx (3)

20-20: Great component extraction improves code organization

Adding the import for the newly created CurrentProfileMenu component is a good refactoring move. This helps separate concerns and makes the code more maintainable.


89-98: Excellent simplification of conditional rendering

The refactoring to use the CurrentProfileMenu component significantly simplifies the JSX and improves readability. This is a good example of component composition.


101-107: Improved UI structure with Box wrapper

The addition of the Box component with proper styling improves the visual organization of the menu items. Grouping the LogoutItem and conditional AddProfileMenuItem together with consistent spacing enhances the user experience.

packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/types.ts (3)

5-7: Clean type imports that reflect the refactored component structure

The import changes properly align with the component refactoring. Including CurrentProfileMenuProps and simplifying the profile-related imports improves type organization.


9-10: Good use of TypeScript type extension with Omit

Extending CurrentProfileMenuProps with Omit for specific properties is a clean way to reuse types while avoiding prop drilling issues. This approach maintains type safety while keeping the interface concise.


12-16: Improved type definitions for better type safety

Updating the ProfilesList property to be non-nullable enhances type safety. The consistent use of optional properties with ? where appropriate makes the interface more flexible and easier to use.

@anicioalexandre anicioalexandre added the needs review PR needs to be reviewed. label Mar 12, 2025
@priscilladeroode priscilladeroode force-pushed the BA-1744-❌-technical-debt-switch-profiles branch from ea72da9 to 3feec2f Compare March 17, 2025 17:58
Copy link

@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)
packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/index.tsx (3)

25-30: Consider memoizing derived values.

The component calculates several derived boolean values during each render. Consider using React's useMemo for these calculations to optimize performance, especially if parent components re-render frequently.

- const loadCurrentProfile = Boolean(CurrentProfile) && Boolean(profile)
- const loadCurrentUser = !loadCurrentProfile && Boolean(CurrentUser)
- const shouldShowDivider = Boolean(
-   loadCurrentProfile || loadCurrentUser || Boolean(SwitchProfileMenu),
- )
+ const loadCurrentProfile = useMemo(() => Boolean(CurrentProfile) && Boolean(profile), [CurrentProfile, profile])
+ const loadCurrentUser = useMemo(() => !loadCurrentProfile && Boolean(CurrentUser), [loadCurrentProfile, CurrentUser])
+ const shouldShowDivider = useMemo(
+   () => Boolean(loadCurrentProfile || loadCurrentUser || Boolean(SwitchProfileMenu)),
+   [loadCurrentProfile, loadCurrentUser, SwitchProfileMenu]
+ )

38-43: Use useCallback for inline function.

Creating a new arrow function in the JSX on each render can impact performance. Consider using useCallback to memoize the function.

+ const handleOpenProfilesList = useCallback(() => setOpenProfilesList(true), [setOpenProfilesList])

// Then in JSX:
  {loadCurrentProfile && Boolean(SwitchProfileMenu) && (
    <SwitchProfileMenu
-     openProfilesList={() => setOpenProfilesList(true)}
+     openProfilesList={handleOpenProfilesList}
      {...SwitchProfileMenuProps}
    />
  )}

Don't forget to add the necessary import:

- import { FC } from 'react'
+ import { FC, useCallback, useMemo } from 'react'

32-53: Consider error handling for profile loading.

The current implementation doesn't include explicit error handling for the useCurrentProfile hook. Consider adding error states or fallback UI for scenarios where profile loading fails.

- const { currentProfile: profile } = useCurrentProfile({ noSSR: false })
+ const { currentProfile: profile, error } = useCurrentProfile({ noSSR: false })

// Then in the return statement, add error handling:
  return (
    <>
+     {error && (
+       <Typography color="error">
+         Failed to load profile information
+       </Typography>
+     )}
      {loadCurrentProfile && <CurrentProfile />}

Don't forget to add the necessary import:

import { Divider } from '@mui/material'
+ import { Divider, Typography } from '@mui/material'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ea72da9 and 3feec2f.

📒 Files selected for processing (7)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/index.tsx (1 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/types.ts (1 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/LogoutItem/index.tsx (1 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/LogoutItem/types.ts (1 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/__tests__/AccountPopover.cy.tsx (3 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/index.tsx (3 hunks)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/LogoutItem/index.tsx
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/LogoutItem/types.ts
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/types.ts
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/tests/AccountPopover.cy.tsx
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/index.tsx
  • packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/types.ts
🔇 Additional comments (3)
packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/CurrentProfileMenu/index.tsx (3)

1-14: Well-organized imports with clear separation.

The imports are neatly organized, with external dependencies separated from internal components. The component structure follows a modular approach, which supports reusability and maintainability.


15-24: Good use of default props and component composition.

The component accepts customizable components with sensible defaults, promoting flexibility and extensibility. This pattern allows for easy customization without changing the core component logic.


45-51: Good use of conditional rendering and optional chaining.

The component properly handles conditional rendering with optional chaining (MenuItemsProps?.menuItems?.length), which prevents errors when dealing with potentially undefined values.

@sonarqubecloud
Copy link

@priscilladeroode priscilladeroode merged commit d788f69 into master Mar 17, 2025
7 of 8 checks passed

export interface AccountPopoverProps {
export interface AccountPopoverProps
extends Omit<CurrentProfileMenuProps, 'handlePopoverOnClose' | 'setOpenProfilesList'> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@priscilladeroode I think we should've Pick the ones we want instead of Omit, so we don't need to worry if we ever add new props to CurrentProfileMenu that should not be part o AccountPopoverProps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review PR needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants