fix(ui): ignore non-finite quota percentages (#1329)

Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
Isaac Sanchez-Hawkins
2026-05-19 17:38:11 +03:00
committed by GitHub
co-authored by Isaac Sanchez
parent 5189eb586e
commit 81c72df8ea
2 changed files with 15 additions and 2 deletions
+13
View File
@@ -0,0 +1,13 @@
import { describe, expect, test } from 'bun:test';
import { clampPercent, formatPercent } from './utils';
describe('quota utils', () => {
test('treats non-finite percentages as missing', () => {
expect(clampPercent(Infinity)).toBeNull();
expect(clampPercent(-Infinity)).toBeNull();
expect(formatPercent(Infinity)).toBe('-');
expect(formatPercent(-Infinity)).toBe('-');
});
});
+2 -2
View File
@@ -1,12 +1,12 @@
export const clampPercent = (value: number | null): number | null => {
if (typeof value !== 'number' || Number.isNaN(value)) {
if (typeof value !== 'number' || !Number.isFinite(value)) {
return null;
}
return Math.max(0, Math.min(100, Math.round(value)));
};
export const formatPercent = (value: number | null): string => {
if (typeof value !== 'number' || Number.isNaN(value)) {
if (typeof value !== 'number' || !Number.isFinite(value)) {
return '-';
}
return `${Math.round(value)}%`;