Skip to content

Commit d9f2d7c

Browse files
authored
feat(Codecov): add test search bar with dynamic title to TA page (#94893)
This PR adds a search bar with dynamic title to the TA page. This component mainly changes the url to add the `term` key, but this PR doesn't clal the API directly as that part needs to be implemented. Notes - - Add `TestSearchBar` component and add it to the tests page - Expose `totalCount` from the test results endpoint
1 parent e1ebed3 commit d9f2d7c

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

static/app/views/codecov/tests/queries/useGetTestResults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export function useInfiniteTestResults() {
151151

152152
return {
153153
data: memoizedData,
154+
totalCount: data?.pages?.[0]?.[0]?.totalCount ?? 0,
154155
// TODO: only provide the values that we're interested in
155156
...rest,
156157
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import {useEffect, useMemo} from 'react';
2+
import {useSearchParams} from 'react-router-dom';
3+
import styled from '@emotion/styled';
4+
import debounce from 'lodash/debounce';
5+
6+
import BaseSearchBar from 'sentry/components/searchBar';
7+
import {t} from 'sentry/locale';
8+
import {space} from 'sentry/styles/space';
9+
10+
const FILTER_TO_NAME = {
11+
slowestTests: 'Slowest Tests',
12+
flakyTests: 'Flaky Tests',
13+
failedTests: 'Failed Tests',
14+
skippedTests: 'Skipped Tests',
15+
};
16+
17+
type TestSearchBarProps = {
18+
testCount: number;
19+
};
20+
21+
export function TestSearchBar({testCount}: TestSearchBarProps) {
22+
const [searchParams, setSearchParams] = useSearchParams();
23+
const term = searchParams.get('term') || '';
24+
25+
const filterBy = searchParams.get('filterBy') || '';
26+
const testTitle =
27+
filterBy in FILTER_TO_NAME
28+
? FILTER_TO_NAME[filterBy as keyof typeof FILTER_TO_NAME]
29+
: 'Tests';
30+
const count = testCount > 999 ? `${(testCount / 1000).toFixed(1)}K` : testCount;
31+
const searchTitle = `${testTitle} (${count})`;
32+
33+
const handleSearchChange = useMemo(
34+
() =>
35+
debounce((newValue: string) => {
36+
setSearchParams(prev => {
37+
const currentParams = Object.fromEntries(prev.entries());
38+
39+
if (newValue) {
40+
currentParams.term = newValue;
41+
} else {
42+
delete currentParams.term;
43+
}
44+
45+
return currentParams;
46+
});
47+
}, 500),
48+
[setSearchParams]
49+
);
50+
51+
useEffect(() => {
52+
// Create a use effect to cancel handleSearchChange fn on unmount to avoid memory leaks
53+
return () => {
54+
handleSearchChange.cancel();
55+
};
56+
}, [handleSearchChange]);
57+
58+
return (
59+
<Container>
60+
<Title>{searchTitle}</Title>
61+
<StyledSearchBar
62+
placeholder={t('Search by test name')}
63+
onChange={handleSearchChange}
64+
query={term}
65+
/>
66+
</Container>
67+
);
68+
}
69+
70+
const StyledSearchBar = styled(BaseSearchBar)`
71+
flex: 1 1 auto;
72+
min-width: 0;
73+
`;
74+
75+
const Title = styled('h2')`
76+
white-space: nowrap;
77+
flex-shrink: 0;
78+
margin: 0;
79+
font-size: ${p => p.theme.fontSize.xl};
80+
`;
81+
82+
const Container = styled('div')`
83+
display: flex;
84+
align-items: center;
85+
gap: ${space(1.5)};
86+
width: 100%;
87+
`;

static/app/views/codecov/tests/tests.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {ValidSort} from 'sentry/views/codecov/tests/testAnalyticsTable/test
2020
import TestAnalyticsTable, {
2121
isAValidSort,
2222
} from 'sentry/views/codecov/tests/testAnalyticsTable/testAnalyticsTable';
23+
import {TestSearchBar} from 'sentry/views/codecov/tests/testSearchBar/testSearchBar';
2324

2425
function EmptySelectorsMessage() {
2526
return (
@@ -70,6 +71,7 @@ function Content() {
7071
<Fragment>
7172
{/* TODO: Conditionally show these if the branch we're in is the main branch */}
7273
<Summaries />
74+
<TestSearchBar testCount={response.totalCount} />
7375
<TestAnalyticsTable response={response} sort={sorts[0]} />
7476
</Fragment>
7577
);

0 commit comments

Comments
 (0)