Skip to content

Commit 471c006

Browse files
authored
feat(explore): Add attribute description throughout explore (#91829)
This adds the search bar style descriptions to various parts of explore - in the visualize attribute dropdown - in the group by drop down - in the samples table editor Close EXP-3
1 parent cff22ad commit 471c006

File tree

4 files changed

+116
-16
lines changed

4 files changed

+116
-16
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type {ReactNode} from 'react';
2+
import styled from '@emotion/styled';
3+
4+
import {t} from 'sentry/locale';
5+
import {space} from 'sentry/styles/space';
6+
import type {FieldKind} from 'sentry/utils/fields';
7+
import {getFieldDefinition} from 'sentry/utils/fields';
8+
9+
interface AttributeDetailsProps {
10+
column: string;
11+
kind: FieldKind;
12+
label: ReactNode;
13+
type: 'span';
14+
}
15+
16+
export function AttributeDetails({column, kind, label, type}: AttributeDetailsProps) {
17+
const definition = getFieldDefinition(column, type, kind);
18+
const description = definition?.desc ?? t('An attribute sent with one or more events');
19+
return (
20+
<Details>
21+
<DetailsLabel>{label}</DetailsLabel>
22+
<DetailsDescription>{description}</DetailsDescription>
23+
</Details>
24+
);
25+
}
26+
27+
const Details = styled('div')`
28+
padding: ${space(0.75)} ${space(1)};
29+
max-width: 220px;
30+
font-size: ${p => p.theme.fontSizeSmall};
31+
`;
32+
33+
const DetailsLabel = styled('p')`
34+
font-weight: ${p => p.theme.fontWeightBold};
35+
word-break: break-all;
36+
margin-bottom: ${space(1)};
37+
`;
38+
39+
const DetailsDescription = styled('p')`
40+
margin-bottom: 0px;
41+
`;

static/app/views/explore/hooks/useVisualizeFields.tsx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import {useMemo} from 'react';
22

33
import type {SelectOption} from 'sentry/components/core/compactSelect';
44
import {defined} from 'sentry/utils';
5-
import {
6-
type ParsedFunction,
7-
parseFunction,
8-
prettifyTagKey,
9-
} from 'sentry/utils/discover/fields';
10-
import {AggregationKey} from 'sentry/utils/fields';
5+
import type {ParsedFunction} from 'sentry/utils/discover/fields';
6+
import {parseFunction, prettifyTagKey} from 'sentry/utils/discover/fields';
7+
import {AggregationKey, FieldKind} from 'sentry/utils/fields';
8+
import {AttributeDetails} from 'sentry/views/explore/components/attributeDetails';
9+
import {TypeBadge} from 'sentry/views/explore/components/typeBadge';
1110
import {useSpanTags} from 'sentry/views/explore/contexts/spanTagsContext';
1211

1312
interface Props {
@@ -37,6 +36,11 @@ export function useVisualizeFields({yAxis, yAxes}: Props) {
3736
}, [yAxes]);
3837

3938
const fieldOptions: Array<SelectOption<string>> = useMemo(() => {
39+
const kind =
40+
parsedYAxis?.name === AggregationKey.COUNT_UNIQUE
41+
? FieldKind.TAG
42+
: FieldKind.MEASUREMENT;
43+
4044
const unknownOptions = parsedYAxes
4145
.flatMap(entry => {
4246
return entry.arguments;
@@ -46,13 +50,30 @@ export function useVisualizeFields({yAxis, yAxes}: Props) {
4650
});
4751

4852
const options = [
49-
...unknownOptions.map(option => ({
50-
label: prettifyTagKey(option),
51-
value: option,
52-
textValue: option,
53-
})),
53+
...unknownOptions.map(option => {
54+
const label = prettifyTagKey(option);
55+
return {
56+
label,
57+
value: option,
58+
textValue: option,
59+
trailingItems: <TypeBadge kind={kind} />,
60+
showDetailsInOverlay: true,
61+
details: (
62+
<AttributeDetails column={option} kind={kind} label={label} type="span" />
63+
),
64+
};
65+
}),
5466
...Object.values(tags).map(tag => {
55-
return {label: tag.name, value: tag.key, textValue: tag.name};
67+
return {
68+
label: tag.name,
69+
value: tag.key,
70+
textValue: tag.name,
71+
trailingItems: <TypeBadge kind={kind} />,
72+
showDetailsInOverlay: true,
73+
details: (
74+
<AttributeDetails column={tag.key} kind={kind} label={tag.name} type="span" />
75+
),
76+
};
5677
}),
5778
];
5879

@@ -69,7 +90,7 @@ export function useVisualizeFields({yAxis, yAxes}: Props) {
6990
});
7091

7192
return options;
72-
}, [tags, parsedYAxes]);
93+
}, [tags, parsedYAxes, parsedYAxis?.name]);
7394

7495
return fieldOptions;
7596
}

static/app/views/explore/tables/columnEditorModal.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {TagCollection} from 'sentry/types/group';
1919
import {defined} from 'sentry/utils';
2020
import {classifyTagKey, prettifyTagKey} from 'sentry/utils/discover/fields';
2121
import {FieldKind} from 'sentry/utils/fields';
22+
import {AttributeDetails} from 'sentry/views/explore/components/attributeDetails';
2223
import {TypeBadge} from 'sentry/views/explore/components/typeBadge';
2324
import {DragNDropContext} from 'sentry/views/explore/contexts/dragNDropContext';
2425
import type {Column} from 'sentry/views/explore/hooks/useDragNDropColumns';
@@ -54,12 +55,18 @@ export function ColumnEditorModal({
5455
!stringTags.hasOwnProperty(column) && !numberTags.hasOwnProperty(column)
5556
)
5657
.map(column => {
58+
const kind = classifyTagKey(column);
59+
const label = prettifyTagKey(column);
5760
return {
58-
label: prettifyTagKey(column),
61+
label,
5962
value: column,
6063
textValue: column,
61-
trailingItems: <TypeBadge kind={classifyTagKey(column)} />,
64+
trailingItems: <TypeBadge kind={kind} />,
6265
key: `${column}-${classifyTagKey(column)}`,
66+
showDetailsInOverlay: true,
67+
details: (
68+
<AttributeDetails column={column} kind={kind} label={label} type="span" />
69+
),
6370
};
6471
}),
6572
...Object.values(stringTags).map(tag => {
@@ -69,6 +76,15 @@ export function ColumnEditorModal({
6976
textValue: tag.name,
7077
trailingItems: <TypeBadge kind={FieldKind.TAG} />,
7178
key: `${tag.key}-${FieldKind.TAG}`,
79+
showDetailsInOverlay: true,
80+
details: (
81+
<AttributeDetails
82+
column={tag.key}
83+
kind={FieldKind.TAG}
84+
label={tag.name}
85+
type="span"
86+
/>
87+
),
7288
};
7389
}),
7490
...Object.values(numberTags).map(tag => {
@@ -78,6 +94,15 @@ export function ColumnEditorModal({
7894
textValue: tag.name,
7995
trailingItems: <TypeBadge kind={FieldKind.MEASUREMENT} />,
8096
key: `${tag.key}-${FieldKind.MEASUREMENT}`,
97+
showDetailsInOverlay: true,
98+
details: (
99+
<AttributeDetails
100+
column={tag.key}
101+
kind={FieldKind.TAG}
102+
label={tag.name}
103+
type="span"
104+
/>
105+
),
81106
};
82107
}),
83108
];

static/app/views/explore/toolbar/toolbarGroupBy.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import {IconDelete} from 'sentry/icons/iconDelete';
1212
import {IconGrabbable} from 'sentry/icons/iconGrabbable';
1313
import {t} from 'sentry/locale';
1414
import {defined} from 'sentry/utils';
15+
import {classifyTagKey} from 'sentry/utils/discover/fields';
16+
import {AttributeDetails} from 'sentry/views/explore/components/attributeDetails';
17+
import {TypeBadge} from 'sentry/views/explore/components/typeBadge';
1518
import {DragNDropContext} from 'sentry/views/explore/contexts/dragNDropContext';
1619
import {
1720
useExploreGroupBys,
@@ -73,7 +76,17 @@ export function ToolbarGroupBy({autoSwitchToAggregates}: ToolbarGroupBy) {
7376
value: UNGROUPED,
7477
textValue: t('\u2014'),
7578
},
76-
...potentialOptions.map(key => ({label: key, value: key, textValue: key})),
79+
...potentialOptions.map(key => {
80+
const kind = classifyTagKey(key);
81+
return {
82+
label: key,
83+
value: key,
84+
textValue: key,
85+
trailingItems: <TypeBadge kind={kind} />,
86+
showDetailsInOverlay: true,
87+
details: <AttributeDetails column={key} kind={kind} label={key} type="span" />,
88+
};
89+
}),
7790
];
7891
}, [groupBys, tags]);
7992

0 commit comments

Comments
 (0)