Skip to content

feat(searchbar): Add tooltip descriptions to filter keys #92449

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 5 commits into from
Jun 2, 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 @@ -17,6 +17,7 @@ const FILTER_KEYS: TagCollection = {
jest.mock('sentry/components/searchQueryBuilder/context', () => ({
useSearchQueryBuilder: () => ({
size: 'normal',
getFieldDefinition: () => null,
}),
}));

Expand Down
10 changes: 10 additions & 0 deletions static/app/components/searchQueryBuilder/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,16 @@ describe('SearchQueryBuilder', function () {
await screen.findByRole('row', {name: 'is:unresolved'})
).toBeInTheDocument();
});

it('shows tooltip with field description when hovering over operator label', async function () {
render(<SearchQueryBuilder {...defaultProps} initialQuery="assigned:me" />);

await userEvent.hover(screen.getByText('assigned'));

expect(
await screen.findByText('Assignee of the issue as a user ID')
).toBeInTheDocument();
});
});

describe('has', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {mergeProps} from '@react-aria/utils';
import type {ListState} from '@react-stately/list';
import type {Node} from '@react-types/shared';

import {Tooltip} from 'sentry/components/core/tooltip';
import InteractionStateLayer from 'sentry/components/interactionStateLayer';
import {useSearchQueryBuilder} from 'sentry/components/searchQueryBuilder/context';
import {FilterKeyCombobox} from 'sentry/components/searchQueryBuilder/tokens/filter/filterKeyCombobox';
Expand All @@ -29,7 +30,8 @@ type FilterKeyProps = {

export function FilterKey({item, state, token, onActiveChange}: FilterKeyProps) {
const ref = useRef<HTMLDivElement>(null);
const {disabled} = useSearchQueryBuilder();
const {disabled, getFieldDefinition} = useSearchQueryBuilder();
const fieldDefinition = getFieldDefinition(token.key.text);

const [isEditing, setIsEditing] = useState(false);

Expand Down Expand Up @@ -59,19 +61,22 @@ export function FilterKey({item, state, token, onActiveChange}: FilterKeyProps)
}

return (
<KeyButton
aria-label={t('Edit key for filter: %s', getKeyName(token.key))}
onClick={() => {
setIsEditing(true);
onActiveChange(true);
}}
disabled={disabled}
{...filterButtonProps}
>
<InteractionStateLayer />
{/* Filter keys have no expected format, so we attempt to split by whitespace, dash, colon, and underscores. */}
{middleEllipsis(getKeyLabel(token.key), 40, /[\s-_:]/)}
</KeyButton>
<Tooltip title={fieldDefinition?.desc} skipWrapper>
<KeyButton
aria-label={t('Edit key for filter: %s', getKeyName(token.key))}
onClick={() => {
setIsEditing(true);
onActiveChange(true);
}}
disabled={disabled}
title="hello"
{...filterButtonProps}
>
<InteractionStateLayer />
{/* Filter keys have no expected format, so we attempt to split by whitespace, dash, colon, and underscores. */}
{middleEllipsis(getKeyLabel(token.key), 40, /[\s-_:]/)}
</KeyButton>
</Tooltip>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {ListState} from '@react-stately/list';
import type {Node} from '@react-types/shared';

import {CompactSelect, type SelectOption} from 'sentry/components/core/compactSelect';
import {Tooltip} from 'sentry/components/core/tooltip';
import InteractionStateLayer from 'sentry/components/interactionStateLayer';
import {useSearchQueryBuilder} from 'sentry/components/searchQueryBuilder/context';
import {UnstyledButton} from 'sentry/components/searchQueryBuilder/tokens/filter/unstyledButton';
Expand Down Expand Up @@ -85,22 +86,29 @@ function getTermOperatorFromToken(token: TokenResult<Token.FILTER>) {
}

function FilterKeyOperatorLabel({
keyValue,
keyLabel,
opLabel,
includeKeyLabel,
}: {
keyLabel: string;
keyValue: string;
includeKeyLabel?: boolean;
keyLabel?: string;
opLabel?: string;
}) {
const {getFieldDefinition} = useSearchQueryBuilder();
const fieldDefinition = getFieldDefinition(keyValue);

if (!includeKeyLabel) {
return <OpLabel>{opLabel}</OpLabel>;
}

return (
<KeyOpLabelWrapper>
<span>{keyLabel}</span>
{opLabel ? <OpLabel> {opLabel}</OpLabel> : null}
<Tooltip title={fieldDefinition?.desc}>
<span>{keyLabel}</span>
{opLabel ? <OpLabel> {opLabel}</OpLabel> : null}
</Tooltip>
</KeyOpLabelWrapper>
);
}
Expand Down Expand Up @@ -138,6 +146,7 @@ export function getOperatorInfo(token: TokenResult<Token.FILTER>): {
operator,
label: (
<FilterKeyOperatorLabel
keyValue={token.key.value}
keyLabel={token.key.text}
opLabel={operator === TermOperator.NOT_EQUAL ? 'not' : undefined}
includeKeyLabel
Expand All @@ -146,14 +155,21 @@ export function getOperatorInfo(token: TokenResult<Token.FILTER>): {
options: [
{
value: TermOperator.DEFAULT,
label: <FilterKeyOperatorLabel keyLabel={token.key.text} includeKeyLabel />,
label: (
<FilterKeyOperatorLabel
keyLabel={token.key.text}
keyValue={token.key.value}
includeKeyLabel
/>
),
textValue: 'is',
},
{
value: TermOperator.NOT_EQUAL,
label: (
<FilterKeyOperatorLabel
keyLabel={token.key.text}
keyValue={token.key.value}
opLabel="not"
includeKeyLabel
/>
Expand All @@ -170,18 +186,31 @@ export function getOperatorInfo(token: TokenResult<Token.FILTER>): {
label: (
<FilterKeyOperatorLabel
keyLabel={operator === TermOperator.NOT_EQUAL ? 'does not have' : 'has'}
keyValue={token.key.value}
includeKeyLabel
/>
),
options: [
{
value: TermOperator.DEFAULT,
label: <FilterKeyOperatorLabel keyLabel="has" includeKeyLabel />,
label: (
<FilterKeyOperatorLabel
keyLabel="has"
keyValue={token.key.value}
includeKeyLabel
/>
),
textValue: 'has',
},
{
value: TermOperator.NOT_EQUAL,
label: <FilterKeyOperatorLabel keyLabel="does not have" includeKeyLabel />,
label: (
<FilterKeyOperatorLabel
keyLabel="does not have"
keyValue={token.key.value}
includeKeyLabel
/>
),
textValue: 'does not have',
},
],
Expand Down
23 changes: 9 additions & 14 deletions static/app/utils/fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2582,33 +2582,28 @@ export const getFieldDefinition = (
switch (type) {
case 'replay':
if (REPLAY_FIELD_DEFINITIONS.hasOwnProperty(key)) {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
return REPLAY_FIELD_DEFINITIONS[key];
return REPLAY_FIELD_DEFINITIONS[key as keyof typeof REPLAY_FIELD_DEFINITIONS];
}
if (REPLAY_CLICK_FIELD_DEFINITIONS.hasOwnProperty(key)) {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
return REPLAY_CLICK_FIELD_DEFINITIONS[key];
return REPLAY_CLICK_FIELD_DEFINITIONS[
key as keyof typeof REPLAY_CLICK_FIELD_DEFINITIONS
];
}
if (REPLAY_FIELDS.includes(key as FieldKey)) {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
return EVENT_FIELD_DEFINITIONS[key];
return EVENT_FIELD_DEFINITIONS[key as FieldKey];
}
return null;
case 'feedback':
if (FEEDBACK_FIELD_DEFINITIONS.hasOwnProperty(key)) {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
return FEEDBACK_FIELD_DEFINITIONS[key];
return FEEDBACK_FIELD_DEFINITIONS[key as keyof typeof FEEDBACK_FIELD_DEFINITIONS];
}
if (FEEDBACK_FIELDS.includes(key as FieldKey)) {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
return EVENT_FIELD_DEFINITIONS[key];
return EVENT_FIELD_DEFINITIONS[key as FieldKey];
}
return null;
case 'span':
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
if (SPAN_FIELD_DEFINITIONS[key]) {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
return SPAN_FIELD_DEFINITIONS[key];
if (SPAN_FIELD_DEFINITIONS[key as keyof typeof SPAN_FIELD_DEFINITIONS]) {
return SPAN_FIELD_DEFINITIONS[key as keyof typeof SPAN_FIELD_DEFINITIONS];
}

// In EAP we have numeric tags that can be passed as parameters to
Expand Down
Loading