Skip to content

Commit 254eb77

Browse files
committed
feat: add test search bar w/ dynamic title to TA page
1 parent 282f05a commit 254eb77

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-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
@@ -149,6 +149,7 @@ export function useInfiniteTestResults() {
149149

150150
return {
151151
data: memoizedData,
152+
totalCount: data?.pages?.[0]?.[0]?.totalCount ?? 0,
152153
// TODO: only provide the values that we're interested in
153154
...rest,
154155
};
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import {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+
const currentParams = Object.fromEntries(searchParams.entries());
37+
38+
if (newValue) {
39+
currentParams.term = newValue;
40+
} else {
41+
delete currentParams.term;
42+
}
43+
44+
setSearchParams(currentParams);
45+
}, 500),
46+
[setSearchParams, searchParams]
47+
);
48+
49+
return (
50+
<Container>
51+
<Title>{searchTitle}</Title>
52+
<StyledSearchBar
53+
placeholder={t('Search by test name')}
54+
onChange={handleSearchChange}
55+
query={term}
56+
/>
57+
</Container>
58+
);
59+
}
60+
61+
const StyledSearchBar = styled(BaseSearchBar)`
62+
flex: 1 1 auto;
63+
min-width: 0;
64+
`;
65+
66+
const Title = styled('h2')`
67+
white-space: nowrap;
68+
flex-shrink: 0;
69+
margin: 0;
70+
font-size: ${p => p.theme.fontSize.xl};
71+
`;
72+
73+
const Container = styled('div')`
74+
display: flex;
75+
align-items: center;
76+
gap: ${space(1.5)};
77+
width: 100%;
78+
`;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {ValidSort} from 'sentry/views/codecov/tests/testAnalyticsTable/test
1515
import TestAnalyticsTable, {
1616
isAValidSort,
1717
} from 'sentry/views/codecov/tests/testAnalyticsTable/testAnalyticsTable';
18+
import {TestSearchBar} from 'sentry/views/codecov/tests/testSearchBar/testSearchBar';
1819

1920
export default function TestsPage() {
2021
const location = useLocation();
@@ -34,6 +35,7 @@ export default function TestsPage() {
3435
</PageFilterBar>
3536
{/* TODO: Conditionally show these if the branch we're in is the main branch */}
3637
<Summaries />
38+
<TestSearchBar testCount={response.totalCount} />
3739
<TestAnalyticsTable response={response} sort={sorts[0]} />
3840
</LayoutGap>
3941
);

0 commit comments

Comments
 (0)