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

Website: Add a toggle feature to sort open-source contributors #1006

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

activus-d
Copy link
Member

@activus-d activus-d commented Jan 10, 2025

Add a toggle feature to the 'contributors' section to allow sorting the list of contributors by the number of commits or latest commits.

Summary by CodeRabbit

  • New Features

    • Enhanced Open Source Contributors section with toggle to view contributors by commit count or latest commit.
    • Added new interfaces for contributors and commits, improving data structure clarity.
    • Introduced a maximum width constraint for issue title display.
  • Bug Fixes

    • Resolved potential null issues with GitHub commit author data.
  • Refactor

    • Updated contributor data handling and sorting mechanisms.
    • Improved type safety for contributor and commit interfaces.
    • Added new export for the toggle-group component for better accessibility.

…to sort the list of contributors by the number of commits or the lastest commits
Copy link

vercel bot commented Jan 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
public ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2025 11:23am

Copy link

coderabbitai bot commented Jan 10, 2025

📝 Walkthrough

Walkthrough

This pull request introduces enhancements to the open-source contributors section of the website. The changes include updating the index.ts to export the toggle-group component, modifying the contributors client component to support dynamic sorting, improving commit data retrieval, and refactoring the contributors section to handle more complex contributor data processing.

Changes

File Change Summary
ui/src/index.ts Added export for toggle-group component
website/src/app/.../contributors-client.tsx Added Contributor interface, updated component to support toggle-based contributor sorting
website/src/app/.../get-commits.ts Updated GitHubCommit interface, enhanced commit data fetching logic
website/src/app/.../contributors.tsx Added new interfaces, improved contributor data processing and sorting
website/src/app/.../issue.tsx Updated TableCell class name for title display
website/src/app/.../issues-client.tsx Added empty <TableCell> in the issues table header

Sequence Diagram

sequenceDiagram
    participant Fetch as Commit Data Fetcher
    participant Process as Contributor Processor
    participant Client as Contributors Client
    
    Fetch->>Process: Retrieve GitHub Commits
    Process->>Process: Sort Contributors
    Process->>Client: Pass Sorted Contributors
    Client->>Client: Render with Toggle Group
Loading

Possibly related PRs

  • Website: Combine the fetch logic in open-source page #985: The changes in this PR involve the introduction of a new fetchData function that centralizes data fetching logic, which may relate to the toggle-group component's accessibility in the main PR by potentially utilizing the same data-fetching patterns or components.

Suggested labels

website

Suggested reviewers

  • andrashee
  • ssandino
  • socialincome-dev

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@activus-d activus-d marked this pull request as draft January 10, 2025 10:03
Copy link

@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 (2)
website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (1)

44-55: Consider optimizing commit date processing

The current implementation iterates through all commits. Consider using reduce for better performance:

-const latestCommitDates = new Map<number, Date>();
-totalCommitsData.forEach((commit: GitHubCommit) => {
-  if (commit.author?.id && commit.commit?.author?.date) {
-    const contributorId = commit.author.id;
-    const commitDate = new Date(commit.commit.author.date);
-    const existingDate = latestCommitDates.get(contributorId);
-    if (!existingDate || commitDate > existingDate) {
-      latestCommitDates.set(contributorId, commitDate);
-    }
-  }
-});
+const latestCommitDates = totalCommitsData.reduce((acc, commit) => {
+  if (commit.author?.id && commit.commit?.author?.date) {
+    const commitDate = new Date(commit.commit.author.date);
+    const existingDate = acc.get(commit.author.id);
+    if (!existingDate || commitDate > existingDate) {
+      acc.set(commit.author.id, commitDate);
+    }
+  }
+  return acc;
+}, new Map<number, Date>());
website/src/app/[lang]/[region]/(website)/open-source/(components)/contributors-client.tsx (1)

73-78: Add accessibility attributes to toggle group

Enhance accessibility by adding ARIA labels:

-<section className="flex mb-10">
+<section className="flex mb-10" role="region" aria-label="Sort contributors">
   <ToggleGroup type="single" value={selectedToggle} onValueChange={handleToggleChange}>
-    <ToggleGroupItem value="commit count">Commit Count</ToggleGroupItem>
-    <ToggleGroupItem value="latest commit">Latest Commit</ToggleGroupItem>
+    <ToggleGroupItem value="commit count" aria-label="Sort by commit count">Commit Count</ToggleGroupItem>
+    <ToggleGroupItem value="latest commit" aria-label="Sort by latest commit">Latest Commit</ToggleGroupItem>
   </ToggleGroup>
 </section>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 55b7607 and 92c7c0d.

📒 Files selected for processing (4)
  • ui/src/index.ts (1 hunks)
  • website/src/app/[lang]/[region]/(website)/open-source/(components)/contributors-client.tsx (4 hunks)
  • website/src/app/[lang]/[region]/(website)/open-source/(components)/get-commits.ts (2 hunks)
  • website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test website
  • GitHub Check: Security checks (typescript)
  • GitHub Check: Prettify
🔇 Additional comments (7)
ui/src/index.ts (1)

30-30: LGTM! Export follows established patterns.

The new toggle-group export maintains consistency with existing exports and supports the PR's toggle feature implementation.

website/src/app/[lang]/[region]/(website)/open-source/(components)/get-commits.ts (3)

Line range hint 6-11: LGTM: Type safety improvement

The interface update ensures type safety by making the author field non-nullable.


59-65: LGTM: Return value enhancement

The addition of totalCommitsData to the return value supports the new sorting feature.


50-57: Add error handling and rate limit considerations

The pagination implementation could:

  1. Hit GitHub API rate limits with large repositories
  2. Fail silently if API requests fail

Add error handling and consider implementing rate limiting:

 for (let page = 1; page <= Math.ceil(totalCommits / 100); page++) {
+  try {
     const pagedUrl = `https://api.github.com/repos/${owner}/${repo}/commits?per_page=100&page=${page}`;
     const pagedRes = await fetchData(owner, repo, pagedUrl);
+    if (!pagedRes.ok) {
+      throw new Error(`Failed to fetch page ${page}: ${pagedRes.statusText}`);
+    }
     const pagedData: GitHubCommit[] = await pagedRes.json();
     totalCommitsData = totalCommitsData.concat(pagedData);
+    // Add delay to respect rate limits
+    await new Promise(resolve => setTimeout(resolve, 1000));
+  } catch (error) {
+    console.error(`Error fetching commits page ${page}:`, error);
+    break;
+  }
 }
website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (1)

70-76: LGTM: Clean sorting implementation

The sorting implementation is well-structured:

  • Creates new arrays to avoid mutations
  • Clear sorting logic for both criteria
website/src/app/[lang]/[region]/(website)/open-source/(components)/contributors-client.tsx (2)

13-18: LGTM: Well-defined interface

The Contributor interface properly defines all required fields.


51-52: LGTM: Clean state management

The state management implementation is efficient and properly initialized.

@activus-d activus-d marked this pull request as ready for review January 10, 2025 15:31
Copy link

@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

🔭 Outside diff range comments (1)
website/src/app/[lang]/[region]/(website)/open-source/(components)/get-commits.ts (1)

Line range hint 6-11: Handle potential null author values from GitHub API

The GitHub API can return null for the author field when commits are made with unregistered email addresses. The interface should allow for null values.

-	author: {
+	author: {
		id: number;
		login: string;
		avatar_url: string;
-	};
+	} | null;
🧹 Nitpick comments (1)
website/src/app/[lang]/[region]/(website)/open-source/(components)/contributors-client.tsx (1)

Line range hint 87-94: Consider performance optimizations for large lists

For better performance with large contributor lists:

  1. Implement virtualization using a library like react-window
  2. Memoize contributor components
+import { FixedSizeGrid } from 'react-window';
+
+const MemoizedContributor = React.memo(Contributor);
+
 <section className="flex flex-wrap gap-4">
-	{displayedContributors.map((contributor: Contributor) => (
-		<Contributor
+	{displayedContributors.map((contributor: Contributor) => (
+		<MemoizedContributor
 			key={contributor.id}
 			name={contributor.name}
 			commits={contributor.commits}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 92c7c0d and 391e3d3.

📒 Files selected for processing (6)
  • ui/src/index.ts (1 hunks)
  • website/src/app/[lang]/[region]/(website)/open-source/(components)/contributors-client.tsx (4 hunks)
  • website/src/app/[lang]/[region]/(website)/open-source/(components)/get-commits.ts (2 hunks)
  • website/src/app/[lang]/[region]/(website)/open-source/(components)/issue.tsx (1 hunks)
  • website/src/app/[lang]/[region]/(website)/open-source/(components)/issues-client.tsx (1 hunks)
  • website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • website/src/app/[lang]/[region]/(website)/open-source/(components)/issue.tsx
  • website/src/app/[lang]/[region]/(website)/open-source/(components)/issues-client.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • ui/src/index.ts
🔇 Additional comments (3)
website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (2)

44-66: Well-implemented data processing logic

Efficient use of Map for tracking commit dates and proper filtering of contributors.


70-76: Clean and efficient sorting implementation

Good use of spread operator to avoid mutations and clear sorting logic.

website/src/app/[lang]/[region]/(website)/open-source/(components)/contributors-client.tsx (1)

80-85: Well-implemented toggle functionality

Clean integration with UI library and proper state management.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant