Skip to content

Introduced new components for recent items.#1239

Merged
arkid15r merged 4 commits intoOWASP:mainfrom
codic-yeeshu:enhancement/added-separate-components
Apr 3, 2025
Merged

Introduced new components for recent items.#1239
arkid15r merged 4 commits intoOWASP:mainfrom
codic-yeeshu:enhancement/added-separate-components

Conversation

@codic-yeeshu
Copy link
Contributor

Resolves #1202

  • Implemented separate components for RecentIssues, RecentPullRequests, and RecentReleases, improving code reusability and maintainability across the main page, user details page, and project details page.

  • Added additional test cases for the About page, increasing test coverage to meet the 75% branch coverage.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 31, 2025

Summary by CodeRabbit

  • New Features

    • Updated the interface to display dedicated sections for recent issues, pull requests, and releases on both the card details and home pages for a cleaner, more organized view.
  • Tests

    • Expanded test coverage to ensure proper behavior during loading, error conditions, and notifications, reinforcing overall reliability.

Walkthrough

This pull request introduces new unit tests for the About component to verify behaviors during loading, error, and GraphQL failure states using a toaster notification. Additionally, it refactors the display of recent entities by replacing the old ItemCardList logic with three reusable components: RecentIssues, RecentPullRequests, and RecentReleases. Updates have been made in both the card details and home pages, with redundant import statements and utilities removed in favor of the dedicated components.

Changes

File(s) Change Summary
frontend/__tests__/unit/pages/About.test.tsx Added test cases for loading spinner, error state, and toaster error notification; introduced a new import for toaster.
frontend/src/components/CardDetailsPage.tsx
frontend/src/pages/Home.tsx
Replaced usage of ItemCardList with new components (RecentIssues, RecentPullRequests, RecentReleases) and removed obsolete utilities and imports.
frontend/src/components/RecentIssues.tsx
frontend/src/components/RecentPullRequests.tsx
frontend/src/components/RecentReleases.tsx
Introduced new reusable React components for recent issues, pull requests, and releases with internal logic for data formatting and rendering.

Assessment against linked issues

Objective Addressed Explanation
Implement separate components for RecentIssues, RecentPullRequests, and RecentReleases [#1202]

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 4c2bab0 and 9abb929.

📒 Files selected for processing (1)
  • frontend/src/pages/Home.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/pages/Home.tsx

🪧 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 (5)
frontend/src/components/RecentReleases.tsx (2)

27-28: Use unique identifiers instead of array index as React keys

Using array index as keys in React lists can lead to rendering issues when the list order changes or items are added/removed.

-            {data.map((item, index) => (
-              <div key={index} className="mb-4 w-full rounded-lg bg-gray-200 p-4 dark:bg-gray-700">
+            {data.map((item) => (
+              <div key={item.id || item.tagName} className="mb-4 w-full rounded-lg bg-gray-200 p-4 dark:bg-gray-700">

If neither id nor tagName is guaranteed to be unique, consider using a combination of fields or a library like uuid to generate unique keys.


25-68: Add null/undefined checks for item properties

There are inconsistent null checks throughout the component. Some properties use optional chaining while others don't. For example, item.name (line 50) is accessed directly while item?.author?.avatarUrl uses optional chaining. To prevent potential runtime errors, apply optional chaining consistently.

-                        {item.name}
+                        {item?.name}

Also, add similar checks for other properties like item.publishedAt and item.tagName in lines 57 and 59.

frontend/src/components/RecentPullRequests.tsx (3)

17-19: Consider using more specific type definitions

The data prop accepts a union type of ItemCardPullRequests[] | PullRequestsType[], which is flexible but might lead to type safety issues. Consider using a more specific approach:

  1. Use a common interface that both types implement
  2. Add type guards to ensure type safety when accessing properties
  3. Or use generics to make the component more type-safe
interface CommonPullRequestFields {
  createdAt: string;
  author: {
    name?: string;
    login: string;
    avatarUrl?: string;
  };
  commentsCount?: number;
  // other common fields
}

interface RecentPullRequestsProps<T extends CommonPullRequestFields> {
  data: T[];
  showAvatar?: boolean;
  variant?: PullRequestVariant;
}

38-52: Improve conditional rendering with early returns

The conditional rendering logic can be simplified for better readability:

-          {variant === 'author'
-            ? (item?.author.name || item?.author.login) && (
-                <>
-                  <FontAwesomeIcon icon={faUser} className="ml-4 mr-2 h-4 w-4" />
-                  <span>{item.author.name || item.author.login}</span>
-                </>
-              )
-            : item?.commentsCount && (
-                <>
-                  <FontAwesomeIcon icon={faFileCode} className="ml-4 mr-2 h-4 w-4" />
-                  <span>
-                    {item.commentsCount} {pluralize(item.commentsCount, 'comment')}
-                  </span>
-                </>
-              )}
+          {variant === 'author' && (item?.author?.name || item?.author?.login) && (
+            <>
+              <FontAwesomeIcon icon={faUser} className="ml-4 mr-2 h-4 w-4" />
+              <span>{item.author?.name || item.author?.login}</span>
+            </>
+          )}
+          {variant === 'comments' && item?.commentsCount && (
+            <>
+              <FontAwesomeIcon icon={faFileCode} className="ml-4 mr-2 h-4 w-4" />
+              <span>
+                {item.commentsCount} {pluralize(item.commentsCount, 'comment')}
+              </span>
+            </>
+          )}

This approach makes the code more readable and consistent.


37-37: Add optional chaining for createdAt

To be consistent with other property accesses and prevent potential runtime errors, use optional chaining for the createdAt property:

-          <span>{formatDate(item.createdAt)}</span>
+          <span>{formatDate(item?.createdAt)}</span>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 70b9780 and f5d3bb7.

📒 Files selected for processing (6)
  • frontend/__tests__/unit/pages/About.test.tsx (3 hunks)
  • frontend/src/components/CardDetailsPage.tsx (2 hunks)
  • frontend/src/components/RecentIssues.tsx (1 hunks)
  • frontend/src/components/RecentPullRequests.tsx (1 hunks)
  • frontend/src/components/RecentReleases.tsx (1 hunks)
  • frontend/src/pages/Home.tsx (2 hunks)
🔇 Additional comments (18)
frontend/src/components/RecentIssues.tsx (1)

1-40: Excellent modular component implementation!

This new RecentIssues component effectively encapsulates the display logic for issue lists, making it reusable across different pages. The implementation follows React best practices with:

  • Clear prop interface definition
  • Default prop values
  • Conditional rendering for comments
  • Proper use of utility functions

One minor suggestion would be to consider adding prop documentation comments to enhance code maintainability for future developers.

frontend/src/components/CardDetailsPage.tsx (3)

7-9: Good refactoring to use dedicated components.

The addition of these specialized import statements aligns with the PR objective of improving code reusability by introducing dedicated components for different types of recent items.


125-130: Clean implementation of specialized components.

The replacement of custom ItemCardList implementations with dedicated components (RecentIssues, RecentPullRequests, RecentReleases) improves code maintainability and readability. The conditional rendering based on user type is well-structured.


134-135: Appropriate use of variant prop for user releases.

Using the "grid" variant for displaying user releases provides consistent UI patterns while allowing for context-specific customization.

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

33-35: Good component imports for improved modularity.

Adding these dedicated imports aligns with the PR objectives to enhance code reusability.


270-273: Effective component replacement for recent items.

The replacement of custom ItemCardList implementations with the dedicated components (RecentIssues, RecentPullRequests, RecentReleases) simplifies the code and enhances maintainability. The use of appropriate variant props ensures consistent UI patterns while enabling context-specific customization.

frontend/__tests__/unit/pages/About.test.tsx (5)

5-5: Good addition of toaster import for testing.

This import is necessary for the new test cases that verify error notifications.


103-103: Good setup for toaster mock.

Adding the mock implementation for toaster.create in the beforeEach setup ensures it's properly initialized for each test.


122-140: Well-structured test for loading state.

This test effectively verifies that the loading spinner appears when data is in a loading state. The test uses appropriate assertions and waitFor to handle asynchronous behavior.


142-160: Good error display test coverage.

This test properly verifies the component's behavior when project data is null, ensuring appropriate error messages are displayed.


162-181: Excellent GraphQL error handling test.

This test provides good coverage for the error notification flow, verifying that the toaster is called with the correct parameters when a GraphQL request fails.

frontend/src/components/RecentReleases.tsx (4)

1-8: The imports and component structure look good

The component is well-organized with appropriate imports, clear type definitions, and good separation of rendering logic based on the variant prop.


20-21: Good use of default prop values

Setting default values for optional props is a good practice. This makes the component more flexible and easier to use without having to specify every prop.


47-49: Good security practices for external links

Using target="_blank" with rel="noopener noreferrer" for external links is a good security practice to prevent potential vulnerabilities.


73-88: Good component composition with ItemCardList

Using ItemCardList for the list variant is a great example of component composition. This promotes code reuse and consistency across the application.

frontend/src/components/RecentPullRequests.tsx (3)

23-27: Good use of default prop values

Setting default values for optional props makes the component more flexible and easier to use without having to specify every prop.


1-14: Well-organized imports and dependencies

The imports are well-organized, with a good separation between external libraries, internal types, and utilities.


49-49: Good use of the pluralize utility

Using the pluralize utility for proper grammar is a nice detail that improves the user experience.

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.

Great refactoring, please look into my comments regarding making it unified when you get a chance:

const RecentReleases: React.FC<RecentReleasesProps> = ({
data,
showAvatar = true,
variant = 'list',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not really sure if we need variants here. The idea is in having a unified look among all pages. It should always be a 'grid' like we currently have on the main page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are using two variants: a grid variant on the main page and the user details page, and a list variant on the project details page.
Please let me know which way I should proceed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please see my previous comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, we're showing grid only and other ui components are being rendered as before.

import { pluralize } from 'utils/pluralize'
import ItemCardList from './ItemCardList'

type PullRequestVariant = 'author' | 'comments'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also needs to be unified -- use comments everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the main page, we are using the author's name, while everywhere else, we are using comments as on user details page.
Please let me know if changes required.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use comments everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are not having comments count data for pull requests, so I used author data to show as before and also introduced a new prop which will control the author name rendering, ensures that the components look similar as before.

@codic-yeeshu codic-yeeshu requested a review from arkid15r April 1, 2025 18:52
@codic-yeeshu codic-yeeshu force-pushed the enhancement/added-separate-components branch from f5d3bb7 to 4c2bab0 Compare April 2, 2025 20:31
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 (2)
frontend/src/components/RecentReleases.tsx (1)

20-67: Grid layout implementation looks good but can be improved

The component implementation correctly handles displaying releases with conditional rendering for avatars and layout variations based on the showSingleColumn prop as requested in previous reviews.

However, the grid layout class string could be simplified for better readability.

-        <div
-          className={`grid ${showSingleColumn ? 'grid-cols-1' : 'grid gap-4 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3'}`}
-        >
+        <div
+          className={`grid gap-4 ${
+            showSingleColumn ? 'grid-cols-1' : 'sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3'
+          }`}
+        >
frontend/src/components/RecentPullRequests.tsx (1)

15-44: Implementation follows review guidance

The component correctly implements the showAuthor prop as false by default, with appropriate conditional rendering as discussed in previous reviews. This ensures consistency with the comments-based approach requested.

However, unlike the RecentReleases component, this one still uses ItemCardList as a base. This creates an inconsistency in the implementation approach between the recent item components.

Consider standardizing the implementation approach across all "Recent" components. Either:

  1. Make RecentReleases use ItemCardList like this component does
  2. Refactor this component to use SecondaryCard directly like RecentReleases does

This would improve consistency and make future maintenance easier.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f5d3bb7 and 4c2bab0.

📒 Files selected for processing (6)
  • frontend/__tests__/unit/pages/About.test.tsx (3 hunks)
  • frontend/src/components/CardDetailsPage.tsx (2 hunks)
  • frontend/src/components/RecentIssues.tsx (1 hunks)
  • frontend/src/components/RecentPullRequests.tsx (1 hunks)
  • frontend/src/components/RecentReleases.tsx (1 hunks)
  • frontend/src/pages/Home.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/src/components/RecentIssues.tsx
  • frontend/src/pages/Home.tsx
🔇 Additional comments (11)
frontend/src/components/CardDetailsPage.tsx (2)

7-9: Good addition of dedicated components

These new component imports replace the previous ItemCardList usage, improving code organization and reusability across different parts of the application.


125-137: Implementation looks good

The refactoring from generic ItemCardList to dedicated components improves readability and maintainability. The conditional rendering based on user type is preserved while leveraging the new components' specific capabilities.

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

8-12: Well-structured props interface

The interface properly defines the component's contract with optional properties for flexibility, which is good practice.


27-61: Ensure consistent styling with other components

The card styling here should be consistent with the styling used in RecentIssues and RecentPullRequests components to maintain UI consistency across the application.

Please verify that the card styling (background colors, padding, margins) matches what's used in the other recent item components.

frontend/__tests__/unit/pages/About.test.tsx (5)

5-5: Appropriate import for toaster testing

Good addition of the toaster import for testing error notifications.


103-103: Good test setup for toaster

Properly mocking the toaster.create function for testing.


122-140: Good loading state test coverage

This test appropriately verifies that the loading indicator is displayed when data is in loading state, which improves overall test coverage.


142-160: Good error handling test coverage

This test properly verifies that error messages are displayed when project data is null, enhancing reliability of the error handling code paths.


162-181: Good toaster error notification test

This test ensures the toaster error notification is triggered when GraphQL requests fail, providing coverage for error notification mechanisms.

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

9-13: Well-defined props interface

The interface correctly accepts both ItemCardPullRequests and PullRequestsType arrays, making the component reusable across different contexts.


33-40: Good conditional rendering of author information

The conditional check for author name or login is properly implemented, with appropriate fallbacks.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 3, 2025

@arkid15r arkid15r added this pull request to the merge queue Apr 3, 2025
Merged via the queue into OWASP:main with commit 2a60606 Apr 3, 2025
22 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 5, 2025
4 tasks
shdwcodr pushed a commit to shdwcodr/Nest that referenced this pull request Jun 5, 2025
Co-authored-by: Kate Golovanova <kate@kgthreads.com>
Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Oct 17, 2025
2 tasks
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.

Introduce reusable components for recent entieies

3 participants