Skip to content

Commit ca3887d

Browse files
authored
fix(tracemetrics): Format aggregate header cell in widget viewer (#105664)
Currently, the table in the widget viewer renders with the long format of the axis value. This creates a header title mapping so we can display a more user-friendly name in the table. e.g. instead of `p50(value,metric_name,distribution,-)` we'll only display `p50(metric_name)`
1 parent 523c068 commit ca3887d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

static/app/components/modals/widgetViewerModal.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,7 @@ function ViewerTableV2({
10481048
const aliases = decodeColumnAliases(
10491049
tableColumns,
10501050
tableWidget.queries[selectedQueryIndex]?.fieldAliases ?? [],
1051-
tableWidget.widgetType === WidgetType.ISSUE
1052-
? datasetConfig?.getFieldHeaderMap?.()
1053-
: {}
1051+
datasetConfig?.getFieldHeaderMap?.(tableWidget.queries[selectedQueryIndex]) ?? {}
10541052
);
10551053

10561054
// Inject any prettified function names that aren't currently aliased into the aliases

static/app/views/dashboards/datasetConfig/traceMetrics.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ function useTraceMetricsSearchBarDataProvider(
164164

165165
export function formatTraceMetricsFunction(
166166
valueToParse: string,
167-
defaultValue: string | ReactNode = ''
167+
defaultValue?: string | ReactNode
168168
) {
169169
const parsedFunction = parseFunction(valueToParse);
170170
if (parsedFunction) {
171171
return `${parsedFunction.name}(${parsedFunction.arguments[1] ?? '…'})`;
172172
}
173-
return defaultValue;
173+
return defaultValue ?? valueToParse;
174174
}
175175

176176
export const TraceMetricsConfig: DatasetConfig<
@@ -259,6 +259,17 @@ export const TraceMetricsConfig: DatasetConfig<
259259
getCustomFieldRenderer: (field, meta, _organization) => {
260260
return getFieldRenderer(field, meta, false);
261261
},
262+
getFieldHeaderMap: widgetQuery => {
263+
return (
264+
widgetQuery?.aggregates.reduce(
265+
(acc, aggregate) => {
266+
acc[aggregate] = formatTraceMetricsFunction(aggregate) as string;
267+
return acc;
268+
},
269+
{} as Record<string, string>
270+
) ?? {}
271+
);
272+
},
262273
};
263274

264275
function getPrimaryFieldOptions(

0 commit comments

Comments
 (0)