@@ -10,7 +10,7 @@ import {COL_WIDTH_UNDEFINED} from 'sentry/components/tables/gridEditable';
1010import { SimpleTable } from 'sentry/components/tables/simpleTable' ;
1111import { IconWarning } from 'sentry/icons/iconWarning' ;
1212import { t } from 'sentry/locale' ;
13- import { parseFunction } from 'sentry/utils/discover/fields' ;
13+ import { isEquation , parseFunction } from 'sentry/utils/discover/fields' ;
1414import { prettifyTagKey } from 'sentry/utils/fields' ;
1515import { useOrganization } from 'sentry/utils/useOrganization' ;
1616import type { TableColumn } from 'sentry/views/discover/table/types' ;
@@ -29,6 +29,7 @@ import {
2929} from 'sentry/views/explore/metrics/metricInfoTabs/metricInfoTabStyles' ;
3030import type { TraceMetric } from 'sentry/views/explore/metrics/metricQuery' ;
3131import { canUseMetricsUIRefresh } from 'sentry/views/explore/metrics/metricsFlags' ;
32+ import { useMetricVisualize } from 'sentry/views/explore/metrics/metricsQueryParams' ;
3233import { TraceMetricKnownFieldKey } from 'sentry/views/explore/metrics/types' ;
3334import {
3435 createTraceMetricFilter ,
@@ -39,6 +40,10 @@ import {
3940 useQueryParamsGroupBys ,
4041 useSetQueryParamsAggregateSortBys ,
4142} from 'sentry/views/explore/queryParams/context' ;
43+ import {
44+ isVisualizeEquation ,
45+ isVisualizeFunction ,
46+ } from 'sentry/views/explore/queryParams/visualize' ;
4247import { FieldRenderer } from 'sentry/views/explore/tables/fieldRenderer' ;
4348import { TraceItemDataset } from 'sentry/views/explore/types' ;
4449import { GenericWidgetEmptyStateWarning } from 'sentry/views/performance/landing/widgets/components/selectableList' ;
@@ -67,9 +72,12 @@ export function AggregatesTab({traceMetric, isMetricOptionsEmpty}: AggregatesTab
6772 const hasMetricsUIRefresh = canUseMetricsUIRefresh ( organization ) ;
6873 const topEvents = useTopEvents ( ) ;
6974 const tableRef = useRef < HTMLDivElement > ( null ) ;
75+ const visualize = useMetricVisualize ( ) ;
7076
7177 const { result, eventView, fields} = useMetricAggregatesTable ( {
72- enabled : Boolean ( traceMetric . name ) && ! isMetricOptionsEmpty ,
78+ enabled : isVisualizeFunction ( visualize )
79+ ? Boolean ( traceMetric . name ) && ! isMetricOptionsEmpty
80+ : isVisualizeEquation ( visualize ) && Boolean ( visualize . expression . text ) ,
7381 limit : RESULT_LIMIT ,
7482 traceMetric,
7583 } ) ;
@@ -107,21 +115,22 @@ export function AggregatesTab({traceMetric, isMetricOptionsEmpty}: AggregatesTab
107115
108116 // When no group bys are selected, prepend the metric name as a virtual group-by column
109117 const displayFields = useMemo ( ( ) => {
110- if ( groupBys . length === 0 ) {
118+ if ( groupBys . length === 0 && isVisualizeFunction ( visualize ) ) {
111119 return [ TraceMetricKnownFieldKey . METRIC_NAME , ...fields ] ;
112120 }
113121 return fields ;
114- } , [ groupBys . length , fields ] ) ;
122+ } , [ groupBys . length , fields , visualize ] ) ;
115123
116124 const displayColumns = useMemo ( ( ) => {
117- if ( groupBys . length === 0 ) {
125+ if ( groupBys . length === 0 && isVisualizeFunction ( visualize ) ) {
118126 return [ METRIC_NAME_COLUMN , ...columns ] ;
119127 }
120128 return columns ;
121- } , [ groupBys . length , columns ] ) ;
129+ } , [ groupBys . length , columns , visualize ] ) ;
122130
123131 // Include the virtual metric name column in the group-by count so grid/divider logic works
124- const groupByFieldCount = groupBys . length === 0 ? 1 : groupBys . length ;
132+ const groupByFieldCount =
133+ groupBys . length === 0 && isVisualizeFunction ( visualize ) ? 1 : groupBys . length ;
125134 const aggregateFieldCount = displayFields . length - groupByFieldCount ;
126135
127136 const tableStyle = useMemo ( ( ) => {
@@ -233,12 +242,16 @@ export function AggregatesTab({traceMetric, isMetricOptionsEmpty}: AggregatesTab
233242 label = `${ func . name } (…)` ;
234243 } else if ( tag ) {
235244 label = tag . name ;
245+ } else if ( isEquation ( field ) ) {
246+ // TODO: This should say the reference format of equations
247+ label = t ( 'Result' ) ;
236248 } else {
237249 label = prettifyTagKey ( field ) ;
238250 }
239251
240252 const direction = sorts . find ( s => s . field === field ) ?. kind ;
241- const canSort = displayColumns [ i ] ?. isSortable !== false ;
253+ const canSort =
254+ displayColumns . find ( column => column . key === field ) ?. isSortable !== false ;
242255
243256 function updateSort ( ) {
244257 const kind = direction === 'desc' ? 'asc' : 'desc' ;
@@ -250,7 +263,9 @@ export function AggregatesTab({traceMetric, isMetricOptionsEmpty}: AggregatesTab
250263 key = { i }
251264 divider = { shouldShowDivider ( i ) }
252265 data-sticky-column = { isLastColumn ( i ) ? 'true' : 'false' }
253- isAggregate = { Boolean ( func ) }
266+ isAggregate = {
267+ Boolean ( func ) || ( isVisualizeEquation ( visualize ) && isEquation ( field ) )
268+ }
254269 isSticky = { isLastColumn ( i ) }
255270 sort = { direction }
256271 handleSortClick = { canSort ? updateSort : undefined }
@@ -289,7 +304,7 @@ export function AggregatesTab({traceMetric, isMetricOptionsEmpty}: AggregatesTab
289304 offset = { j === 0 ? firstColumnOffset : undefined }
290305 >
291306 < FieldRenderer
292- column = { displayColumns [ j ] }
307+ column = { displayColumns . find ( column => column . key === field ) }
293308 data = { displayRow }
294309 unit = { getMetricsUnit ( meta , field ) }
295310 meta = { meta }
0 commit comments