Skip to content

Conversation

@codic-yeeshu
Copy link
Contributor

Resolves #1355

  • Updated the UI behavior for member and project links to ensure proper hover effects and cursor styles.

  • Jest test cases have been updated to reflect the changes in the navigation logic, ensuring the correct URL patterns are being used.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 15, 2025

Summary by CodeRabbit

  • New Features
    • Introduced new utility functions for generating member and project URLs.
  • Refactor
    • Updated contributor navigation to use direct links instead of button-based navigation for a more consistent user experience.
    • Replaced usage of project URLs with project keys throughout the application and data structures.
  • Tests
    • Adjusted unit and mock data tests to reflect changes from project URLs to project keys and updated navigation verification.
  • Bug Fixes
    • Improved accuracy of contributor link rendering and navigation behavior.

Summary by CodeRabbit

  • New Features

    • Introduced utility functions for generating consistent project and member URLs.
  • Refactor

    • Updated contributor and project navigation to use clickable links instead of button-based navigation.
    • Centralized URL formatting for member and project links.
    • Improved conditional styling and link behavior for contributor and project names.
  • Tests

    • Updated tests to verify link attributes directly instead of simulating click events.

Walkthrough

This change refactors the TopContributors component to use Next.js Link elements for navigation to user and project pages, replacing imperative routing with declarative links. The contributor and project names are now individually wrapped in anchor elements, each with appropriate URLs generated by new utility functions. Associated unit tests for project and repository details pages are updated to check for correct anchor elements and href attributes, rather than simulating click events. A new utility module, urlFormatter.ts, is introduced to centralize and standardize URL creation for members and projects.

Changes

Files/Paths Change Summary
frontend/src/components/TopContributors.tsx Refactored to replace router-based navigation with Next.js Link components for user and project links; updated logic for conditional linking and styling; uses new URL formatting utilities.
frontend/src/utils/urlFormatter.ts Introduced new utility module exporting getProjectUrl and getMemberUrl functions for consistent URL formatting.
frontend/__tests__/unit/pages/ProjectDetails.test.tsx,
frontend/__tests__/unit/pages/RepositoryDetails.test.tsx
Updated tests to assert the presence and correct href attributes of anchor elements for contributors, removing click simulation and router assertions.
backend/apps/github/graphql/nodes/repository_contributor.py,
backend/apps/github/graphql/queries/repository_contributor.py
Replaced project_url field with project_key in GraphQL schema and query; updated query to fetch project key instead of URL; removed usage of project_url.
frontend/__tests__/e2e/data/mockHomeData.ts,
frontend/__tests__/unit/data/mockContributeData.ts,
frontend/__tests__/unit/data/mockProjectData.ts
Updated mock data to replace projectUrl with projectKey or project_key accordingly in top contributors and issue data.
frontend/src/server/queries/homeQueries.ts Modified GraphQL query to replace projectUrl field with projectKey in topContributors selection set.
frontend/src/types/contributor.ts Updated type definition by removing projectUrl and adding projectKey as an optional property in TopContributorsTypeGraphql.

Assessment against linked issues

Objective Addressed Explanation
Make user and project names in TopContributors separate clickable links with titles (hover event) (#1355)
Use consistent, declarative navigation (e.g., Next.js Link) for user and project links in TopContributors (#1355)

Possibly related PRs

  • Migration from React to Nextjs(Initial step) #1236: Migration of frontend components and tests from React Router and Chakra UI to Next.js routing and HeroUI components, including replacing imperative navigation with Next.js Link components and updating tests accordingly.

Suggested labels

backend

Suggested reviewers

  • kasya
✨ Finishing Touches
  • 📝 Generate Docstrings

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

🧹 Nitpick comments (2)
frontend/src/utils/urlFormatter.ts (1)

8-10: Consider adding validation for the login name.

The getMemberUrl function accepts any string as input without validation, which could lead to invalid URLs if incorrect values are passed.

export const getMemberUrl = (loginName = ''): string => {
+  // Sanitize the login name to prevent invalid URLs
+  const sanitizedLogin = loginName ? loginName.trim() : '';
+  return `/members/${sanitizedLogin}`
-  return `/members/${loginName}`
}
frontend/src/components/TopContributors.tsx (1)

1-101: Consider splitting component into two separate components.

The component currently handles two different types of content (contributors and projects) with conditional rendering and behavior based on the type prop. This mixed responsibility makes the component harder to maintain and understand.

Consider refactoring into separate components or using more explicit prop-based configuration for the different display modes. This would improve component clarity and maintainability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 317b881 and 249d0b9.

📒 Files selected for processing (4)
  • frontend/__tests__/unit/pages/ProjectDetails.test.tsx (1 hunks)
  • frontend/__tests__/unit/pages/RepositoryDetails.test.tsx (1 hunks)
  • frontend/src/components/TopContributors.tsx (3 hunks)
  • frontend/src/utils/urlFormatter.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
frontend/src/components/TopContributors.tsx (3)
frontend/src/types/link.ts (1)
  • Link (1-6)
frontend/src/utils/urlFormatter.ts (2)
  • getMemberUrl (8-10)
  • getProjectUrl (3-6)
frontend/src/utils/capitalize.ts (1)
  • capitalize (1-4)
🔇 Additional comments (4)
frontend/__tests__/unit/pages/RepositoryDetails.test.tsx (1)

133-134: LGTM! Good switch to testing declarative links.

The test has been properly updated to verify the presence and correctness of the href attribute on the contributor link, which aligns with the component's new declarative navigation approach.

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

131-132: LGTM! Good switch to testing declarative links.

The test has been properly updated to verify the presence and correctness of the href attribute on the contributor link, which aligns with the component's new declarative navigation approach.

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

37-38: Good semantic naming for clarity.

Creating a named variable for the type check improves readability compared to repeating the condition.


56-61: LGTM! Good implementation of the member link.

The implementation correctly wraps the contributor name in a Next.js Link component, providing proper styling and navigation to the member page.

Comment on lines 3 to 6
export const getProjectUrl = (url: string): string => {
const projectName = _.last(_.split(url, 'www-project-')) || ''
return `/projects/${projectName}`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for invalid project URLs.

The getProjectUrl function assumes URLs will always contain 'www-project-' and extracts the project name by splitting on this pattern. However, this approach may break if the URL format changes or if an invalid URL is passed.

Consider adding validation and more robust error handling:

export const getProjectUrl = (url: string): string => {
+  if (!url) return '/projects';
  const projectName = _.last(_.split(url, 'www-project-')) || ''
+  if (!projectName) {
+    console.warn('Could not extract project name from URL:', url);
+  }
  return `/projects/${projectName}`
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getProjectUrl = (url: string): string => {
const projectName = _.last(_.split(url, 'www-project-')) || ''
return `/projects/${projectName}`
}
export const getProjectUrl = (url: string): string => {
if (!url) return '/projects';
const projectName = _.last(_.split(url, 'www-project-')) || ''
if (!projectName) {
console.warn('Could not extract project name from URL:', url);
}
return `/projects/${projectName}`
}

@codic-yeeshu codic-yeeshu force-pushed the feat/top-contributors-link-update branch from 249d0b9 to c0fa49d Compare April 15, 2025 06:35
@sonarqubecloud
Copy link

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

🧹 Nitpick comments (1)
backend/apps/github/graphql/queries/repository_contributor.py (1)

57-59: Consider using Project.nest_key instead of manual string replacement.

The Project model already has a nest_key property that performs the same replace("www-project-", "") operation. Consider using that property to maintain consistency and avoid duplicating logic.

You could modify the query to use the nest_key property or create a database function that implements the same logic, depending on what's more efficient for your database setup.

Alternatively, consider creating a utility function in Python that's used consistently across the codebase:

def get_nest_key(project_key):
    """Convert a project key to a nest key by removing the www-project- prefix."""
    return project_key.replace("www-project-", "") if project_key else ""

Then use this function both in the model's property and in this query.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c0fa49d and e898da2.

📒 Files selected for processing (9)
  • backend/apps/github/graphql/nodes/repository_contributor.py (1 hunks)
  • backend/apps/github/graphql/queries/repository_contributor.py (3 hunks)
  • frontend/__tests__/e2e/data/mockHomeData.ts (1 hunks)
  • frontend/__tests__/unit/data/mockContributeData.ts (1 hunks)
  • frontend/__tests__/unit/data/mockProjectData.ts (1 hunks)
  • frontend/src/components/TopContributors.tsx (3 hunks)
  • frontend/src/server/queries/homeQueries.ts (1 hunks)
  • frontend/src/types/contributor.ts (1 hunks)
  • frontend/src/utils/urlFormatter.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • frontend/tests/unit/data/mockContributeData.ts
  • frontend/src/types/contributor.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/TopContributors.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
backend/apps/github/graphql/queries/repository_contributor.py (1)
backend/apps/owasp/models/project.py (1)
  • Project (18-279)
🔇 Additional comments (4)
frontend/src/server/queries/homeQueries.ts (1)

32-32: LGTM! Good data structure update.

Replacing projectUrl with projectKey is a better approach as it separates data from presentation concerns. This change enables the new navigation pattern where links can be generated consistently from keys rather than storing complete URLs in the backend.

frontend/__tests__/unit/data/mockProjectData.ts (1)

16-16: LGTM! Mock data properly updated.

The mock data has been correctly updated to match the new data model, replacing projectUrl with projectKey. This ensures unit tests will work with the updated TopContributors component implementation.

backend/apps/github/graphql/nodes/repository_contributor.py (1)

13-13: LGTM! Good schema field update.

Replacing project_url with project_key in the GraphQL schema is a better architectural approach. It properly separates data from presentation concerns and allows for more flexible URL generation on the frontend side. This change aligns well with your goal of improving navigation in the TopContributors component.

frontend/__tests__/e2e/data/mockHomeData.ts (1)

92-92: LGTM! End-to-end test data properly updated.

The mock data has been correctly updated for all three contributors, replacing projectUrl with appropriate projectKey values that match real project identifiers. This ensures end-to-end tests will work correctly with the updated TopContributors component implementation.

Also applies to: 100-100, 108-108

Comment on lines +1 to +2
export const getMemberUrl = (login: string): string => `/members/${login}`
export const getProjectUrl = (projectKey: string): string => `/projects/${projectKey}`
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation and JSDoc comments to the URL formatter functions.

These utility functions need input validation and documentation for better maintainability:

+/**
+ * Constructs a URL path to a member's page
+ * @param login - The GitHub username of the member
+ * @returns The URL path to the member's page
+ */
-export const getMemberUrl = (login: string): string => `/members/${login}`
+export const getMemberUrl = (login: string): string => {
+  if (!login) return '/members';
+  return `/members/${encodeURIComponent(login)}`;
+}

+/**
+ * Constructs a URL path to a project's page
+ * @param projectKey - The key identifier for the project
+ * @returns The URL path to the project's page
+ */
-export const getProjectUrl = (projectKey: string): string => `/projects/${projectKey}`
+export const getProjectUrl = (projectKey: string): string => {
+  if (!projectKey) return '/projects';
+  return `/projects/${encodeURIComponent(projectKey)}`;
+}

This implementation:

  1. Adds fallback for empty/null/undefined inputs
  2. Uses encodeURIComponent to handle special characters in parameters
  3. Provides JSDoc comments explaining function purpose and parameters
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getMemberUrl = (login: string): string => `/members/${login}`
export const getProjectUrl = (projectKey: string): string => `/projects/${projectKey}`
/**
* Constructs a URL path to a member's page
* @param login - The GitHub username of the member
* @returns The URL path to the member's page
*/
export const getMemberUrl = (login: string): string => {
if (!login) return '/members';
return `/members/${encodeURIComponent(login)}`;
}
/**
* Constructs a URL path to a project's page
* @param projectKey - The key identifier for the project
* @returns The URL path to the project's page
*/
export const getProjectUrl = (projectKey: string): string => {
if (!projectKey) return '/projects';
return `/projects/${encodeURIComponent(projectKey)}`;
}

contributions_count=trc["contributions_count"],
login=trc["user__login"],
name=trc["user__name"],
project_key=trc["project_key"].replace("www-project-", ""),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check before using the replace method.

The code currently assumes project_key will always be a string. If for any reason trc["project_key"] is None, calling .replace() will cause a runtime error.

-                project_key=trc["project_key"].replace("www-project-", ""),
+                project_key=trc["project_key"].replace("www-project-", "") if trc["project_key"] else "",

This adds a null check to prevent potential runtime errors when accessing the project_key field.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
project_key=trc["project_key"].replace("www-project-", ""),
project_key=trc["project_key"].replace("www-project-", "") if trc["project_key"] else "",

@arkid15r arkid15r enabled auto-merge April 16, 2025 01:08
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 Apr 16, 2025
Merged via the queue into OWASP:main with commit d6072ee Apr 16, 2025
22 checks passed
shdwcodr pushed a commit to shdwcodr/Nest that referenced this pull request Jun 5, 2025
…avigation (OWASP#1374)

* feat: update TopContributors to use separate links for member and project navigation

* Update code

---------

Co-authored-by: Arkadii Yakovets <[email protected]>
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 top cotributors component

2 participants