Skip to content

Conversation

@abhayymishraa
Copy link
Contributor

Resolves #1012

Add the PR description here.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Summary by CodeRabbit

  • New Features
    • The sponsor display now includes additional type information, resulting in improved ordering of sponsor listings.
    • An informational section has been added beneath the logo carousel, featuring details on sponsor importance with call-to-action links for corporate support and sponsorship opportunities.
    • Contribution timeline text on the Contribute page has been updated to reflect a more current status.

Walkthrough

This pull request introduces the sponsor_type field to the GraphQL data model in the SponsorNode class, enhancing data representation. The GET_MAIN_PAGE_DATA query is updated to include the sponsorType field for retrieving sponsor types. The resolve_sponsors method in the SponsorQuery class is modified to sort sponsors based on their type. Additionally, the LogoCarousel component is updated to include a new informational section with call-to-action links for potential sponsors. The SponsorType type definition is also updated to reflect the new field.

Changes

Files Change Summary
backend/.../sponsor.py, frontend/.../homeQueries.ts, frontend/.../home.ts Added the sponsor type field: sponsor_type was added in the backend GraphQL node, sponsorType in the API query, and updated in type definitions.
frontend/.../LogoCarousel.tsx, backend/.../sponsor.py Enhanced the sponsor display by implementing a sorting mechanism for sponsors based on sponsorType and added a new informational section with a call-to-action link.
frontend/.../Contribute.spec.ts Updated test case to reflect a change in expected output for the time since contribution.

Possibly related PRs

  • Improved the "/sponsors" command for slack  #630: The changes in the main PR, which involve adding the sponsor_type field to the SponsorNode class, are related to the modifications in the retrieved PR that enhance the /sponsors command, as both involve the Sponsor model and its attributes.

Suggested labels

nestbot

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

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

18-22: Consider making the sponsor type prioritization more resilient.

The current implementation assumes that sponsor types will always be uppercase and exactly match the keys in the priority object. This might cause issues if the data format changes.

Consider making the sorting more resilient by:

-  const priority = { DIAMOND: 1, PLATINUM: 2, GOLD: 3, SILVER: 4, SUPPORTER: 5, NOT_A_SPONSOR: 6 }
+  const priority = {
+    DIAMOND: 1,
+    PLATINUM: 2,
+    GOLD: 3,
+    SILVER: 4,
+    SUPPORTER: 5,
+    NOT_A_SPONSOR: 6,
+  }
+
+  const getSponsorPriority = (type: string) => {
+    const upperType = type?.toUpperCase();
+    return priority[upperType] || 999; // Default to lowest priority if type not found
+  }
+
+  const sortedSponsors = [...sponsors].sort(
+    (a, b) => getSponsorPriority(a.sponsorType) - getSponsorPriority(b.sponsorType)
+  )

Also, please verify if "NOT_A_SPONSOR" is an actual value that will be used in the system or if it can be removed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8a79e09 and dfa6cbe.

📒 Files selected for processing (4)
  • backend/apps/owasp/graphql/nodes/sponsor.py (1 hunks)
  • frontend/src/api/queries/homeQueries.ts (1 hunks)
  • frontend/src/components/LogoCarousel.tsx (1 hunks)
  • frontend/src/types/home.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: CodeQL (python)
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend unit tests
🔇 Additional comments (5)
backend/apps/owasp/graphql/nodes/sponsor.py (1)

15-15: LGTM! The addition of the sponsor_type field enhances the GraphQL node.

The addition of the "sponsor_type" field to the SponsorNode's Meta class fields tuple is a good enhancement that makes this attribute available via GraphQL. This change is necessary to support the new sorting functionality implemented in the frontend.

frontend/src/types/home.ts (1)

38-38: LGTM! The TypeScript type definition is consistent with the backend changes.

The addition of the sponsorType property to the SponsorType interface provides type safety for the frontend when working with the new field. The naming follows frontend conventions (camelCase) and correctly corresponds to the snake_case field added in the backend.

frontend/src/api/queries/homeQueries.ts (1)

56-56: LGTM! GraphQL query updated to request the new field.

The addition of the sponsorType field to the sponsors section of the GraphQL query allows the frontend to retrieve this data from the backend. This change aligns well with the backend and TypeScript type changes.

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

24-59: LGTM! Carousel implementation now uses sorted sponsors.

The implementation correctly creates a copy of the sponsors array before sorting it and uses the sorted array in the render logic. This ensures sponsors are displayed according to their priority.


60-75: LGTM! Informative section adds context and clear call-to-action.

The addition of an informational section with descriptive text and a "Become a sponsor" link provides good context for users and a clear call-to-action for potential sponsors.

@abhayymishraa abhayymishraa marked this pull request as draft March 6, 2025 19:36
@abhayymishraa abhayymishraa marked this pull request as ready for review March 6, 2025 19:53
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)
backend/apps/owasp/graphql/queries/sponsor.py (1)

17-25: Good implementation of priority-based sorting for sponsors.

The implementation correctly sorts sponsors based on their type using a priority mapping dictionary, which is a clean approach. The diamond sponsors get the highest priority (lowest number), followed by platinum, gold, silver, etc.

However, there's a potential issue: if a sponsor has a sponsor_type that's not in the priority_order dictionary, a KeyError will be raised. Consider handling this edge case:

- return sorted(Sponsor.objects.all(), key=lambda x: priority_order[x.sponsor_type])
+ return sorted(Sponsor.objects.all(), key=lambda x: priority_order.get(x.sponsor_type, 999))  # Use high number for unknown types

This would place any sponsors with unknown types at the end of the list instead of crashing.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6bbf964 and 1ae7859.

📒 Files selected for processing (2)
  • backend/apps/owasp/graphql/queries/sponsor.py (1 hunks)
  • frontend/src/components/LogoCarousel.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/LogoCarousel.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

@arkid15r arkid15r changed the title Added sorting based on types Added sponsors sorting based on their type Mar 6, 2025
@arkid15r arkid15r enabled auto-merge March 6, 2025 23:41
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 6, 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

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/__tests__/e2e/pages/Contribute.spec.ts (1)

20-20: Consider making time-based tests more resilient.

The test has been updated from expecting "2 months ago" to "3 months ago". While this fixes the test in the short term, time-based tests can become fragile as they'll need updates whenever the mock data's timestamp changes.

Consider one of these approaches for more resilient tests:

  1. Use a regex or partial match instead of exact text
  2. Mock the date in your tests to ensure consistent behavior
  3. Test the format pattern rather than the specific output value
- await expect(page.getByText('3 months ago')).toBeVisible()
+ await expect(page.getByText(/\d+ months? ago/)).toBeVisible()
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ae7859 and db0737f.

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

1-69:

❓ Verification inconclusive

Note: Test update seems unrelated to PR objective.

This test update appears to be unrelated to the main PR objective of "Added sorting based on types" and adding a sponsorType field. It's merely adjusting the expected text in a time-based test.

Make sure this change is intentional and verify whether:

  1. The mock data in mockContributeData was updated to change the timestamp
  2. The method for calculating relative times was modified
  3. This change is necessary to accommodate the sponsor type sorting functionality

🏁 Script executed:

#!/bin/bash
# Check if mockContributeData was modified in this PR
git diff --name-only HEAD^ HEAD | grep -q "mockContributeData" && echo "mockContributeData was modified" || echo "mockContributeData was not modified"

# Look for the mock data definition to understand how timestamp is set
cd frontend && grep -r "mockContributeData" --include="*.ts" . | grep -v "import"

Length of output: 574


Action Required: Verify Time Display Update in Contribute Page Tests

The current test update changes the expected relative time text ("3 months ago") without any modification to mockContributeData. Please confirm the following:

  • Relative Time Calculation: Has the method for calculating relative times been updated? If so, please ensure the test reflects the new logic.
  • Intentional Update for Sponsor Sorting: Is this expected text update an intentional side-effect of the sponsor type sorting changes, or was it introduced inadvertently?

@arkid15r arkid15r added this pull request to the merge queue Mar 6, 2025
Merged via the queue into OWASP:main with commit ed957de Mar 6, 2025
18 checks passed
@abhayymishraa abhayymishraa deleted the feat/logoCarousel branch March 7, 2025 03:06
shdwcodr pushed a commit to shdwcodr/Nest that referenced this pull request Jun 5, 2025
* Added sorting based on types

* shifted sorting logic in the backend '

* 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.

Impeove sponsor logo carousel

2 participants