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

563-refactor: Widget school menu #659

Merged
merged 30 commits into from
Dec 16, 2024
Merged

Conversation

Quiddlee
Copy link
Member

@Quiddlee Quiddlee commented Nov 22, 2024

What type of PR is this? (select all that apply)

  • πŸ• Feature
  • πŸ› Bug Fix
  • 🚧 Breaking Change
  • πŸ§‘β€πŸ’» Code Refactor
  • πŸ“ Documentation Update

Description

Related Tickets & Documents

Screenshots, Recordings

Screenshot 2024-11-22 at 11 33 41β€―PM

Added/updated tests?

  • πŸ‘Œ Yes
  • πŸ™…β€β™‚οΈ No, because they aren't needed
  • πŸ™‹β€β™‚οΈ No, because I need help

[optional] Are there any post deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

gif

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced communityMenuStaticLinks and schoolMenuStaticLinks for enhanced menu navigation.
    • Updated DesktopView and MobileView components to utilize new static links for menu items.
    • Added new SchoolMenu component to render school items with customizable headings and colors.
    • New Color type for enforcing specific color options.
  • Bug Fixes

    • Improved responsiveness of the mobile menu by adjusting height properties.
  • Tests

    • Added comprehensive tests for the SchoolMenu and desktop menu functionality.
  • Styles

    • Introduced new styles for school-item and school-menu components to enhance layout and responsiveness.

Copy link

Lighthouse Report:

  • Performance: 84 / 100
  • Accessibility: 100 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

Copy link

Lighthouse Report:

  • Performance: 75 / 100
  • Accessibility: 100 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

Copy link

github-actions bot commented Dec 7, 2024

Lighthouse Report:

  • Performance: 67 / 100
  • Accessibility: 100 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

@SpaNb4 SpaNb4 mentioned this pull request Dec 9, 2024
8 tasks
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 20 changed files in this pull request and generated 2 comments.

Files not reviewed (15)
  • src/core/base-layout/components/header/header.module.scss: Language not supported
  • src/widgets/school-menu/ui/school-item/school-item.module.scss: Language not supported
  • src/widgets/school-menu/ui/school-menu.scss: Language not supported
  • src/widgets/school-menu/ui/school-menu/school-menu.module.scss: Language not supported
  • src/widgets/school-menu/school-menu.test.tsx: Evaluated as low risk
  • src/widgets/school-menu/ui/school-menu.tsx: Evaluated as low risk
  • src/widgets/school-menu/ui/school-list/school-list.tsx: Evaluated as low risk
  • src/core/base-layout/components/header/nav-item/nav-item.tsx: Evaluated as low risk
  • dev-data/index.ts: Evaluated as low risk
  • src/core/const/index.ts: Evaluated as low risk
  • src/shared/tests/visual/main.spec.ts: Evaluated as low risk
  • src/widgets/mobile-view/ui/mobile-view.tsx: Evaluated as low risk
  • src/widgets/school-menu/index.ts: Evaluated as low risk
  • src/core/base-layout/components/header/header.tsx: Evaluated as low risk
  • src/widgets/school-menu/types.ts: Evaluated as low risk
Comments suppressed due to low confidence (1)

src/widgets/school-menu/ui/school-menu/school-menu.tsx:16

  • The 'className' prop is being passed to the 'ul' element without any validation. Ensure that it is a valid class name.
export const SchoolMenu = ({ heading, color = 'light', children, className }: SchoolMenuProps) => {

Copy link

Lighthouse Report:

  • Performance: 87 / 100
  • Accessibility: 100 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

πŸ“ Walkthrough

Walkthrough

The pull request introduces enhancements to the school-menu module, including the addition of new static links for community and school menus. Modifications are made to the Header, Footer, and MobileView components to utilize these links. The responsiveness of the .mobile-menu class is improved, and various components are refactored for better prop management and maintainability. Additionally, unit tests for the SchoolMenu component are added to ensure its functionality.

Changes

File Change Summary
dev-data/index.ts Exported communityMenuStaticLinks and schoolMenuStaticLinks.
dev-data/school-menu-links.ts Added constants schoolMenuStaticLinks and communityMenuStaticLinks.
src/core/base-layout/components/footer/... Modified DesktopView to render SchoolMenu using static links.
src/core/base-layout/components/header/... Updated Header to use dynamic rendering for NavItem components with new static links.
src/core/base-layout/components/header/... Adjusted NavItem to accept children instead of a dropdown prop.
src/core/base-layout/components/header/... Removed unnecessary state management in Header.
src/core/base-layout/components/header/... Updated MobileView to utilize static links and added onClose prop.
src/core/const/index.ts Added new entries to ANCHORS: UPCOMING_COURSES, EVENTS, MERCH, CONTRIBUTE.
src/shared/tests/visual/main.spec.ts Added a test case for the desktop menu functionality.
src/widgets/mobile-view/ui/mobile-view.tsx Modified MobileView to accept onClose prop and render items from static links.
src/widgets/school-menu/index.ts Updated export path for SchoolMenu.
src/widgets/school-menu/school-menu.test.tsx Added unit tests for the SchoolMenu component.
src/widgets/school-menu/types.ts Introduced new type alias Color for color options.
src/widgets/school-menu/ui/school-item/... Added styles for .school-item and related classes.
src/widgets/school-menu/ui/school-item.tsx Redefined SchoolItemProps and simplified rendering logic.
src/widgets/school-menu/ui/school-list.tsx Deleted SchoolList component and related interfaces.
src/widgets/school-menu/ui/school-menu.tsx Deleted old SchoolMenu component and introduced a new one with updated props.
src/widgets/school-menu/ui/school-menu/... Added new styles for .school-menu, .heading, and .school-list.

Assessment against linked issues

Objective Addressed Explanation
Refactor school-menu.tsx and related components (e.g., school-item.tsx, school-list.tsx) βœ…
Improve hover state for links in dropdown (related to header links) ❌ No changes related to hover states were made.
Move constants to constants.ts and update ANCHORS βœ…

Possibly related PRs

Suggested reviewers

  • dzmitry-varabei
  • andron13
  • natanchik
  • SpaNb4

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


πŸ“œ Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 1ea946c and 6f80458.

πŸ“’ Files selected for processing (2)
  • src/widgets/school-menu/ui/school-item/school-item.tsx (1 hunks)
  • src/widgets/school-menu/ui/school-menu/school-menu.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/widgets/school-menu/ui/school-menu/school-menu.test.tsx
πŸ”‡ Additional comments (2)
src/widgets/school-menu/ui/school-item/school-item.tsx (2)

12-18: LGTM: Well-structured type definition

The SchoolItemProps type properly extends HTML list item props while adding specific properties needed for the school menu item.


Line range hint 20-50: LGTM: Clean and accessible implementation

The component follows React best practices with:

  • Proper prop spreading
  • Conditional rendering
  • Accessibility considerations
  • Test coverage support

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.

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

🧹 Outside diff range and nitpick comments (12)
src/widgets/school-menu/ui/school-item/school-item.tsx (1)

34-34: Provide meaningful alt text for the Image component

Currently, the alt attribute is empty (alt=""). To enhance accessibility, consider providing a descriptive alt text if the icon conveys important information.

src/widgets/school-menu/ui/school-menu/school-menu.tsx (1)

16-21: Pass down additional props to the <ul> element

Since SchoolMenuProps extends HTMLProps<HTMLUListElement>, it would be beneficial to spread ...props onto the <ul> to allow additional HTML attributes to be applied.

dev-data/school-menu-links.ts (1)

5-13: Align property names between data and component props

The static link objects use detailsUrl, while SchoolItemProps expects a url property. For consistency and to prevent potential errors, consider renaming detailsUrl to url in the static link data.

Also applies to: 18-36

src/shared/__tests__/visual/main.spec.ts (1)

31-41: Consider enhancing test reliability and assertions.

Add visibility checks and improve screenshot naming:

 test('Main page desktop menu', async ({ page }) => {
   await page.goto(ROUTES.HOME);

   const elements = page.getByTestId('menu-item');
   const elementsCount = await elements.count();
+  expect(elementsCount).toBeGreaterThan(0);

   for (let i = 0; i < elementsCount; i++) {
     await elements.nth(i).hover();
+    const menuContent = page.getByTestId(`menu-content-${i}`);
+    await expect(menuContent).toBeVisible();
-    await takeScreenshot(page, `Main page desktop - menu open ${i + 1}`);
+    await takeScreenshot(page, `Main page desktop - ${await elements.nth(i).textContent()} menu`);
   }
 });
src/core/base-layout/components/footer/desktop-view.tsx (1)

13-23: Consider lifting color prop to reduce duplication

The color="light" prop is repeated across all SchoolMenu.Item components. Consider lifting it to the SchoolMenu level.

 <SchoolMenu heading="rs school" color="light">
   {schoolMenuStaticLinks.map((link) => (
     <SchoolMenu.Item
       key={link.detailsUrl}
       title={link.title}
       description={link.description}
       url={link.detailsUrl}
-      color="light"
     />
   ))}
 </SchoolMenu>

Also applies to: 27-38

src/core/base-layout/components/header/header.module.scss (1)

95-96: Consider adding fallback for dvh unit

While dvh provides better mobile viewport handling, it needs fallback for older browsers.

-  min-height: 100dvh;
-  max-height: 100dvh;
+  min-height: 100vh;
+  min-height: 100dvh;
+  max-height: 100vh;
+  max-height: 100dvh;
src/core/base-layout/components/header/nav-item/nav-item.tsx (1)

67-67: Consider simplifying href construction

The href template literal can be simplified when only prepending a slash.

-href={`/${href}`}
+href={'/' + href}
src/widgets/mobile-view/ui/mobile-view.tsx (1)

40-49: Consider extracting repeated SchoolMenu.Item mapping logic

There are three nearly identical mapping patterns for SchoolMenu.Item rendering.

Consider creating a reusable helper:

+ const renderMenuItems = (items: any[], color?: string, onClose?: () => void) => (
+   items.map((item, i) => (
+     <SchoolMenu.Item
+       key={item.id || i}
+       title={item.title}
+       description={item.description}
+       url={item.detailsUrl}
+       icon={item.iconSmall}
+       color={color}
+       onClick={onClose}
+     />
+   ))
+ );

Also applies to: 79-88, 98-107

src/widgets/school-menu/ui/school-menu/school-menu.test.tsx (4)

9-12: Consider adding type guards instead of type assertions.

Replace type assertions with type guards to improve type safety.

-  const aws = mockedCourses.find(
-    (course) => course.title === COURSE_TITLES.AWS_FUNDAMENTALS,
-  ) as Course;
+  const aws = mockedCourses.find(
+    (course): course is Course => course.title === COURSE_TITLES.AWS_FUNDAMENTALS,
+  );
+  if (!aws) throw new Error('AWS course not found in mocked data');

47-49: Consider using more specific assertions.

Instead of checking length only, verify the actual content of links and descriptions.

  expect(screen.getAllByRole('link')).toHaveLength(2);
-  expect(container.getElementsByTagName('small')).toHaveLength(2);
+  const links = screen.getAllByRole('link');
+  expect(links[0]).toHaveTextContent(schoolMenuStaticLinks[0].title);
+  expect(links[1]).toHaveTextContent(schoolMenuStaticLinks[1].title);

71-89: Improve test description clarity.

The test name "[mentorshipId]" is unclear. Consider renaming to better describe what's being tested.

-  it('renders [mentorshipId] correct when "all courses" heading is passed', () => {
+  it('renders course icons correctly for all courses', () => {

126-129: Avoid using magic numbers in array indices.

Instead of using hardcoded indices, find elements by their content.

-  const linkReact = links.at(3);
-  const linkAWS = links.at(-1);
+  const linkReact = screen.getByRole('link', { name: new RegExp(COURSE_TITLES.REACT, 'i') });
+  const linkAWS = screen.getByRole('link', { name: new RegExp(COURSE_TITLES.AWS_FUNDAMENTALS, 'i') });
πŸ“œ Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between b7c52eb and eee1a00.

πŸ“’ Files selected for processing (20)
  • dev-data/index.ts (1 hunks)
  • dev-data/school-menu-links.ts (1 hunks)
  • src/core/base-layout/components/footer/desktop-view.tsx (2 hunks)
  • src/core/base-layout/components/header/header.module.scss (1 hunks)
  • src/core/base-layout/components/header/header.tsx (3 hunks)
  • src/core/base-layout/components/header/nav-item/nav-item.tsx (4 hunks)
  • src/core/const/index.ts (1 hunks)
  • src/shared/__tests__/visual/main.spec.ts (1 hunks)
  • src/widgets/mobile-view/ui/mobile-view.tsx (3 hunks)
  • src/widgets/school-menu/index.ts (1 hunks)
  • src/widgets/school-menu/school-menu.test.tsx (0 hunks)
  • src/widgets/school-menu/types.ts (1 hunks)
  • src/widgets/school-menu/ui/school-item/school-item.module.scss (1 hunks)
  • src/widgets/school-menu/ui/school-item/school-item.tsx (1 hunks)
  • src/widgets/school-menu/ui/school-list/school-list.tsx (0 hunks)
  • src/widgets/school-menu/ui/school-menu.scss (0 hunks)
  • src/widgets/school-menu/ui/school-menu.tsx (0 hunks)
  • src/widgets/school-menu/ui/school-menu/school-menu.module.scss (1 hunks)
  • src/widgets/school-menu/ui/school-menu/school-menu.test.tsx (1 hunks)
  • src/widgets/school-menu/ui/school-menu/school-menu.tsx (1 hunks)
πŸ’€ Files with no reviewable changes (4)
  • src/widgets/school-menu/ui/school-list/school-list.tsx
  • src/widgets/school-menu/ui/school-menu.scss
  • src/widgets/school-menu/school-menu.test.tsx
  • src/widgets/school-menu/ui/school-menu.tsx
βœ… Files skipped from review due to trivial changes (2)
  • src/widgets/school-menu/index.ts
  • src/widgets/school-menu/ui/school-menu/school-menu.module.scss
πŸ”‡ Additional comments (9)
src/widgets/school-menu/types.ts (1)

1-1: LGTM!

The new Color type improves type safety and clarifies expected values.

src/core/const/index.ts (1)

5-8: LGTM! New anchor constants follow consistent naming pattern.

src/core/base-layout/components/header/nav-item/nav-item.tsx (1)

Line range hint 60-94: LGTM! Well-structured component with good accessibility

The component has proper keyboard navigation, ARIA attributes, and event handling.

dev-data/index.ts (1)

36-36: LGTM: Clean export of menu links

The export follows the established pattern and supports the centralization of menu data.

src/widgets/mobile-view/ui/mobile-view.tsx (1)

35-37: Consistent onClick handler usage

Good implementation of the onClose handler across all navigation links.

Also applies to: 54-56, 74-76, 93-95

src/core/base-layout/components/header/header.tsx (3)

39-41: Clean implementation of menu close handler

Good separation of concerns with a dedicated handler function.


64-65: Simplified color state management

Good cleanup of the color state management, making it more straightforward.


80-87: Consider consistent item structure across menus

The SchoolMenu.Item implementations vary slightly between different menus (some with icons, some without).

Let's check if this is intentional:

Also applies to: 105-112, 117-124

src/widgets/school-menu/ui/school-menu/school-menu.test.tsx (1)

1-7: LGTM! Well-organized imports.

The imports are properly structured with testing utilities, component under test, and mock data.

Copy link

Lighthouse Report:

  • Performance: 97 / 100
  • Accessibility: 100 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

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

🧹 Outside diff range and nitpick comments (1)
src/widgets/school-menu/ui/school-item/school-item.tsx (1)

30-30: Enhance Link accessibility with aria-label.

Add an aria-label to the Link component to improve screen reader experience.

-      <Link href={url} className={cx('school-item')}>
+      <Link href={url} className={cx('school-item')} aria-label={`${title}${description ? `: ${description}` : ''}`}>
πŸ“œ Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between eee1a00 and 1ea946c.

πŸ“’ Files selected for processing (2)
  • src/widgets/school-menu/ui/school-item/school-item.module.scss (1 hunks)
  • src/widgets/school-menu/ui/school-item/school-item.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/widgets/school-menu/ui/school-item/school-item.module.scss
πŸ”‡ Additional comments (2)
src/widgets/school-menu/ui/school-item/school-item.tsx (2)

12-18: LGTM! Well-structured type definition.

The type extends HTMLProps correctly and provides a clear interface with required and optional properties.


24-24: πŸ› οΈ Refactor suggestion

Add type validation for the color prop.

Consider using a union type for allowed color values to prevent invalid colors.

-  color?: Color;
+  color?: 'dark' | 'light';  // Add specific allowed values

Likely invalid or redundant comment.

src/widgets/school-menu/ui/school-item/school-item.tsx Outdated Show resolved Hide resolved
Copy link

Lighthouse Report:

  • Performance: 75 / 100
  • Accessibility: 100 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

@Quiddlee
Copy link
Member Author

run visual now

@Quiddlee Quiddlee merged commit 7306559 into main Dec 16, 2024
3 of 4 checks passed
@Quiddlee Quiddlee deleted the refactor/563-widget-school-menu branch December 16, 2024 08:20
@coderabbitai coderabbitai bot mentioned this pull request Dec 24, 2024
8 tasks
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.

FSD: Widget School-menu Rework hover state for Links
4 participants