-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(Codecov): add test search bar with dynamic title to TA page #94893
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
254eb77
feat: add test search bar w/ dynamic title to TA page
adrianviquez c4e56f2
feat: get rid of unecessary useMemo hook
adrianviquez 8fe17d8
try fixing debouncing recreation every render
adrianviquez 251a6cc
replace usememo with usecallback
adrianviquez 5b38785
add useMemo to prevent fn recreation
adrianviquez 27f1c3e
fix: add useeffect to dlelete debounce ref on unmount
adrianviquez e45cf96
merge
adrianviquez 65e4c2b
replace ref implementation w/ useMemo instead
adrianviquez 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
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
78 changes: 78 additions & 0 deletions
78
static/app/views/codecov/tests/testSearchBar/testSearchBar.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,78 @@ | ||
import {useMemo} from 'react'; | ||
import {useSearchParams} from 'react-router-dom'; | ||
import styled from '@emotion/styled'; | ||
import debounce from 'lodash/debounce'; | ||
|
||
import BaseSearchBar from 'sentry/components/searchBar'; | ||
import {t} from 'sentry/locale'; | ||
import {space} from 'sentry/styles/space'; | ||
|
||
const FILTER_TO_NAME = { | ||
slowestTests: 'Slowest Tests', | ||
flakyTests: 'Flaky Tests', | ||
failedTests: 'Failed Tests', | ||
skippedTests: 'Skipped Tests', | ||
}; | ||
|
||
type TestSearchBarProps = { | ||
testCount: number; | ||
}; | ||
|
||
export function TestSearchBar({testCount}: TestSearchBarProps) { | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
const term = searchParams.get('term') || ''; | ||
|
||
const filterBy = searchParams.get('filterBy') || ''; | ||
const testTitle = | ||
filterBy in FILTER_TO_NAME | ||
? FILTER_TO_NAME[filterBy as keyof typeof FILTER_TO_NAME] | ||
: 'Tests'; | ||
const count = testCount > 999 ? `${(testCount / 1000).toFixed(1)}K` : testCount; | ||
const searchTitle = `${testTitle} (${count})`; | ||
|
||
const handleSearchChange = useMemo( | ||
() => | ||
debounce((newValue: string) => { | ||
const currentParams = Object.fromEntries(searchParams.entries()); | ||
|
||
if (newValue) { | ||
currentParams.term = newValue; | ||
} else { | ||
delete currentParams.term; | ||
} | ||
|
||
setSearchParams(currentParams); | ||
}, 500), | ||
[setSearchParams, searchParams] | ||
); | ||
|
||
return ( | ||
<Container> | ||
<Title>{searchTitle}</Title> | ||
<StyledSearchBar | ||
placeholder={t('Search by test name')} | ||
onChange={handleSearchChange} | ||
query={term} | ||
/> | ||
</Container> | ||
); | ||
} | ||
|
||
const StyledSearchBar = styled(BaseSearchBar)` | ||
flex: 1 1 auto; | ||
min-width: 0; | ||
`; | ||
|
||
const Title = styled('h2')` | ||
white-space: nowrap; | ||
flex-shrink: 0; | ||
margin: 0; | ||
font-size: ${p => p.theme.fontSize.xl}; | ||
`; | ||
|
||
const Container = styled('div')` | ||
display: flex; | ||
align-items: center; | ||
gap: ${space(1.5)}; | ||
width: 100%; | ||
`; |
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
Oops, something went wrong.
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.
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.
Having
searchParams
as a useMemo dependency will cause redefining handleSearchChange on every rerender since it is treated as a different object every time. I think we need a way to debounce this without relying onsearcchParams