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

use leaders-list for main page #1207

Merged
merged 8 commits into from
Mar 31, 2025

Conversation

yashgoyal0110
Copy link
Contributor

fixes: #1203

Copy link
Contributor

coderabbitai bot commented Mar 29, 2025

Summary by CodeRabbit

  • New Features

    • Improved the display of leader information by introducing a dedicated component for more consistent and flexible presentation.
    • Enhanced text handling now supports displaying complete information via tooltips when text is truncated.
  • Style

    • Applied a hover underline effect to links for improved interactivity.
    • Refined container styling ensures a more uniform and polished appearance.

Walkthrough

This pull request updates the rendering of leader names by incorporating the LeadersList component into the Home component and utilizing the TruncatedText component within LeadersList. The changes include replacing inline rendering of leaders with the new component, enhancing the structure and styling of the output. Additionally, the TruncatedText component has been modified to accept new props, improving its flexibility in rendering text.

Changes

File Summary
frontend/src/components/LeadersList.tsx Imports TruncatedText for leader names; replaces fragment with TruncatedText and simplifies key assignment for <span> elements. Adds hover:underline class to <Link>.
frontend/src/pages/Home.tsx Integrates LeadersList component for leader names; replaces inline rendering with LeadersList and updates class names for styling consistency.
frontend/src/components/TruncatedText.tsx Updates props to include optional text and new children prop; modifies rendering logic to display either text or children.

Assessment against linked issues

Objective Addressed Explanation
Improve main page recent chapters/projects leader display (#1203) by using LeadersList and wrapping names with TruncatedText

Possibly related PRs

Suggested labels

frontend-tests

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 5a686ef and b10a2f7.

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

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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 (1)
frontend/src/pages/Home.tsx (1)

205-205: Double trimming of leader names

There's a potential minor redundancy in the code. You're trimming each leader name here, but the LeadersList component also performs trimming on the input string again after splitting it.

While not a functional issue, you could consider removing one of these trim operations for slightly better performance.

Also applies to: 240-240

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee53ac6 and f4d8c59.

📒 Files selected for processing (2)
  • frontend/src/components/LeadersList.tsx (1 hunks)
  • frontend/src/pages/Home.tsx (3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
frontend/src/components/LeadersList.tsx (1)
frontend/src/types/leaders.ts (1)
  • LeadersListProps (1-3)
🔇 Additional comments (9)
frontend/src/components/LeadersList.tsx (6)

13-13: Good addition of TruncatedText component

Adding the TruncatedText component improves the handling of potentially long leader names, ensuring a consistent display across the application.


21-21: Improved layout with flex container

Wrapping the list of leaders in a flex container with appropriate spacing classes enhances the layout and provides better control over spacing between items.

Also applies to: 34-34


23-23: Better structure with individual item wrapping

Wrapping each leader item in a span with flex alignment ensures consistent spacing and alignment, especially when leader names wrap to multiple lines.


27-27: Enhanced user experience with hover effect

Adding the hover:underline class provides better visual feedback to users, making it clear that leader names are clickable links.


29-29: Properly handling long text with TruncatedText

Using the TruncatedText component instead of displaying the raw text ensures that overly long leader names will be properly truncated with an ellipsis when needed.


31-31: Improved separator styling

Wrapping the comma separator in a span with margin provides better control over spacing between leaders and ensures consistent styling.

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

26-26: Good component import

Importing the LeadersList component is appropriate for the planned refactoring to improve code reusability.


202-206: Improved chapter leaders display with consistent styling

Using the LeadersList component for chapter leaders improves code maintainability and ensures consistent styling. The CSS class adjustments provide better alignment with the design system.


237-241: Consistent implementation for project leaders

The implementation for project leaders matches the chapter leaders implementation, ensuring a consistent user experience throughout the application.

@yashgoyal0110 yashgoyal0110 force-pushed the fix/using-leaderslist-for-homepage branch from 6706055 to 0105aea Compare March 29, 2025 19:11
@yashgoyal0110 yashgoyal0110 force-pushed the fix/using-leaderslist-for-homepage branch from 87b7106 to 353494c Compare March 29, 2025 19:28
@arkid15r arkid15r requested a review from aramattamara March 29, 2025 23:34
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.

We want to have a consistent looks for recent chapters/projects on the main page.
For achieving that the contents need to be truncated. It's not the case at the moment:

Screenshot 2025-03-30 at 7 14 48 PM

Also make sure to remove extra spacing near commas. For future I suggest focusing on PRs quality in general.

@yashgoyal0110
Copy link
Contributor Author

We want to have a consistent looks for recent chapters/projects on the main page. For achieving that the contents need to be truncated. It's not the case at the moment:

Screenshot 2025-03-30 at 7 14 48 PM Also make sure to remove extra spacing near commas. For future I suggest focusing on PRs quality in general.

Do we need to truncate every leader name or truncation is only needed when leader name div reaches available width?

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/TruncatedText.tsx (3)

35-35: Consider adding children to effect dependencies.

The useEffect hook's dependencies array includes text and checkTruncation, but not children. If changes to children should trigger the truncation check, consider adding it to the dependencies array.

- }, [text, checkTruncation])
+ }, [text, children, checkTruncation])

19-19: Update dependency array in checkTruncation useCallback.

Similar to the useEffect, the useCallback dependency array should include children if it's going to influence the truncation check.

- }, [text])
+ }, [text, children])

1-45: Consider adding JSDoc comments for better documentation.

As this is a public component with updated functionality, adding JSDoc comments would improve developer experience and clarify how to use the component with its new flexibility.

 import { React, useRef, useEffect, useCallback } from 'react'

+/**
+ * TruncatedText component that displays text with ellipsis when it overflows.
+ * @param {object} props - Component props
+ * @param {string} [props.text] - Text to display (takes precedence over children)
+ * @param {React.ReactNode} [props.children] - Children elements to display if text is not provided
+ * @param {string} [props.className] - Additional CSS classes
+ * @returns {JSX.Element} - Rendered component
+ */
 export const TruncatedText = ({
   text,
   children,
   className = '',
 }: {
   text?: string
   children?: React.ReactNode
   className?: string
 }) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 353494c and 3e04229.

📒 Files selected for processing (2)
  • frontend/src/components/LeadersList.tsx (2 hunks)
  • frontend/src/components/TruncatedText.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/LeadersList.tsx
🔇 Additional comments (3)
frontend/src/components/TruncatedText.tsx (3)

3-11: Good enhancement to component flexibility!

Making the text prop optional and adding support for children improves the component's reusability and follows React's compositional pattern. This allows the component to be used in more scenarios and aligns with React's design principles.


17-17: Robust fallback logic for title attribute.

Setting the title attribute with a fallback mechanism ensures it always has meaningful content, which improves accessibility. This is especially important for truncated text where users need to see the full content on hover.


42-42: Rendering logic aligns with updated props.

The component now correctly renders either the text prop or children content, with preference given to text. This is consistent with the updated prop definitions.

@yashgoyal0110 yashgoyal0110 force-pushed the fix/using-leaderslist-for-homepage branch from d7f955e to 454b7c4 Compare March 31, 2025 14:58
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/TruncatedText.tsx (3)

35-35: Missing dependency in useEffect.

The useEffect depends on text but not on children, which could lead to stale behavior if only children changes.

-  }, [text, checkTruncation])
+  }, [text, children, checkTruncation])

42-42: Add a fallback for when both text and children are undefined.

The current implementation renders nothing when both text and children are undefined. Consider adding a default value or fallback message.

-      {text || children}
+      {text || children || ''}

9-9: Document prop precedence when both text and children are provided.

When both text and children are provided, it's not immediately clear which one takes precedence. The implementation prioritizes text, but this behavior should be documented.

Consider adding a comment above the component definition explaining this behavior:

/**
 * TruncatedText component that displays text with truncation.
 * When both text and children are provided, text takes precedence.
 */
export const TruncatedText = ({

Also applies to: 42-42

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e04229 and 48fb083.

📒 Files selected for processing (2)
  • frontend/src/components/LeadersList.tsx (2 hunks)
  • frontend/src/components/TruncatedText.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/LeadersList.tsx
🔇 Additional comments (2)
frontend/src/components/TruncatedText.tsx (2)

3-11: Props enhancement improves component flexibility.

The component now accepts either text or children props, making it more versatile for different usage scenarios. This is a good improvement that aligns with React patterns.


17-17:

❓ Verification inconclusive

Consider the case when children is a complex React node.

When setting the title, the fallback to element.textContent works for string content but might produce unexpected results for complex React node structures.


🏁 Script executed:

#!/bin/bash
# Check where the component is used with complex children
rg -A 3 -B 3 "TruncatedText.*>.*<" --glob "*.tsx" --glob "*.jsx"

Length of output: 66


Action: Review title extraction for non-string children in TruncatedText

The current logic—using element.title = text || element.textContent || ''—relies on element.textContent as a fallback, which works for plain text but could yield unexpected results when children are complex React nodes. Although our initial search didn’t reveal any usages with nested or complex children, it's important to ensure that only plain text is passed or to update the component if support for complex nodes is intended.

Please verify that:

  • All usages of <TruncatedText> pass text (or string-renderable) children.
  • If complex React nodes might be passed in the future, either update the title derivation logic or document that the component only supports plain text.

@yashgoyal0110 yashgoyal0110 force-pushed the fix/using-leaderslist-for-homepage branch from 48fb083 to c29b8c0 Compare March 31, 2025 15:01
@yashgoyal0110 yashgoyal0110 force-pushed the fix/using-leaderslist-for-homepage branch from da2b234 to 3174adc Compare March 31, 2025 15:37
@yashgoyal0110 yashgoyal0110 requested a review from arkid15r March 31, 2025 15:53
@yashgoyal0110
Copy link
Contributor Author

yashgoyal0110 commented Mar 31, 2025

Hey @arkid15r
I have made the changes and enabled truncate component to receive both elements and text as props for wider usecase

@arkid15r arkid15r enabled auto-merge March 31, 2025 16:38
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

@arkid15r arkid15r added this pull request to the merge queue Mar 31, 2025
Merged via the queue into OWASP:main with commit 148ddf3 Mar 31, 2025
20 checks passed
@yashgoyal0110 yashgoyal0110 deleted the fix/using-leaderslist-for-homepage branch April 1, 2025 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve main page recent chapters/projects component
2 participants