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 1 commit
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
78 changes: 78 additions & 0 deletions static/app/views/codecov/tests/testSearchBar/testSearchBar.tsx
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]
Copy link
Contributor

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 on searcchParams

);

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 @@ -15,6 +15,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';

export default function TestsPage() {
const location = useLocation();
Expand All @@ -34,6 +35,7 @@ export default function TestsPage() {
</PageFilterBar>
{/* 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]} />
</LayoutGap>
);
Expand Down
Loading