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 #1005

Closed
wants to merge 6 commits into from

Conversation

activus-d
Copy link
Member

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

Add a toogle feature to the 'contributors' section to allow visitors sort the list of contributors by the Number of commits or Lastest commits

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced Open Source Contributors section with toggle functionality.
    • Added ability to view contributors by commit count and latest commit.
    • Integrated a new toggle group component for improved user interaction.
  • Improvements

    • Refined commit data retrieval to support multiple pages.
    • Added type safety for contributor and commit interfaces.
    • Implemented a more dynamic contributor sorting mechanism based on commit activity.
  • Technical Updates

    • Expanded export capabilities for the toggle group component.

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

vercel bot commented Jan 9, 2025

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

Name Status Preview Comments Updated (UTC)
public 🛑 Canceled (Inspect) Jan 10, 2025 8:08am

Copy link

coderabbitai bot commented Jan 9, 2025

📝 Walkthrough

Walkthrough

This pull request introduces updates to the open-source contributors section of the website, focusing on enhancing component exports, contributor display logic, and commit data retrieval. Key changes include exporting the toggle-group component, implementing a new Contributor interface, and modifying the getCommits function to handle multiple pages of commit data. The updates improve type safety and user interaction through a toggle mechanism for viewing contributors based on commit activity.

Changes

File Change Summary
ui/src/index.ts Added export for toggle-group component
website/src/app/[lang]/[region]/(website)/open-source/(components)/contributors-client.tsx Added Contributor interface, implemented toggle functionality for contributor views
website/src/app/[lang]/[region]/(website)/open-source/(components)/get-commits.ts Updated GitHubCommit interface, enhanced commit data fetching across multiple pages
website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx Added new interfaces, improved contributor data processing and sorting

Possibly related PRs

Suggested Labels

website

Suggested Reviewers

  • andrashee
  • ssandino
  • socialincome-dev
  • mkue

Finishing Touches

  • 📝 Generate Docstrings

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.

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

🧹 Nitpick comments (2)
website/src/app/[lang]/[region]/(website)/open-source/(components)/contributors-client.tsx (2)

Line range hint 7-18: Consolidate contributor interfaces

ContributorProp and Contributor interfaces have overlapping properties. Consider using a single interface.

-type ContributorProp = {
-  name: string;
-  commits: number;
-  avatarUrl: string;
-};
-
 interface Contributor {
   id: number;
   name: string;
   avatarUrl: string;
   commits: number;
 }
+
+type ContributorProp = Omit<Contributor, 'id'>;

54-54: Extract magic number to constant

The value 16 for pagination should be defined as a named constant.

+const CONTRIBUTORS_PER_PAGE = 16;
+
 export function OpenSourceContributorsClient({
   // ...
-  const displayedContributors = showAllContributors ? contributors : contributors.slice(0, 16);
+  const displayedContributors = showAllContributors ? contributors : contributors.slice(0, CONTRIBUTORS_PER_PAGE);
📜 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 81c1628.

📒 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)
🧰 Additional context used
🪛 Biome (1.9.4)
website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx

[error] 49-49: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test website
🔇 Additional comments (3)
ui/src/index.ts (1)

30-30: LGTM!

The toggle-group component export is correctly added.

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

Line range hint 6-11: Consider handling null authors

Making the author field non-nullable might cause runtime errors if GitHub API returns null authors for some commits.

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

74-77: LGTM!

Toggle implementation is clean and follows the UI component library patterns.

Copy link

vercel bot commented Jan 9, 2025

@activus-d is attempting to deploy a commit to the Social Income Team on Vercel.

A member of the Team first needs to authorize it.

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

🧹 Nitpick comments (1)
website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (1)

49-54: Strengthen null safety in date comparison.

The null check could be more robust by verifying the date value before creating a Date object.

-if (commit.author?.id && commit.commit?.author?.date) {
+const date = commit.commit?.author?.date;
+if (commit.author?.id && date) {
   const contributorId = commit.author.id;
-  const commitDate = new Date(commit.commit.author.date);
+  const commitDate = new Date(date);
   if (!latestCommitDates.has(contributorId) || commitDate > latestCommitDates.get(contributorId)) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 81c1628 and c270e3e.

📒 Files selected for processing (1)
  • website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test website
🔇 Additional comments (2)
website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (2)

25-31: Well-structured interface definition.

The CombinedContributor interface provides clear type safety for the contributor data structure.


3-3: 🛠️ Refactor suggestion

Remove unused imports.

ToggleGroup and ToggleGroupItem are imported but not used in this file. They appear to be used in the client component instead.

-import { ToggleGroup, ToggleGroupItem } from '@socialincome/ui';

Likely invalid or redundant comment.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c270e3e and 40144e8.

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

25-31: Well-structured interface definition

The CombinedContributor interface provides a clear and type-safe structure for the contributor data.


82-83: 🛠️ Refactor suggestion

Use camelCase for React props

Props should follow camelCase naming convention in React.

-ContributorsByCommitCount={contributorsByCommitCount}
-ContributorsByLatestCommit={contributorsByLatestCommit}
+contributorsByCommitCount={contributorsByCommitCount}
+contributorsByLatestCommit={contributorsByLatestCommit}

Likely invalid or redundant comment.


3-3: Remove unused imports

ToggleGroup and ToggleGroupItem are imported but not used in this file.

@activus-d activus-d changed the title Add a toggle feature to sort open-source contributors Website: Add a toggle feature to sort open-source contributors Jan 9, 2025
@ssandino
Copy link
Member

ssandino commented Jan 9, 2025

@activus-d in case you don't have access to the deployment logs. Here the errors that show up:
Screenshot 2025-01-09 at 09 52 51
Screenshot 2025-01-09 at 09 52 39

Hope this helps to debug.

…fined; use map/filter to combine data in 'combinedContributors' to improve readability
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 (4)
website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (1)

58-67: Extract fallback date as a constant.

Consider extracting new Date(0) as a named constant for better readability and maintainability.

+const FALLBACK_DATE = new Date(0);

const combinedContributors = contributors
  .filter((contributor) => latestCommitDates.has(contributor.id))
  .map((contributor) => ({
    id: contributor.id,
    name: contributor.name,
    avatarUrl: contributor.avatarUrl,
    commits: contributor.commits,
-   latestCommitDate: latestCommitDates.get(contributor.id) || new Date(0),
+   latestCommitDate: latestCommitDates.get(contributor.id) || FALLBACK_DATE,
  }));
website/src/app/[lang]/[region]/(website)/open-source/(components)/contributors-client.tsx (3)

13-18: Consider moving interface to a shared location.

The Contributor interface could be moved to a shared types file since it's used across multiple components.


51-52: Add type safety to toggle value.

Consider using a union type for the toggle value to prevent typos and ensure type safety.

+type ToggleValue = "commit count" | "latest commit";
-const [selectedToggle, setSelectedToggle] = useState("commit count");
+const [selectedToggle, setSelectedToggle] = useState<ToggleValue>("commit count");

56-63: Simplify toggle handler logic.

The conditional logic can be simplified using an object lookup.

+const contributorsMap = {
+  "latest commit": contributorsByLatestCommit,
+  "commit count": contributorsByCommitCount,
+} as const;

const handleToggleChange = (value: string) => {
  setSelectedToggle(value);
-  if (value === "latest commit") {
-    setContributors(contributorsByLatestCommit);
-  } else {
-    setContributors(contributorsByCommitCount);
-  }
+  setContributors(contributorsMap[value as keyof typeof contributorsMap]);
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 40144e8 and d5db96c.

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

45-56: LGTM! Well-structured commit date collection.

The code properly handles null checks and maintains the latest commit date per contributor.


71-77: LGTM! Clean sorting implementation.

The sorting logic is well-implemented with proper type safety.


12-23: 🛠️ Refactor suggestion

Remove duplicate interface definition.

The GitHubCommit interface is already defined in get-commits.ts. Import it instead of redefining.

-interface GitHubCommit {
-  author: {
-    id: number;
-    login: string;
-    avatar_url: string;
-  };
-  commit: {
-    author: {
-      date: string;
-    };
-  };
-}
+import { GitHubCommit } from '../(components)/get-commits';

Likely invalid or redundant comment.

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

73-78: LGTM! Clean toggle group implementation.

The toggle group UI is well-structured with proper spacing and component usage.

@activus-d
Copy link
Member Author

@activus-d in case you don't have access to the deployment logs. Here the errors that show
...
Hope this helps to debug.

Thank you @ssandino

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d5db96c and 7a6d30d.

📒 Files selected for processing (1)
  • website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (2 hunks)
🔇 Additional comments (2)
website/src/app/[lang]/[region]/(website)/open-source/(sections)/contributors.tsx (2)

11-30: LGTM! Well-structured interfaces.

The GitHubCommit and CombinedContributor interfaces provide good type safety and clear data structure.


70-84: LGTM! Clean sorting implementation.

The sorting logic is efficient and the component structure follows React best practices.

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.

2 participants