-
-
Notifications
You must be signed in to change notification settings - Fork 127
Improve chapters/project leaders presentation #1729
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
Improve chapters/project leaders presentation #1729
Conversation
|
Summary by CodeRabbit
WalkthroughA reusable Changes
Assessment against linked issues
Suggested labels
Suggested reviewers
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (9)
backend/apps/owasp/graphql/nodes/common.py
(1 hunks)frontend/src/app/about/page.tsx
(2 hunks)frontend/src/app/projects/[projectKey]/page.tsx
(1 hunks)frontend/src/components/CardDetailsPage.tsx
(4 hunks)frontend/src/components/LeadersListBlock.tsx
(1 hunks)frontend/src/server/queries/projectQueries.ts
(1 hunks)frontend/src/types/card.ts
(2 hunks)frontend/src/types/leaders.ts
(1 hunks)frontend/src/types/project.ts
(2 hunks)
🧰 Additional context used
🧠 Learnings (3)
frontend/src/app/projects/[projectKey]/page.tsx (1)
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a length check before rendering HealthMetrics: `healthMetricsData.length > 0`. This ensures that when HealthMetrics is rendered, the data array has at least one element, making accessing data[0] safe within the HealthMetrics component.
frontend/src/types/card.ts (1)
Learnt from: ahmedxgouda
PR: OWASP/Nest#1714
File: frontend/src/components/ProjectTypeDashboardCard.tsx:8-12
Timestamp: 2025-07-08T17:07:50.957Z
Learning: In the OWASP/Nest project, union types for component props are not necessary when they would require creating separate type definitions. The project prefers inline prop type definitions even for props with specific string values, maintaining consistency with the single-use component prop pattern.
frontend/src/components/CardDetailsPage.tsx (2)
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a length check before rendering HealthMetrics: `healthMetricsData.length > 0`. This ensures that when HealthMetrics is rendered, the data array has at least one element, making accessing data[0] safe within the HealthMetrics component.
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a safety check that ensures HealthMetrics component is only rendered when healthMetricsData exists and has at least one element: `healthMetricsData && healthMetricsData.length > 0`. This makes accessing data[0] safe within the HealthMetrics component.
🧬 Code Graph Analysis (4)
frontend/src/types/card.ts (1)
frontend/src/types/user.ts (1)
User
(10-30)
frontend/src/types/project.ts (1)
frontend/src/types/user.ts (1)
User
(10-30)
backend/apps/owasp/graphql/nodes/common.py (1)
backend/apps/github/graphql/queries/user.py (1)
user
(40-56)
frontend/src/components/CardDetailsPage.tsx (3)
backend/apps/owasp/graphql/nodes/common.py (1)
leaders
(19-21)backend/apps/github/graphql/queries/user.py (1)
user
(40-56)frontend/src/types/leaders.ts (1)
LeadersListBlockProps
(5-7)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Run frontend e2e tests
🔇 Additional comments (12)
frontend/src/types/project.ts (2)
8-8
: LGTM! Import correctly added.The User type import is properly added to support the new
leadersTemp
field.
29-29
: LGTM! New field added correctly.The
leadersTemp
field is properly typed asUser[]
. As mentioned in the PR objectives, this temporary naming addresses the confusion with the existingleaders
field that corresponds to string arrays.frontend/src/app/projects/[projectKey]/page.tsx (1)
106-106
: No type mismatch—DetailsCard
handlesUser[]
correctly.The
DetailsCardProps
interface definesleaders?: User[]
, and insideCardDetailsPage.tsx
the component converts that array into the{[key: string]: string}
mapping forLeadersListBlock
via.reduce(...)
. Passingproject.leadersTemp
(aUser[]
) directly is therefore valid and needs no further transformation.frontend/src/types/card.ts (2)
14-14
: LGTM! Import correctly added.The User type import is properly added to support the new
leaders
prop inDetailsCardProps
.
57-57
: LGTM! Optional prop maintains backward compatibility.The
leaders?: User[]
prop is correctly typed and optional, ensuring backward compatibility with existing usage ofDetailsCardProps
.backend/apps/owasp/graphql/nodes/common.py (1)
6-6
: LGTM!The import addition is correct and necessary for the new method.
frontend/src/components/CardDetailsPage.tsx (3)
14-14
: LGTM!The imports are correctly added for the new functionality.
Also applies to: 23-23
54-54
: LGTM!The addition of the optional
leaders
prop to the component signature is correctly placed and typed.
203-211
: Data transformation validated—please document empty descriptionsThe
reduce
call infrontend/src/components/CardDetailsPage.tsx
(around lines 203–211) correctly builds aLeadersListBlockProps
({ [login: string]: string }
), mapping each leader’slogin
to''
. SinceLeadersListBlock
usesdescription={leaders[user.login]}
, the empty string is intentional given that certification data isn’t yet available.• File to update:
frontend/src/components/CardDetailsPage.tsx
(around thereduce
block)
• Suggested change:- Add a brief code comment or update the component’s documentation to note that descriptions are blank by design until certification details are introduced.
frontend/src/app/about/page.tsx (2)
26-26
: LGTM!The import for the new LeadersListBlock component is correctly added.
111-113
: LGTM!The integration of LeadersListBlock is clean and follows the established pattern. The conditional rendering, icon prop, and label are appropriately configured.
frontend/src/components/LeadersListBlock.tsx (1)
58-68
: LGTM!The main component structure and rendering logic look good. The responsive layout with flexbox and the mapping over leader keys is implemented correctly.
leadersTemp { | ||
login | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider fetching additional User fields for complete leader display.
Currently, only the login
field is being fetched from leadersTemp
. However, for a proper leader display component, you'll likely need additional fields such as:
avatarUrl
for profile picturesname
for display namescompany
andlocation
for professional informationbio
for user descriptions
leadersTemp {
login
+ avatarUrl
+ name
+ company
+ location
+ bio
+ url
}
📝 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.
leadersTemp { | |
login | |
} | |
leadersTemp { | |
login | |
avatarUrl | |
name | |
company | |
location | |
bio | |
url | |
} |
🤖 Prompt for AI Agents
In frontend/src/server/queries/projectQueries.ts around lines 13 to 15, the
GraphQL query for leadersTemp only fetches the login field, which is
insufficient for a complete leader display. Update the query to also fetch
avatarUrl, name, company, location, and bio fields from leadersTemp to provide
richer user information for the UI.
export type LeadersListBlockProps = { | ||
[key: string]: string | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
LGTM! Type definition follows requirements.
The LeadersListBlockProps
type correctly defines the string-to-string mapping format expected by the component, as mentioned in the PR objectives.
Consider adding a comment to clarify the structure:
+// Maps username to certification strings (e.g., { arkid15r: 'CCSP, CISSP, CSSLP' })
export type LeadersListBlockProps = {
[key: string]: string
}
📝 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.
export type LeadersListBlockProps = { | |
[key: string]: string | |
} | |
// Maps username to certification strings (e.g., { arkid15r: 'CCSP, CISSP, CSSLP' }) | |
export type LeadersListBlockProps = { | |
[key: string]: string | |
} |
🤖 Prompt for AI Agents
In frontend/src/types/leaders.ts around lines 5 to 7, add a brief comment above
the LeadersListBlockProps type definition to clarify that it represents a
mapping of string keys to string values, which helps improve code readability
and maintainability.
@strawberry.field | ||
def leaders_temp(self) -> list[UserNode]: | ||
"""Resolve leaders logins.""" | ||
return self.leaders.all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider improving method naming and documentation.
The implementation correctly exposes User objects via GraphQL, but consider the following improvements:
- The method name
leaders_temp
suggests this is temporary. Based on the PR objectives, consider planning for the eventual rename. - The docstring says "Resolve leaders logins" but it actually returns User objects, not just logins.
- def leaders_temp(self) -> list[UserNode]:
- """Resolve leaders logins."""
+ def leaders_temp(self) -> list[UserNode]:
+ """Resolve leaders as User objects."""
📝 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.
@strawberry.field | |
def leaders_temp(self) -> list[UserNode]: | |
"""Resolve leaders logins.""" | |
return self.leaders.all() | |
@strawberry.field | |
def leaders_temp(self) -> list[UserNode]: | |
"""Resolve leaders as User objects.""" | |
return self.leaders.all() |
🤖 Prompt for AI Agents
In backend/apps/owasp/graphql/nodes/common.py around lines 13 to 16, rename the
method from leaders_temp to a more descriptive and permanent name like leaders
to reflect its purpose accurately. Update the docstring to clearly state that
the method returns a list of User objects representing leaders, not just their
logins, ensuring the documentation matches the method's functionality.
const LeaderData = ({ username }: { username: string }) => { | ||
const { data, loading, error } = useQuery(GET_LEADER_DATA, { | ||
variables: { key: username }, | ||
}) | ||
const router = useRouter() | ||
|
||
if (loading) return <p>Loading {username}...</p> | ||
if (error) return <p>Error loading {username}'s data</p> | ||
|
||
const user = data?.user | ||
|
||
if (!user) { | ||
return <p>No data available for {username}</p> | ||
} | ||
|
||
const handleButtonClick = (user: User) => { | ||
router.push(`/members/${user.login}`) | ||
} | ||
|
||
return ( | ||
<UserCard | ||
avatar={user.avatarUrl} | ||
button={{ | ||
icon: <FontAwesomeIconWrapper icon="fa-solid fa-right-to-bracket" />, | ||
label: 'View Profile', | ||
onclick: () => handleButtonClick(user), | ||
}} | ||
className="h-64 w-40 bg-inherit" | ||
company={user.company} | ||
description={leaders[user.login]} | ||
location={user.location} | ||
name={user.name || username} | ||
/> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider potential performance implications and error handling improvements.
The nested LeaderData
component creates individual GraphQL queries for each leader, which could lead to N+1 query performance issues. Consider these improvements:
-
Performance: If multiple leaders are displayed, this creates multiple separate queries. Consider batching or using a single query with multiple variables.
-
Error handling: The error states are basic. Consider providing more user-friendly error messages or retry mechanisms.
-
Loading state: Individual loading states per leader might create a poor UX when multiple leaders are loading.
For better performance, consider fetching all leader data in a single query or using GraphQL batching:
// Alternative approach - single query for all leaders
const { data, loading, error } = useQuery(GET_MULTIPLE_LEADERS_DATA, {
variables: { usernames: Object.keys(leaders) },
})
🤖 Prompt for AI Agents
In frontend/src/components/LeadersListBlock.tsx around lines 22 to 56, the
LeaderData component runs a separate GraphQL query for each leader, causing
potential N+1 query performance issues and fragmented loading/error states.
Refactor to fetch all leader data in a single query by creating a new GraphQL
query that accepts multiple usernames as variables and returns their data
collectively. Replace the multiple individual queries with one useQuery call
that fetches all leaders at once, then map over the results to render each
leader's data. Additionally, improve error handling by providing more
user-friendly messages and consider adding retry logic. Consolidate loading
states to avoid multiple loading indicators and improve UX.
const handleButtonClick = (user: User) => { | ||
router.push(`/members/${user.login}`) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix type annotation for handleButtonClick parameter.
The parameter type should match the actual user object structure from the GraphQL response, not the Sentry User type.
- const handleButtonClick = (user: User) => {
+ const handleButtonClick = (user: any) => {
router.push(`/members/${user.login}`)
}
Or better yet, define a proper User type and use it consistently throughout the application.
📝 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.
const handleButtonClick = (user: User) => { | |
router.push(`/members/${user.login}`) | |
} | |
const handleButtonClick = (user: any) => { | |
router.push(`/members/${user.login}`) | |
} |
🤖 Prompt for AI Agents
In frontend/src/components/LeadersListBlock.tsx around lines 37 to 39, the
handleButtonClick function parameter is currently typed as Sentry's User type,
which does not match the actual user object structure from the GraphQL response.
To fix this, define a proper User type that reflects the GraphQL user data
structure and update the parameter type annotation of handleButtonClick to use
this new User type consistently throughout the application.
'use client' | ||
import { useQuery } from '@apollo/client' | ||
import { IconProp } from '@fortawesome/fontawesome-svg-core' | ||
import { User } from '@sentry/nextjs' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect import for User type.
The User
type should not be imported from @sentry/nextjs
. This is likely meant to be a local User type definition.
-import { User } from '@sentry/nextjs'
+import { User } from 'types/user'
If the User type doesn't exist in types/user
, you may need to create it or import from the correct location.
📝 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.
import { User } from '@sentry/nextjs' | |
-import { User } from '@sentry/nextjs' | |
+import { User } from 'types/user' |
🤖 Prompt for AI Agents
In frontend/src/components/LeadersListBlock.tsx at line 4, the User type is
incorrectly imported from '@sentry/nextjs'. Remove this import and instead
import the User type from the correct local path, such as 'types/user'. If the
User type does not exist there, create the appropriate type definition in that
location before importing it.
will resolve cr comments. |
Resolves #1431
Hello, I need help @arkid15r ,
here's what I did in this PR:
leaders_temp
fieldLeaders
Block in a componentquestions/blockers:
leaders_temp
as i could not come up with a different name. There's already aleaders
field exposed but it's misleading as its actuallyleaders_raw
in the database which is juststring[]
. I'm not sure what to name it. I think renaming the existingleaders
toleaders_raw
orleaders_names
would be a good approach.Leaders
block requires data in the following format:however, I'm not sure how to get the
CCSP, CISSP, CSSLP
part from the database.3. since
leaders_temp
is of typeUser[]
we need to convert it in the above format (typeLeadersListBlockProps
). in this implementation, I have just reduced it using code. But I'm not sure if this is a good approach, please let me know.Please let me know what you think, I will update the code and the related tests accordingly.