Skip to content

Commit c5eb380

Browse files
committed
Support minimum values in metric readouts
1 parent d6d72f7 commit c5eb380

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

static/app/views/performance/metricReadout.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface Props {
2929
value: ReactText | undefined;
3030
align?: 'left' | 'right';
3131
isLoading?: boolean;
32+
minimumValue?: number;
3233
tooltip?: React.ReactNode;
3334
}
3435

@@ -40,7 +41,14 @@ export function MetricReadout(props: Props) {
4041
);
4142
}
4243

43-
function ReadoutContent({unit, value, tooltip, align = 'right', isLoading}: Props) {
44+
function ReadoutContent({
45+
unit,
46+
value,
47+
tooltip,
48+
align = 'right',
49+
isLoading,
50+
minimumValue,
51+
}: Props) {
4452
if (isLoading) {
4553
return (
4654
<LoadingContainer align={align}>
@@ -58,7 +66,9 @@ function ReadoutContent({unit, value, tooltip, align = 'right', isLoading}: Prop
5866
if (isARateUnit(unit)) {
5967
renderedValue = (
6068
<NumberContainer align={align}>
61-
{formatRate(typeof value === 'string' ? parseFloat(value) : value, unit)}
69+
{formatRate(typeof value === 'string' ? parseFloat(value) : value, unit, {
70+
minimumValue: minimumValue ?? MINIMUM_RATE,
71+
})}
6272
</NumberContainer>
6373
);
6474
}
@@ -96,7 +106,13 @@ function ReadoutContent({unit, value, tooltip, align = 'right', isLoading}: Prop
96106
if (unit === 'percentage') {
97107
renderedValue = (
98108
<NumberContainer align={align}>
99-
{formatPercentage(typeof value === 'string' ? parseFloat(value) : value)}
109+
{formatPercentage(
110+
typeof value === 'string' ? parseFloat(value) : value,
111+
undefined,
112+
{
113+
minimumValue: minimumValue ?? MINIMUM_PERCENTAGE,
114+
}
115+
)}
100116
</NumberContainer>
101117
);
102118
}
@@ -114,6 +130,9 @@ function ReadoutContent({unit, value, tooltip, align = 'right', isLoading}: Prop
114130
return <NumberContainer align={align}>{renderedValue}</NumberContainer>;
115131
}
116132

133+
const MINIMUM_RATE = 0.01;
134+
const MINIMUM_PERCENTAGE = 0.01;
135+
117136
const NumberContainer = styled('div')<{align: 'left' | 'right'}>`
118137
text-align: ${p => p.align};
119138
font-variant-numeric: tabular-nums;

0 commit comments

Comments
 (0)