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 2 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 @@ -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 @@ -89,17 +90,22 @@ function FilterKeyOperatorLabel({
opLabel,
includeKeyLabel,
}: {
keyLabel: string;
includeKeyLabel?: boolean;
keyLabel?: string;
opLabel?: string;
}) {
const {getFieldDefinition} = useSearchQueryBuilder();
const fieldDefinition = getFieldDefinition(keyLabel);

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

return (
<KeyOpLabelWrapper>
<span>{keyLabel}</span>
<Tooltip title={fieldDefinition?.desc} skipWrapper>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to wrap this tooltip around the whole thing? For is not it looks like it only gets wrapped around is. Kind of an edge case though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

<span>{keyLabel}</span>
</Tooltip>
{opLabel ? <OpLabel> {opLabel}</OpLabel> : null}
</KeyOpLabelWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from '@emotion/styled';

import {getEscapedKey} from 'sentry/components/core/compactSelect/utils';
import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/context';
import {FormattedQuery} from 'sentry/components/searchQueryBuilder/formattedQuery';
import {KeyDescription} from 'sentry/components/searchQueryBuilder/tokens/filterKeyListBox/keyDescription';
import type {
Expand Down Expand Up @@ -169,11 +170,19 @@ export function createRecentQueryItem({
textValue: search.query,
type: 'recent-query' as const,
label: (
<FormattedQuery
query={search.query}
<SearchQueryBuilderProvider
filterKeys={filterKeys}
fieldDefinitionGetter={getFieldDefinition}
/>
getTagValues={() => Promise.resolve([])}
initialQuery={search.query}
searchSource="formatted_query"
>
<FormattedQuery
query={search.query}
filterKeys={filterKeys}
fieldDefinitionGetter={getFieldDefinition}
/>
</SearchQueryBuilderProvider>
),
hideCheck: true,
};
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 (key in REPLAY_FIELD_DEFINITIONS) {
// @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 (key in REPLAY_CLICK_FIELD_DEFINITIONS) {
// @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 (key in FEEDBACK_FIELD_DEFINITIONS) {
// @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