Skip to content

Commit eb30f53

Browse files
committed
add epm to explore
1 parent 930c103 commit eb30f53

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

static/app/utils/fields/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ export const ALLOWED_EXPLORE_VISUALIZE_FIELDS: SpanIndexedField[] = [
833833

834834
export const ALLOWED_EXPLORE_VISUALIZE_AGGREGATES: AggregationKey[] = [
835835
AggregationKey.COUNT, // DO NOT RE-ORDER: the first element is used as the default
836+
AggregationKey.EPM,
836837
AggregationKey.COUNT_UNIQUE,
837838
AggregationKey.AVG,
838839
AggregationKey.P50,
@@ -846,7 +847,7 @@ export const ALLOWED_EXPLORE_VISUALIZE_AGGREGATES: AggregationKey[] = [
846847
AggregationKey.MAX,
847848
];
848849

849-
const SPAN_AGGREGATION_FIELDS: Record<AggregationKey, FieldDefinition> = {
850+
export const SPAN_AGGREGATION_FIELDS: Record<AggregationKey, FieldDefinition> = {
850851
...AGGREGATION_FIELDS,
851852
[AggregationKey.COUNT]: {
852853
...AGGREGATION_FIELDS[AggregationKey.COUNT],

static/app/views/explore/contexts/pageParamsContext/visualizes.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
AggregationKey,
99
ALLOWED_EXPLORE_VISUALIZE_AGGREGATES,
1010
ALLOWED_EXPLORE_VISUALIZE_FIELDS,
11+
SPAN_AGGREGATION_FIELDS,
1112
} from 'sentry/utils/fields';
1213
import {decodeList} from 'sentry/utils/queryString';
1314
import {ChartType} from 'sentry/views/insights/common/components/chart';
@@ -150,6 +151,8 @@ export function updateVisualizeAggregate({
150151
oldAggregate: string;
151152
oldArgument: string;
152153
}): string {
154+
const functionDefinition = SPAN_AGGREGATION_FIELDS[newAggregate as AggregationKey];
155+
153156
// the default aggregate only has 1 allowed field
154157
if (newAggregate === DEFAULT_VISUALIZATION_AGGREGATE) {
155158
return DEFAULT_VISUALIZATION;
@@ -169,7 +172,17 @@ export function updateVisualizeAggregate({
169172
return `${newAggregate}(${DEFAULT_VISUALIZATION_FIELD})`;
170173
}
171174

172-
return `${newAggregate}(${oldArgument})`;
175+
let newArgument = oldArgument;
176+
if (functionDefinition) {
177+
const hasParameters =
178+
functionDefinition.parameters && functionDefinition.parameters.length > 0;
179+
if (!hasParameters) {
180+
newArgument = '';
181+
}
182+
// TODO: check if old parameter is valid for new function
183+
}
184+
185+
return `${newAggregate}(${newArgument})`;
173186
}
174187

175188
const FUNCTION_TO_CHART_TYPE: Record<string, ChartType> = {

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {IconAdd} from 'sentry/icons';
1212
import {IconDelete} from 'sentry/icons/iconDelete';
1313
import {t} from 'sentry/locale';
1414
import {parseFunction} from 'sentry/utils/discover/fields';
15-
import {ALLOWED_EXPLORE_VISUALIZE_AGGREGATES} from 'sentry/utils/fields';
15+
import type {AggregationKey} from 'sentry/utils/fields';
16+
import {
17+
ALLOWED_EXPLORE_VISUALIZE_AGGREGATES,
18+
SPAN_AGGREGATION_FIELDS,
19+
} from 'sentry/utils/fields';
1620
import {
1721
useExploreVisualizes,
1822
useSetExploreVisualizes,
@@ -165,7 +169,11 @@ function VisualizeDropdown({
165169
// We want to lock down the fields dropdown when using count so that we can
166170
// render `count(spans)` for better legibility. However, for backwards
167171
// compatibility, we don't want to lock down all `count` queries immediately.
168-
const lockOptions = yAxis === DEFAULT_VISUALIZATION;
172+
const functionDefinition =
173+
SPAN_AGGREGATION_FIELDS[parsedVisualize?.name as AggregationKey];
174+
const shouldHaveParameters =
175+
functionDefinition?.parameters && functionDefinition.parameters.length > 0;
176+
const lockOptions = yAxis === DEFAULT_VISUALIZATION || !shouldHaveParameters;
169177

170178
const countFieldOptions: Array<SelectOption<string>> = useMemo(
171179
() => [
@@ -183,7 +191,7 @@ function VisualizeDropdown({
183191
});
184192
const fieldOptions = lockOptions ? countFieldOptions : defaultFieldOptions;
185193

186-
const aggregateOptions: Array<SelectOption<string>> = useMemo(() => {
194+
const aggregateOptions: Array<SelectOption<AggregationKey>> = useMemo(() => {
187195
return ALLOWED_EXPLORE_VISUALIZE_AGGREGATES.map(aggregate => {
188196
return {
189197
label: aggregate,

0 commit comments

Comments
 (0)