-
-
Notifications
You must be signed in to change notification settings - Fork 629
Limit releases to only show most recent ones #4570
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
7613c1c
21fc8ce
64c0e57
2d36380
697c955
2361dd6
102607c
d4a485e
4f73c62
fb8e628
18aaa44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import '@testing-library/jest-dom' | ||
| import { fireEvent, render, screen } from '@testing-library/react' | ||
|
|
||
| import { MAX_RELEASES_TO_SHOW } from 'utils/constants' | ||
| import { ReleasesSection } from 'components/SnapshotReleaseSection' | ||
|
|
||
| describe('ReleasesSection', () => { | ||
| const mockReleases = Array.from({ length: MAX_RELEASES_TO_SHOW + 1 }, (_, i) => ({ | ||
| id: `release-${i}`, | ||
| name: `Release v${i}`, | ||
| publishedAt: new Date().toISOString(), | ||
| tagName: `v${i}`, | ||
| })) | ||
|
|
||
| it('renders only MAX_RELEASES_TO_SHOW items when showAll is false', () => { | ||
| render(<ReleasesSection releases={mockReleases} showAll={false} onToggle={jest.fn()} />) | ||
|
|
||
| const items = screen.getAllByText(/Release v/) | ||
| expect(items.length).toBe(MAX_RELEASES_TO_SHOW) | ||
| }) | ||
|
|
||
| it('renders all releases when showAll is true', () => { | ||
| render(<ReleasesSection releases={mockReleases} showAll={true} onToggle={jest.fn()} />) | ||
|
|
||
| const items = screen.getAllByText(/Release v/) | ||
| expect(items.length).toBe(MAX_RELEASES_TO_SHOW + 1) | ||
| }) | ||
|
|
||
| it('renders the show more button for releases > MAX_RELEASES_TO_SHOW', () => { | ||
| render(<ReleasesSection releases={mockReleases} showAll={false} onToggle={jest.fn()} />) | ||
| expect(screen.getByRole('button', { name: 'Show more' })).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('calls onToggle when the show more button is clicked', () => { | ||
| const onToggle = jest.fn() | ||
|
|
||
| render(<ReleasesSection releases={mockReleases} showAll={false} onToggle={onToggle} />) | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: 'Show more' })) | ||
| expect(onToggle).toHaveBeenCalledTimes(1) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { Release as ReleaseType } from 'types/release' | ||
| import { MAX_RELEASES_TO_SHOW } from 'utils/constants' | ||
| import Release from 'components/Release' | ||
| import ShowMoreButton from 'components/ShowMoreButton' | ||
|
|
||
| type ReleasesSectionProps = { | ||
| releases: ReleaseType[] | ||
| showAll: boolean | ||
| onToggle: () => void | ||
| } | ||
|
|
||
| export const ReleasesSection = ({ releases, showAll, onToggle }: ReleasesSectionProps) => { | ||
| const visibleReleases = showAll ? releases : releases.slice(0, MAX_RELEASES_TO_SHOW) | ||
| return ( | ||
| <> | ||
| <div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3"> | ||
| {visibleReleases.map((release, index) => { | ||
| return ( | ||
| <Release | ||
| key={ | ||
| release.id || `${release.tagName}-${release.repositoryName ?? 'unknown'}-${index}` | ||
| } | ||
| release={release as unknown as ReleaseType} | ||
|
Check warning on line 23 in frontend/src/components/SnapshotReleaseSection.tsx
|
||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| showAvatar={true} | ||
| index={index} | ||
| /> | ||
| ) | ||
| })} | ||
| </div> | ||
| {releases.length > MAX_RELEASES_TO_SHOW && <ShowMoreButton onToggle={onToggle} />} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify ShowMoreButton API and whether it receives expansion state.
fd -t f "ShowMoreButton.tsx" "ShowMoreButton.jsx" "ShowMoreButton/index.tsx" "ShowMoreButton/index.jsx"
rg -n -C3 "type .*ShowMoreButton|interface .*ShowMoreButton|function ShowMoreButton|const ShowMoreButton|aria-expanded|Show all|Show less|Show more|onToggle" --type ts --type tsx --type js --type jsx
# Verify call sites and passed props.
rg -n -C2 "<ShowMoreButton" --type tsx --type jsxRepository: OWASP/Nest Length of output: 358 🏁 Script executed: #!/bin/bash
# Find ShowMoreButton component file
fd "ShowMoreButton" --type f
# Check the ShowMoreButton implementation
fd "ShowMoreButton" --type f -x cat -n {} \;Repository: OWASP/Nest Length of output: 2367 🏁 Script executed: #!/bin/bash
# Find and examine SnapshotReleaseSection.tsx
fd "SnapshotReleaseSection" --type f -x cat -n {} \;Repository: OWASP/Nest Length of output: 3235 🏁 Script executed: #!/bin/bash
# Find where ReleasesSection is used/imported
rg "ReleasesSection" --type ts --type tsxRepository: OWASP/Nest Length of output: 82 🏁 Script executed: #!/bin/bash
# Find where ReleasesSection is used
rg "ReleasesSection" -g "*.ts" -g "*.tsx" -g "*.js" -g "*.jsx"Repository: OWASP/Nest Length of output: 1353 🏁 Script executed: #!/bin/bash
# Examine the page component where ReleasesSection is used
cat -n "frontend/src/app/community/snapshots/[id]/page.tsx"Repository: OWASP/Nest Length of output: 7942 ShowMoreButton needs to synchronize with parent
Consider either:
Add 🤖 Prompt for AI Agents |
||
| </> | ||
| ) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.