Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
63 changes: 39 additions & 24 deletions static/app/utils/discover/fieldRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,36 @@ function renderAIOutputMessages(rawOutputMessages: unknown) {
* "Special fields" either do not map 1:1 to an single column in the event database,
* or they require custom UI formatting that can't be handled by the datatype formatters.
*/
function performanceScoreRenderer(field: string): SpecialField {
return {
renderFunc: data => {
const score = data[field];
if (typeof score !== 'number') {
return <RightAlignedContainer>{emptyValue}</RightAlignedContainer>;
}
return (
<RightAlignedContainer>
<PerformanceBadge score={Math.round(score * 100)} />
</RightAlignedContainer>
);
},
};
}

function opportunityScoreRenderer(field: string): SpecialField {
return {
renderFunc: data => {
const score = data[field];
if (typeof score !== 'number') {
return <Container>{emptyValue}</Container>;
}
return (
<RightAlignedContainer>{Math.round(score * 10000) / 100}</RightAlignedContainer>
);
},
};
}

const SPECIAL_FIELDS: Record<string, SpecialField> = {
// This is a custom renderer for a field outside discover
// TODO - refactor code and remove from this file or add ability to query for attachments in Discover
Expand Down Expand Up @@ -866,30 +896,15 @@ const SPECIAL_FIELDS: Record<string, SpecialField> = {
</Container>
),
},
'performance_score(measurements.score.total)': {
renderFunc: data => {
const score = data['performance_score(measurements.score.total)'];
if (typeof score !== 'number') {
return <RightAlignedContainer>{emptyValue}</RightAlignedContainer>;
}
return (
<RightAlignedContainer>
<PerformanceBadge score={Math.round(score * 100)} />
</RightAlignedContainer>
);
},
},
'opportunity_score(measurements.score.total)': {
renderFunc: data => {
const score = data['opportunity_score(measurements.score.total)'];
if (typeof score !== 'number') {
return <Container>{emptyValue}</Container>;
}
return (
<RightAlignedContainer>{Math.round(score * 10000) / 100}</RightAlignedContainer>
);
},
},
// The spans form takes the total score measurement, the trace metrics form no argument
'performance_score(measurements.score.total)': performanceScoreRenderer(
'performance_score(measurements.score.total)'
),
'performance_score()': performanceScoreRenderer('performance_score()'),
'opportunity_score(measurements.score.total)': opportunityScoreRenderer(
'opportunity_score(measurements.score.total)'
),
'opportunity_score()': opportunityScoreRenderer('opportunity_score()'),
'browser.name': {
renderFunc: data => {
const browserName = data['browser.name'];
Expand Down
2 changes: 2 additions & 0 deletions static/app/utils/discover/getSortField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ const SPECIAL_FIELD_SORT_FIELDS = {
'span.status_code': 'span.status_code',
'performance_score(measurements.score.total)':
'performance_score(measurements.score.total)',
'performance_score()': 'performance_score()',
'opportunity_score(measurements.score.total)':
'opportunity_score(measurements.score.total)',
'opportunity_score()': 'opportunity_score()',
'browser.name': 'browser.name',
browser: 'browser',
'os.name': 'os.name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export function webVitalCountField(vital: WebVitals): string {
export const WEB_VITAL_SCORE_FIELDS = ORDER.map(webVitalScoreField);
export const WEB_VITAL_SCORE_COUNT_FIELDS = ORDER.map(webVitalScoreCountField);

export const PERFORMANCE_SCORE_FIELD = 'performance_score(measurements.score.total)';
export const OPPORTUNITY_SCORE_FIELD = 'opportunity_score(measurements.score.total)';
export const PERFORMANCE_SCORE_FIELD = 'performance_score()';
export const OPPORTUNITY_SCORE_FIELD = 'opportunity_score()';

export function isWebVitalScoreFormula(field: string): boolean {
return field === PERFORMANCE_SCORE_FIELD || field === OPPORTUNITY_SCORE_FIELD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe('hasUnresolvedTraceMetric', () => {
WidgetQueryFixture({
aggregates: [
'count(value,browser.web_vital.ttfb,distribution,millisecond)',
'performance_score(measurements.score.total)',
'opportunity_score(measurements.score.total)',
'performance_score()',
'opportunity_score()',
],
}),
],
Expand Down
Loading