-
Notifications
You must be signed in to change notification settings - Fork 2
BA-1744: Technical Debts #230
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
BA-1744: Technical Debts #230
The head ref may contain hidden characters: "BA-1744-\u274C-technical-debt-switch-profiles"
Conversation
|
WalkthroughThe pull request introduces a new React component, Changes
Possibly related PRs
Suggested reviewers
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 suggestionReview unnecessary currentProfile fetching
Since you've refactored to use
CurrentProfileMenuwhich 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 inCurrentProfileMenu.packages/components/modules/navigations/web/Header/AccountMenu/AccountPopover/types.ts (1)
19-25: 💡 Verification agent🧩 Analysis chain
Consider removing unused interfaces
The
SectionControllerandComponentItemstypes 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 tsLength of output: 609
Unused type definitions found
Our search confirms that both
SectionControllerandComponentItemsare only referenced withinAccountPopover/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 containsUsing
cy.findByTextinstead ofcy.containsimproves 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 checksThe 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 packageInstead 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 refactoringNow that you're using the
CurrentProfileMenucomponent which internally usesuseCurrentProfile, 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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 goodRemoving 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 patternThis interface follows good component composition practices by:
- Using dependency injection pattern with optional component props
- Supporting partial props for customization
- 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 testsConsistent use of
cy.findByTextfor profile text validation improves test readability and maintains a uniform approach to element queries.
171-177: Improved avatar testing approachThe refactored approach to testing profile avatars is more direct and efficient:
- Using
findAllByAltTexttargets elements semantically- Checking attributes on the parent element is more precise
- 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 purposeThe 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 defaultsThe 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 organizationAdding the import for the newly created
CurrentProfileMenucomponent is a good refactoring move. This helps separate concerns and makes the code more maintainable.
89-98: Excellent simplification of conditional renderingThe refactoring to use the
CurrentProfileMenucomponent significantly simplifies the JSX and improves readability. This is a good example of component composition.
101-107: Improved UI structure with Box wrapperThe 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 structureThe import changes properly align with the component refactoring. Including
CurrentProfileMenuPropsand simplifying the profile-related imports improves type organization.
9-10: Good use of TypeScript type extension with OmitExtending
CurrentProfileMenuPropswithOmitfor 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 safetyUpdating the
ProfilesListproperty 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.
ea72da9 to
3feec2f
Compare
There was a problem hiding this 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
useMemofor 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
useCallbackto 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
useCurrentProfilehook. 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
📒 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.
|
|
|
||
| export interface AccountPopoverProps { | ||
| export interface AccountPopoverProps | ||
| extends Omit<CurrentProfileMenuProps, 'handlePopoverOnClose' | 'setOpenProfilesList'> { |
There was a problem hiding this comment.
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



move statics from
packages/components/modules/navigations/Header/AccountMenu/AccountPopover/_storybook_/static/profile-1.pngtopackages/components/.storybook/staticsimprove 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
CurrentProfileMenucomponent for enhanced user profile management.AccountPopovercomponent for improved clarity and structure.LogoutItemcomponent by removing unnecessary wrapper elements.AccountPopoverPropsinterface to streamline properties.1.0.23in the package.