-
-
Notifications
You must be signed in to change notification settings - Fork 633
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
Open
devnchill
wants to merge
7
commits into
OWASP:main
Choose a base branch
from
devnchill:feat/limit-release
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−17
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7613c1c
feat: toggle button to showAll/showLess releases
devnchill 21fc8ce
refactor: rename showAll to showAllReleases
devnchill 64c0e57
fix: set showAllRelease to false whenever shanpshots change
devnchill 2d36380
fix: incorrect tailwind class replaced uppercase k with lowercase k i…
devnchill 697c955
refactor: move MAX_RELEASES_TO_SHOW to util/constant.ts
devnchill 2361dd6
refactor: extract ReleaseSection as a component from snapshot page
devnchill 102607c
feat: add unit test for SnapshotReleaseComponent
devnchill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
frontend/__tests__/unit/components/SnapshotReleaseSection.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import '@testing-library/jest-dom' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { ReleasesSection } from 'components/SnapshotReleaseSection' | ||
| import { MAX_RELEASES_TO_SHOW } from 'utils/constants' | ||
|
|
||
| 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('button has label `show all` for releases > MAX_RELEASES_TO_SHOW', () => { | ||
| render(<ReleasesSection releases={mockReleases} showAll={false} onToggle={jest.fn()} />) | ||
| expect(screen.getByRole('button', { name: 'show all' })).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('button has label `show less` for releases > MAX_RELEASES_TO_SHOW', () => { | ||
| render(<ReleasesSection releases={mockReleases} showAll={true} onToggle={jest.fn()} />) | ||
| expect(screen.getByRole('button', { name: 'show less' })).toBeInTheDocument() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { MAX_RELEASES_TO_SHOW } from 'utils/constants' | ||
| import Release from 'components/Release' | ||
| import type { Release as ReleaseType } from 'types/release' | ||
|
|
||
| type ReleasesSectionProps = { | ||
| releases: ReleaseType[] | ||
| showAll: boolean | ||
| onToggle: () => void | ||
| } | ||
|
|
||
| export const ReleasesSection = ({ releases, showAll, onToggle }: ReleasesSectionProps) => { | ||
| const showButton = { | ||
| label: showAll ? 'show less' : 'show all', | ||
| classname: | ||
| 'dark:hover:text-white rounded-md border-1 font-light border-blue-400 p-2 text-blue-400 hover:bg-blue-500 hover:text-white', | ||
| } | ||
|
|
||
| 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} | ||
| showAvatar={true} | ||
| index={index} | ||
| /> | ||
| ) | ||
| })} | ||
| </div> | ||
| {releases.length > MAX_RELEASES_TO_SHOW && ( | ||
| <div className="flex w-full justify-center"> | ||
| <button className={showButton.classname} type="button" onClick={onToggle}> | ||
| {showButton.label} | ||
| </button> | ||
| </div> | ||
| )} | ||
| </> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.