Skip to content

adding feature of anchor links #960

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

Merged
merged 47 commits into from
Apr 21, 2025

Conversation

shining-bluemoon-11
Copy link
Contributor

@shining-bluemoon-11 shining-bluemoon-11 commented Feb 28, 2025

RESOLVE #926

Tasks Completed:

  • Added anchor links to major blocks.
  • Implemented smooth scrolling.
  • Updated navigation to use anchor links.
  • Added hover-based visual indicators for anchors.
VID20250228221656.mp4

@shining-bluemoon-11
Copy link
Contributor Author

@arkid15r done

Copy link
Contributor

coderabbitai bot commented Mar 1, 2025

Summary by CodeRabbit

  • New Features

    • Introduced anchor-linked section titles throughout the app using the new AnchorTitle component, enabling easy navigation to key sections.
    • Added smooth scrolling and improved anchor behavior for section navigation.
  • Enhancements

    • Section titles in cards and lists now feature clickable anchor links and consistent styling.
    • Improved flexibility for titles and labels in various components, allowing richer content and elements.
    • Updated empty state messaging for item lists.
  • Bug Fixes

    • Simplified and improved tests for toggling contributor lists.
  • Tests

    • Added end-to-end test verifying the display of top contributors on repository details pages.
    • Refactored unit tests for contributor toggling for clarity and maintainability.
  • Style

    • Added new CSS classes for icon alignment, color inheritance, and section scrolling.
  • Chores

    • Minor code cleanup and import adjustments for consistency.

Walkthrough

This change introduces anchor links to major sections throughout the frontend, enabling direct linking and smooth scrolling to specific content blocks such as "Top Contributors," "Recent Issues," and others. A new AnchorTitle component is implemented and integrated into various components by replacing static string titles with this anchor-enabled title element. Corresponding updates are made to component prop types to accept React.ReactNode instead of string for titles and labels. CSS rules are added to support smooth scrolling and anchor offset. Unit and E2E tests are updated to reflect the new structure and ensure continued correct behavior.

Changes

Files / Areas Changed Summary
src/components/AnchorTitle.tsx New AnchorTitle component added for rendering anchor-linked section titles.
src/components/CardDetailsPage.tsx, RecentIssues.tsx, RecentPullRequests.tsx, Integrated AnchorTitle into section titles, replacing plain strings with anchor-enabled JSX elements.
RecentReleases.tsx, TopContributors.tsx, app/page.tsx
src/components/SecondaryCard.tsx, ToggleableList.tsx, ItemCardList.tsx Updated title/label prop types from string to React.ReactNode for anchor compatibility.
src/app/globals.css Added CSS for smooth scrolling, anchor offset, and icon styling.
__tests__/unit/pages/About.test.tsx, ProjectDetails.test.tsx, RepositoryDetails.test.tsx Simplified contributor toggle tests to use global queries for "Show more"/"Show less" buttons.
__tests__/e2e/pages/RepositoryDetails.spec.ts Added E2E test for visibility of "Top Contributors" section and its content.
__tests__/e2e/pages/Home.spec.ts Added a blank line (no logic changes).

Assessment against linked issues

Objective Addressed Explanation
Add anchor links to all major blocks (Top Contributors, Recent Issues, Recent Releases, etc) (#926)
Ensure clicking anchor links scrolls smoothly to the corresponding section (#926)
Visual indication of anchor link appears only on hover, positioned on right of headers (#926)
Update navigation to use these anchors for better user navigation (if applicable) (#926) No explicit navigation update is shown; only section headers have anchor links.

Possibly related PRs

  • OWASP/Nest#1359: Both PRs modify section titles in shared components; this related PR adds icon props, while the current PR focuses on anchor link functionality.

Suggested reviewers

  • kasya

📜 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 9c8d215 and 8529ed9.

📒 Files selected for processing (3)
  • frontend/__tests__/e2e/pages/Home.spec.ts (1 hunks)
  • frontend/__tests__/e2e/pages/RepositoryDetails.spec.ts (1 hunks)
  • frontend/src/components/AnchorTitle.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/tests/e2e/pages/Home.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/tests/e2e/pages/RepositoryDetails.spec.ts
  • frontend/src/components/AnchorTitle.tsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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: 0

🧹 Nitpick comments (5)
frontend/src/components/ItemCardList.tsx (1)

52-52: Text formatting inconsistency in fallback message.

The fallback message has inconsistent spacing with extra spaces before and after commas and periods.

-      <p>Currently , Nothing to Display . </p>
+      <p>Currently, Nothing to Display.</p>
frontend/src/pages/Home.tsx (1)

169-182: Well-implemented anchor link for New Projects section.

The implementation follows the same pattern as other sections, providing consistent navigation.

The ID new-Projects has inconsistent capitalization. Consider maintaining all-lowercase or kebab-case for IDs:

-            <div id="new-Projects" className="relative scroll-mt-20">
+            <div id="new-projects" className="relative scroll-mt-20">

Also update the corresponding href attribute on line 174.

frontend/src/components/CardDetailsPage.tsx (3)

128-164: Consider enhancing anchor links accessibility for keyboard users.

The implementation for Languages and Topics sections looks good, but the hover-only visibility of the anchor links might present accessibility issues for keyboard or touch device users.

Consider making the link icon visible when the element receives keyboard focus as well:

- className="inherit-color ml-2 opacity-0 transition-opacity duration-200 group-hover:opacity-100"
+ className="inherit-color ml-2 opacity-0 transition-opacity duration-200 group-hover:opacity-100 group-focus-within:opacity-100"

195-218: Consider adding aria-label to anchor links for better screen reader support.

The anchor links implementation for Recent Releases is good, but lacks explicit screen reader support.

Add an aria-label to improve accessibility:

<a
  href="#recent-releases"
  className="inherit-color ml-2 opacity-0 transition-opacity duration-200 group-hover:opacity-100"
+ aria-label="Link to Recent Releases section"
>

41-240: Consider creating a reusable component for section headers with anchor links.

There is significant repetition in the anchor link pattern across multiple sections. This could be refactored into a reusable component to reduce duplication and make future maintenance easier.

Example implementation:

// SectionHeader component
const SectionHeader = ({ id, title }: { id: string; title: string }) => (
  <div id={id} className="relative scroll-mt-20">
    <div className="group relative flex items-center">
      {title}
      <a
        href={`#${id}`}
        className="inherit-color ml-2 opacity-0 transition-opacity duration-200 group-hover:opacity-100"
        aria-label={`Link to ${title} section`}
      >
        <FontAwesomeIcon icon={faLink} className="h-7 w-5" />
      </a>
    </div>
  </div>
);

// Usage
<SecondaryCard title={<SectionHeader id="summary" title="Summary" />}>
  <p>{summary}</p>
</SecondaryCard>
🧰 Tools
🪛 Biome (1.9.4)

[error] 76-81: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e41cd8 and 39af270.

📒 Files selected for processing (9)
  • frontend/__tests__/unit/pages/ProjectDetails.test.tsx (1 hunks)
  • frontend/__tests__/unit/pages/RepositoryDetails.test.tsx (1 hunks)
  • frontend/src/components/CardDetailsPage.tsx (7 hunks)
  • frontend/src/components/ItemCardList.tsx (3 hunks)
  • frontend/src/components/SecondaryCard.tsx (1 hunks)
  • frontend/src/components/ToggleContributors.tsx (2 hunks)
  • frontend/src/components/ToggleableList.tsx (1 hunks)
  • frontend/src/index.css (1 hunks)
  • frontend/src/pages/Home.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: CodeQL (python)
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run frontend e2e tests
🔇 Additional comments (24)
frontend/src/components/SecondaryCard.tsx (1)

8-8: Good type enhancement for title prop

Changing the type from string to React.ReactNode improves flexibility by allowing the title to accept complex JSX elements including anchor links, which aligns with the PR objective of adding anchor links to major blocks.

frontend/__tests__/unit/pages/ProjectDetails.test.tsx (1)

101-101: Improved test selector precision

The change from .closest('div') to .closest('div.mb-8') provides a more specific DOM selector, ensuring the test correctly identifies the contributors section with its new anchor link structure.

frontend/__tests__/unit/pages/RepositoryDetails.test.tsx (1)

102-102: Improved test selector precision

The change from .closest('div') to .closest('div.mb-8') provides a more specific DOM selector, ensuring the test correctly identifies the contributors section with its new anchor link structure.

frontend/src/components/ToggleableList.tsx (2)

5-5: Added React import for JSX support

Adding the React import is necessary when using React.ReactNode type and JSX syntax in the component.


13-13: Good type enhancement for label prop

Changing the type from string to React.ReactNode improves flexibility by allowing the label to accept complex JSX elements including anchor links, which aligns with the PR objective of adding anchor links to major blocks.

frontend/src/index.css (2)

297-299: Good addition of smooth scrolling behavior!

The scroll-behavior: smooth property provides a better user experience by adding a smooth animation when users navigate to anchor links, rather than jumping abruptly to the target location.


301-303: Well implemented utility class for color inheritance.

This .inherit-color class allows elements (like the anchor links) to take on the color of their parent elements, maintaining visual consistency while still being interactive elements.

frontend/src/components/ToggleContributors.tsx (2)

2-2: Clean addition of the link icon import.

The FontAwesome link icon is appropriately imported alongside the existing icons.


32-42: Well-structured anchor link implementation.

This implementation:

  1. Creates a proper anchor point with ID top-contributors
  2. Uses scroll-mt-20 to offset the scroll position and prevent the heading from being hidden under any fixed headers
  3. Implements a clean hover effect where the link icon only appears when hovering over the section heading
  4. Uses the inherit-color class to maintain style consistency

The grouping of elements and relative positioning is also well done.

frontend/src/components/ItemCardList.tsx (2)

2-2: Appropriate addition of React import.

The React import is necessary for using the React.ReactNode type.


11-11: Good type update to support JSX in title.

Changing the title prop type from string to React.ReactNode enables passing JSX elements, which is necessary for implementing the anchor links with icons.

frontend/src/pages/Home.tsx (5)

8-8: Clean addition of the link icon import.

The FontAwesome link icon is correctly imported alongside the existing icons.


132-144: Well-implemented anchor link for New Chapters section.

The structure provides a good user experience with:

  • Proper ID-based anchor
  • Scroll margin to prevent header overlap
  • Hover effect for the link icon
  • Consistent styling using the inherit-color class

211-221: Well-structured anchor link for Chapters Nearby section.

The implementation maintains consistency with the other sections while correctly wrapping the h2 element.


230-243: Properly implemented anchor link for Recent Issues section.

The anchor structure is well implemented with appropriate hover effects and styling.


254-267: Properly implemented anchor link for Recent Releases section.

The anchor is correctly structured with consistent styling and behavior matching the other sections.

frontend/src/components/CardDetailsPage.tsx (8)

1-1: FontAwesome import updated to include faLink icon.

Good addition of the faLink icon which is used for the anchor links throughout the component.


41-57: Anchor link implementation for Summary section adds navigation improvement.

The addition of anchor links provides a nice way for users to link directly to specific sections. The implementation using hover-based visibility is clean and unobtrusive.


60-85: Anchor link implementation for Details section follows consistent pattern.

The same anchor link pattern is consistently applied to the Details section.

🧰 Tools
🪛 Biome (1.9.4)

[error] 76-81: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


87-107: Statistics section anchor link looks good.

The anchor implementation for the Statistics section maintains the consistent pattern seen throughout the component.


171-194: Recent Issues section anchor link implementation is consistent.

The anchor link implementation follows the same pattern as other sections, maintaining consistency throughout the UI.


222-240: Repositories section anchor link implemented consistently.

The anchor link pattern is maintained for the Repositories section, ensuring a consistent user experience.


48-48:

❓ Verification inconclusive

Verify that the 'inherit-color' class is defined in your global CSS.

The inherit-color class is used for the anchor links, but it's not defined in this file. Ensure it's properly defined in your global CSS to avoid styling issues.

Also applies to: 67-67, 94-94, 137-137, 155-155, 178-178, 202-202, 229-229


🏁 Script executed:

#!/bin/bash
# Check if the inherit-color class is defined in the CSS files

echo "Searching for inherit-color class definition..."
rg "\.inherit-color" -t css -t scss

echo "Searching for inherit-color in tailwind config..."
rg "inheritColor|inherit-color" -t js -t ts tailwind

Length of output: 384


Action Required: Verify Global CSS Definition for "inherit-color"

The automated search did not provide conclusive evidence that the "inherit-color" class is defined in your global CSS. It appears either the definition is missing or is located in a file/type not covered by the search. Please manually verify that the global stylesheet includes a definition for .inherit-color (e.g., .inherit-color { color: inherit; }) to ensure the anchor link styling works as intended.


43-43:

❓ Verification inconclusive

Ensure smooth scrolling behavior is enabled in your global CSS.

The scroll-mt-20 class suggests you're implementing smooth scrolling with an offset. Make sure you have defined smooth scrolling behavior in your global CSS.

Also applies to: 62-62, 89-89, 132-132, 150-150, 173-173, 197-197, 224-224


🏁 Script executed:

#!/bin/bash
# Check if smooth scrolling is defined in the CSS files

echo "Searching for scroll-behavior definition..."
rg "scroll-behavior:\s*smooth" -t css -t scss

echo "Checking for smooth scroll in global HTML/CSS..."
rg "html\s*{[^}]*scroll-behavior:\s*smooth" -t css -t scss

echo "Checking for scroll-mt-20 class in tailwind config..."
rg "scrollMargin|scroll-mt" -t js -t ts tailwind

Length of output: 687


Ensure global CSS implements smooth scrolling behavior

The file at frontend/src/components/CardDetailsPage.tsx (line 43) applies the scroll-mt-20 class to create an offset for smooth scrolling. However, our automated search did not conclusively locate a global CSS rule—such as html { scroll-behavior: smooth; }—that enables smooth scrolling. This might be due to configuration differences or search limitations.

Please manually verify that:

  • Your global CSS (e.g., a file like styles/global.css) contains a rule similar to:
    html {
      scroll-behavior: smooth;
    }
  • Your Tailwind configuration is correctly set up to support custom scroll margin classes. Similar usages were found on lines 62, 89, 132, 150, 173, 197, and 224, so consistency across the codebase is important.

If the smooth scrolling behavior is not defined globally, add the necessary CSS rule to ensure consistent behavior.

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

Thank you!
Left some comments:

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

🧹 Nitpick comments (5)
frontend/src/components/TitleWithIcon.tsx (5)

4-8: Props interface looks good but consider making title more flexible.

The interface is well-defined, but you might want to consider using React.ReactNode instead of string for the title prop to allow for more complex title content including nested elements.

interface TitleWithIconProps {
  href: string
  icon: IconProp
-  title: string
+  title: React.ReactNode
}

1-38: Consider adding CSS transition for smoother interactions.

The current implementation only has a transition for opacity. Consider adding transitions for other properties to make the interaction smoother.

<a
  href={href}
- className="inherit-color ml-2 opacity-0 transition-opacity duration-200 group-hover:opacity-100"
+ className="inherit-color ml-2 opacity-0 transform scale-95 transition-all duration-200 group-hover:opacity-100 group-hover:scale-100"
  onClick={handleClick}
  aria-label={`Link to ${typeof title === 'string' ? title : 'this section'}`}
  title={`Link to ${typeof title === 'string' ? title : 'this section'}`}
>

4-38: Add JSDoc comments for better code documentation.

Adding JSDoc comments would improve documentation and provide better IDE hints for users of this component.

+/**
+ * Props for the TitleWithIcon component
+ */
interface TitleWithIconProps {
  href: string
  icon: IconProp
  title: React.ReactNode
}

+/**
+ * A component that renders a title with an anchor link icon that appears on hover.
+ * Clicking the icon smoothly scrolls to the corresponding section.
+ * 
+ * @param props - The component props
+ * @param props.href - The href attribute for the anchor link (should start with #)
+ * @param props.icon - The FontAwesome icon to display
+ * @param props.title - The title content to display
+ * @returns A React component
+ */
const TitleWithIcon: React.FC<TitleWithIconProps> = ({ href, icon, title }) => {
  // Component implementation...
}

22-23: Improve screen reader compatibility.

The current implementation uses items-top which is not a standard Tailwind class. Additionally, the class structure could be improved for better accessibility and maintainability.

- <div id={id} className="relative scroll-mt-20">
-   <div className="group relative flex items-top">
+ <div id={id} className="relative scroll-mt-20 group">
+   <div className="relative flex items-start">

21-34: Enhance user experience with focus states.

Consider adding focus states for better keyboard navigation support, ensuring the component is fully accessible.

  return (
    <div id={id} className="relative scroll-mt-20">
      <div className="group relative flex items-top">
        <h2 className="mb-4 text-2xl font-semibold">{title}</h2>
        <a
          href={href}
-         className="inherit-color ml-2 opacity-0 transition-opacity duration-200 group-hover:opacity-100"
+         className="inherit-color ml-2 opacity-0 transition-opacity duration-200 group-hover:opacity-100 focus:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
          onClick={handleClick}
          aria-label={`Link to ${typeof title === 'string' ? title : 'this section'}`}
        >
          <FontAwesomeIcon icon={icon} className="h-7 w-5" />
        </a>
      </div>
    </div>
  )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 39af270 and daf3979.

📒 Files selected for processing (4)
  • frontend/src/components/CardDetailsPage.tsx (8 hunks)
  • frontend/src/components/TitleWithIcon.tsx (1 hunks)
  • frontend/src/components/ToggleContributors.tsx (2 hunks)
  • frontend/src/pages/Home.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • frontend/src/components/ToggleContributors.tsx
  • frontend/src/pages/Home.tsx
  • frontend/src/components/CardDetailsPage.tsx
🔇 Additional comments (1)
frontend/src/components/TitleWithIcon.tsx (1)

1-2:

❓ Verification inconclusive

Verify FontAwesome dependency inclusion.

Ensure that the FontAwesome packages are correctly listed in your package.json and that you're importing only the icons you need to minimize bundle size.


🏁 Script executed:

#!/bin/bash
# Check FontAwesome packages in package.json
echo "Checking FontAwesome packages in package.json..."
grep -E "@fortawesome" package.json || echo "FontAwesome packages not found in package.json"

# Check if there's a central icon import file
echo "Checking for central icon imports..."
find . -type f -name "*.ts" -o -name "*.tsx" | xargs grep -l "import.*from.*@fortawesome" | sort

# Check if faLink is imported somewhere
echo "Checking for faLink imports..."
find . -type f -name "*.ts" -o -name "*.tsx" | xargs grep -l "faLink" | sort

Length of output: 1912


Action: Validate your FontAwesome dependency setup.

In frontend/src/components/TitleWithIcon.tsx (lines 1–2), you're importing modules from FontAwesome. However, our check for a package.json at the repository root did not find any FontAwesome-related dependencies. If your project uses a separate package.json (for example, within the frontend/ directory), please confirm that packages such as @fortawesome/react-fontawesome and @fortawesome/fontawesome-svg-core are listed there. Also, ensure you import only the icons you truly need to reduce bundle size.

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 comments (1)
frontend/src/pages/Home.tsx (1)

131-234: ⚠️ Potential issue

Missing ID attributes for anchor links.

While you've added anchor links with hrefs (e.g., "#new-chapters", "#recent-issues"), I don't see corresponding ID attributes on the target HTML elements. For the anchor links to work correctly, you need to add matching ID attributes to the elements they should navigate to.

Add ID attributes to each section that corresponds to the anchor href. For example:

-      <div className="grid gap-4 md:grid-cols-2">
+      <div id="new-chapters" className="grid gap-4 md:grid-cols-2">

Apply this pattern to all sections that need anchor links:

  • Add id="new-chapters" to the div at line 131
  • Add id="new-projects" to the div at line 157
  • Add id="chapters-nearby" to the div at line 187
  • Add id="recent-issues" to the div at line 195
  • Add id="recent-releases" to the div at line 207
🧹 Nitpick comments (5)
frontend/src/pages/Home.tsx (5)

158-158: Fix capitalization inconsistency in the anchor ID.

There's an inconsistency in the anchor ID format. All other anchor IDs use lowercase, but this one has a capital 'P' in "Projects".

-          title={<TitleWithIcon href="#new-Projects" icon={faLink} title="New Projects" />}
+          title={<TitleWithIcon href="#new-projects" icon={faLink} title="New Projects" />}

112-253: Consider implementing smooth scrolling for anchor links.

Adding smooth scrolling behavior would enhance the user experience when navigating between sections using the anchor links. This can be done using CSS.

You can add the following CSS to your global styles:

html {
  scroll-behavior: smooth;
}

Or add it to your styled component/CSS-in-JS solution if you're using one. This will ensure smooth scrolling when users click on anchor links.


188-193: Implement a more semantic section structure for "OWASP Chapters Nearby".

For better accessibility and semantic HTML structure, consider wrapping this section in a <section> element or using appropriate ARIA roles.

-      <div className="mb-20">
+      <section id="chapters-nearby" className="mb-20">
        <TitleWithIcon href="#chapters-nearby" icon={faLink} title="OWASP Chapters Nearby" />
        <ChapterMap
          geoLocData={geoLocData}
          style={{ height: '400px', width: '100%', zIndex: '0' }}
        />
-      </div>
+      </section>

194-223: Implement a consistent approach to container elements.

For "Recent Issues" and "Recent Releases", consider adding a wrapper with an ID to each section, rather than relying on the ItemCardList component to serve as the anchor target. This would create a more consistent approach with the other sections.

-      <div className="grid gap-4 md:grid-cols-2">
+      <div className="grid gap-4 md:grid-cols-2">
+        <div id="recent-issues">
          <ItemCardList
            title={<TitleWithIcon href="#recent-issues" icon={faLink} title="Recent Issues" />}
            data={data.recentIssues}
            renderDetails={(item) => (
              /* ... existing code ... */
            )}
          />
+        </div>
+        <div id="recent-releases">
          <ItemCardList
            title={<TitleWithIcon href="#recent-releases" icon={faLink} title="Recent Releases" />}
            data={data.recentReleases}
            renderDetails={(item) => (
              /* ... existing code ... */
            )}
          />
+        </div>
       </div>

132-223: Consider making the anchor link icon more accessible.

For better accessibility, consider adding more context to the anchor links, such as screen reader text that explains the purpose of the links.

In your TitleWithIcon component, you could enhance accessibility with:

<a 
  href={href} 
  className="anchor-link" 
  aria-label={`Link to ${title} section`}
>
  <FontAwesomeIcon icon={icon} />
  <span className="sr-only">Link to {title} section</span>
</a>

This ensures screen readers can properly convey the purpose of these anchor links to users with visual impairments.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 63e5c44 and b2c8854.

📒 Files selected for processing (4)
  • frontend/src/components/CardDetailsPage.tsx (8 hunks)
  • frontend/src/components/TitleWithIcon.tsx (1 hunks)
  • frontend/src/components/ToggleContributors.tsx (2 hunks)
  • frontend/src/pages/Home.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • frontend/src/components/ToggleContributors.tsx
  • frontend/src/components/CardDetailsPage.tsx
  • frontend/src/components/TitleWithIcon.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Run backend tests
  • GitHub Check: CodeQL (python)
  • GitHub Check: Run frontend unit tests
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run frontend e2e tests
🔇 Additional comments (3)
frontend/src/pages/Home.tsx (3)

8-8: The imports for faLink and TitleWithIcon look good.

These imports properly support the anchor link functionality being added to the page.

Also applies to: 27-27


132-134: Anchor link implementation for "New Chapters" looks correct.

The title has been properly updated to use the TitleWithIcon component with appropriate parameters.


132-159: Address the scrolling issue mentioned in previous review.

In previous reviews, it was noted that clicking anchor links in the two-column layout (specifically the second card) causes the page to scroll to the top instead of staying in place. This issue was acknowledged but doesn't appear to be fixed in this update.

To properly test this issue, we need to check if clicking the anchor link for "New Projects" (which is in the second column) causes undesired scrolling behavior.

#!/bin/bash
# Look for any scroll prevention measures or anchor-related JS in the codebase

echo "Checking for scroll prevention measures in TitleWithIcon component..."
fd "TitleWithIcon" -t f --exec cat {} \; | grep -A 10 -B 10 "onClick\|preventDefault\|scroll"

echo "Checking for any smooth scroll implementations..."
rg "scroll-behavior|scrollIntoView" --type=css
rg "scrollIntoView|preventDefault" --type=ts --type=tsx

@shining-bluemoon-11
Copy link
Contributor Author

@arkid15r @kasya done
(as @arkid15r mentioned that the e2e test ( making problem ) so he disabled as a merge requirement
rest all checks passes

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

This is much better! A few more comments:

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

🧹 Nitpick comments (3)
frontend/src/components/AnchorTitle.tsx (3)

5-8: Consider making the title prop more flexible.

The title prop is currently typed as a string, which limits flexibility. Consider allowing React nodes (ReactNode type) to support more complex title content like formatted text or nested elements.

interface AnchorTitleProps {
  href: string
- title: string
+ title: React.ReactNode
}

11-11: Add more robust ID generation.

The current ID generation simply removes '#' characters, but IDs should be unique and valid HTML IDs. Consider a more comprehensive approach to handle special characters and ensure valid ID generation.

- const id = href.replace('#', '')
+ const id = href.replace('#', '').replace(/[^a-zA-Z0-9-_:]/g, '-').toLowerCase()

22-33: Enhance accessibility of the anchor link component.

While the component functions well visually, it could benefit from additional accessibility attributes for screen readers and keyboard navigation.

<div id={id} className="relative scroll-mt-20">
  <div className="items-top group relative flex">
    <h2 className="mb-4 text-2xl font-semibold">{title}</h2>
    <a
      href={href}
      className="inherit-color ml-2 opacity-0 transition-opacity duration-200 group-hover:opacity-100"
      onClick={handleClick}
+     aria-label={`Link to ${typeof title === 'string' ? title : 'this section'}`}
+     title={`Link to ${typeof title === 'string' ? title : 'this section'}`}
    >
      <FontAwesomeIcon icon={faLink} className="h-7 w-5" />
    </a>
  </div>
</div>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b2c8854 and a58ff4e.

📒 Files selected for processing (4)
  • frontend/src/components/AnchorTitle.tsx (1 hunks)
  • frontend/src/components/CardDetailsPage.tsx (7 hunks)
  • frontend/src/components/ToggleContributors.tsx (2 hunks)
  • frontend/src/pages/Home.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • frontend/src/components/ToggleContributors.tsx
  • frontend/src/pages/Home.tsx
  • frontend/src/components/CardDetailsPage.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: CodeQL (python)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run backend tests
🔇 Additional comments (3)
frontend/src/components/AnchorTitle.tsx (3)

13-19: Good implementation of smooth scrolling functionality.

The click handler properly prevents default behavior and uses the smooth scrolling API. The null check before accessing the element is also a good practice.


22-22: Good use of scroll-mt-20 for scroll positioning.

The scroll-mt-20 class ensures the element isn't hidden under fixed headers when scrolled to. This is a thoughtful implementation detail for a better user experience.


27-27:

✅ Verification successful

Verify the color inheritance styling.

The class inherit-color is used for the anchor element, but it's not a standard Tailwind class. Ensure this class is properly defined in your CSS to prevent styling issues.


🏁 Script executed:

#!/bin/bash
# Check if the inherit-color class is defined in the project's CSS files
echo "Searching for inherit-color class definition..."
rg -t css "inherit-color" --no-heading

Length of output: 183


Action: Confirm CSS Definition for "inherit-color"

The verification shows that the inherit-color class is defined in frontend/src/index.css, so there are no styling issues with the anchor element. No further changes are needed.

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

♻️ Duplicate comments (2)
frontend/src/components/AnchorTitle.tsx (2)

12-12: 🛠️ Refactor suggestion

Add validation for the href format.

The current implementation assumes that href always starts with '#', but this isn't validated. If an invalid href is provided, it could lead to unexpected behavior.

-const id = href.replace('#', '')
+const id = href.startsWith('#') ? href.substring(1) : href

17-18: 🛠️ Refactor suggestion

Make the component more resilient to DOM structure changes.

The current implementation tightly couples to the DOM structure by assuming an h2 element exists within the target element. This makes the component brittle to changes.

-const headingHeight = element.querySelector('h2')?.offsetHeight || 0
-const yOffset = -headingHeight - 50
+// Either pass this as a prop or determine it dynamically based on component sizing
+const FIXED_HEADER_OFFSET = 50
+const yOffset = -FIXED_HEADER_OFFSET
🧹 Nitpick comments (3)
frontend/src/components/AnchorTitle.tsx (1)

56-56: Fix the vertical alignment of the icon.

The icon doesn't appear to be vertically centered compared to the text, as noted in previous feedback.

-          <FontAwesomeIcon icon={faLink} className="custom-icon h-7 w-5" />
+          <FontAwesomeIcon icon={faLink} className="custom-icon h-6 w-5 align-middle relative top-[-2px]" />

Consider using the custom-icon class that was added in globals.css to fix the alignment issues instead of inline styles or positioning adjustments.

frontend/src/app/page.tsx (2)

153-157: Consider using the custom-icon class instead of inline positioning.

You're using a negative top position and inline styles to adjust the icon alignment. This is inconsistent with the custom-icon class you've added in globals.css.

-              <FontAwesomeIcon
-                icon={faCalendar}
-                className="relative -top-[8px] h-5 w-5"
-                style={{ verticalAlign: 'middle' }}
-              />
+              <FontAwesomeIcon
+                icon={faCalendar}
+                className="custom-icon h-5 w-5" 
+              />

Apply this change to all similar FontAwesomeIcon instances in this file for consistency.


29-29: Consider using a default export in import statement.

The AnchorTitle component is imported without curly braces, which means it's a default export, yet the import statement doesn't use the default keyword. This is not an issue but could be clearer.

-import AnchorTitle from 'components/AnchorTitle'
+import AnchorTitle from 'components/AnchorTitle'

This suggestion is just for clarity; both approaches work correctly in JavaScript/TypeScript.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e36d0b and 7b49504.

📒 Files selected for processing (19)
  • frontend/__tests__/e2e/pages/ChapterDetails.spec.ts (1 hunks)
  • frontend/__tests__/e2e/pages/Home.spec.ts (3 hunks)
  • frontend/__tests__/e2e/pages/ProjectDetails.spec.ts (3 hunks)
  • frontend/__tests__/e2e/pages/RepositoryDetails.spec.ts (3 hunks)
  • frontend/__tests__/e2e/pages/UserDetails.spec.ts (2 hunks)
  • frontend/__tests__/unit/pages/About.test.tsx (1 hunks)
  • frontend/__tests__/unit/pages/ProjectDetails.test.tsx (1 hunks)
  • frontend/__tests__/unit/pages/RepositoryDetails.test.tsx (1 hunks)
  • frontend/src/app/globals.css (1 hunks)
  • frontend/src/app/page.tsx (7 hunks)
  • frontend/src/components/AnchorTitle.tsx (1 hunks)
  • frontend/src/components/CardDetailsPage.tsx (5 hunks)
  • frontend/src/components/ItemCardList.tsx (3 hunks)
  • frontend/src/components/RecentIssues.tsx (2 hunks)
  • frontend/src/components/RecentPullRequests.tsx (2 hunks)
  • frontend/src/components/RecentReleases.tsx (2 hunks)
  • frontend/src/components/SecondaryCard.tsx (1 hunks)
  • frontend/src/components/ToggleableList.tsx (1 hunks)
  • frontend/src/components/TopContributors.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (16)
  • frontend/tests/unit/pages/ProjectDetails.test.tsx
  • frontend/src/components/ItemCardList.tsx
  • frontend/tests/e2e/pages/ChapterDetails.spec.ts
  • frontend/tests/e2e/pages/Home.spec.ts
  • frontend/tests/e2e/pages/ProjectDetails.spec.ts
  • frontend/src/components/RecentReleases.tsx
  • frontend/src/components/ToggleableList.tsx
  • frontend/tests/e2e/pages/UserDetails.spec.ts
  • frontend/src/components/TopContributors.tsx
  • frontend/tests/e2e/pages/RepositoryDetails.spec.ts
  • frontend/tests/unit/pages/RepositoryDetails.test.tsx
  • frontend/src/components/SecondaryCard.tsx
  • frontend/src/components/RecentPullRequests.tsx
  • frontend/src/components/RecentIssues.tsx
  • frontend/src/components/CardDetailsPage.tsx
  • frontend/tests/unit/pages/About.test.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
frontend/src/app/page.tsx (1)
frontend/src/components/AnimatedCounter.tsx (1)
  • AnimatedCounter (10-35)
🔇 Additional comments (2)
frontend/src/app/globals.css (1)

297-313: Good additions to support smooth scrolling and anchor navigation.

These CSS additions are well-implemented:

  1. The scroll-behavior: smooth property enables smooth scrolling for the entire page
  2. The inherit-color class allows text to inherit its parent's color
  3. The custom-icon class improves icon alignment
  4. The scroll-margin-top property ensures sections don't scroll under fixed headers
frontend/src/app/page.tsx (1)

389-396: Improved structure for counter data display.

Wrapping each counter in a div improves the structure and isolation of each counter element. This makes the code more maintainable and provides better control over the layout.

@shining-bluemoon-11
Copy link
Contributor Author

@kasya done

@shining-bluemoon-11 shining-bluemoon-11 marked this pull request as ready for review April 12, 2025 18:00
@shining-bluemoon-11 shining-bluemoon-11 marked this pull request as draft April 17, 2025 14:20
@kasya kasya marked this pull request as ready for review April 21, 2025 02:01
@arkid15r arkid15r enabled auto-merge April 21, 2025 03:24
Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

LGTM!

@arkid15r arkid15r added this pull request to the merge queue Apr 21, 2025
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

LGTM, it's a great base for further improvements!

Thank you @shining-bluemoon-11!

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Apr 21, 2025
@arkid15r arkid15r added this pull request to the merge queue Apr 21, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 21, 2025
@arkid15r arkid15r enabled auto-merge April 21, 2025 05:43
Copy link

@arkid15r arkid15r added this pull request to the merge queue Apr 21, 2025
Merged via the queue into OWASP:main with commit 03d8e6d Apr 21, 2025
22 checks passed
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.

Improve Entity Details Component with Anchors for Direct Linking
3 participants