Skip to content

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 8 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export function useInfiniteTestResults() {

return {
data: memoizedData,
totalCount: data?.pages?.[0]?.[0]?.totalCount ?? 0,
// TODO: only provide the values that we're interested in
...rest,
};
Expand Down
87 changes: 87 additions & 0 deletions static/app/views/codecov/tests/testSearchBar/testSearchBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {useEffect, 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) => {
setSearchParams(prev => {
const currentParams = Object.fromEntries(prev.entries());

if (newValue) {
currentParams.term = newValue;
} else {
delete currentParams.term;
}

return currentParams;
});
}, 500),
[setSearchParams]
);

useEffect(() => {
// Create a use effect to cancel handleSearchChange fn on unmount to avoid memory leaks
return () => {
handleSearchChange.cancel();
};
}, [handleSearchChange]);

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%;
`;
2 changes: 2 additions & 0 deletions static/app/views/codecov/tests/tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {ValidSort} from 'sentry/views/codecov/tests/testAnalyticsTable/test
import TestAnalyticsTable, {
isAValidSort,
} from 'sentry/views/codecov/tests/testAnalyticsTable/testAnalyticsTable';
import {TestSearchBar} from 'sentry/views/codecov/tests/testSearchBar/testSearchBar';

function EmptySelectorsMessage() {
return (
Expand Down Expand Up @@ -70,6 +71,7 @@ function Content() {
<Fragment>
{/* TODO: Conditionally show these if the branch we're in is the main branch */}
<Summaries />
<TestSearchBar testCount={response.totalCount} />
<TestAnalyticsTable response={response} sort={sorts[0]} />
</Fragment>
);
Expand Down
Loading