fix(ui): ignore non-finite quota percentages (#1329)
Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
5189eb586e
commit
81c72df8ea
@@ -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('-');
|
||||
});
|
||||
});
|
||||
@@ -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)}%`;
|
||||
|
||||
Reference in New Issue
Block a user