From 403fdf1d040d80877d80fb7981284b701be077c9 Mon Sep 17 00:00:00 2001 From: maany Date: Wed, 13 Dec 2023 04:30:25 +0100 Subject: [PATCH] handle infinity in JSON responses --- src/app/(rucio)/rule/create/page.tsx | 6 ++++++ .../Pages/Rule/CreateRuleRSETable.tsx | 2 +- src/component-library/Text/Content/Number.tsx | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app/(rucio)/rule/create/page.tsx b/src/app/(rucio)/rule/create/page.tsx index 017be1dca..37869e7f1 100644 --- a/src/app/(rucio)/rule/create/page.tsx +++ b/src/app/(rucio)/rule/create/page.tsx @@ -78,11 +78,17 @@ export default function CreateRule() { ) const processRSEAccountUsageLimitViewModelBatchResponse = (batch: BatchResponse) => { + // The feature replaces Infinity with -1 for the bytes_limit and bytes_remaining fields + // This is done because Infinity is not a valid JSON value + // This code replaces -1 with Infinity for the bytes_limit and bytes_remaining fields batch.data.forEach((rseAccountUsageLimitViewModel: RSEAccountUsageLimitViewModel) => { if(rseAccountUsageLimitViewModel.status === 'success') { if(rseAccountUsageLimitViewModel.bytes_limit === -1) { rseAccountUsageLimitViewModel.bytes_limit = Infinity } + if(rseAccountUsageLimitViewModel.bytes_remaining === -1) { + rseAccountUsageLimitViewModel.bytes_remaining = Infinity + } } }) return batch diff --git a/src/component-library/Pages/Rule/CreateRuleRSETable.tsx b/src/component-library/Pages/Rule/CreateRuleRSETable.tsx index 668aa2465..1aab4e000 100644 --- a/src/component-library/Pages/Rule/CreateRuleRSETable.tsx +++ b/src/component-library/Pages/Rule/CreateRuleRSETable.tsx @@ -88,7 +88,7 @@ export const CreateRuleRSETable = ( style: "w-24" } }), - columnHelper.accessor(row => row.bytes_limit - row.used_bytes, { + columnHelper.accessor(row => row.bytes_remaining, { id: 'remaining_bytes', header: info => { return ( diff --git a/src/component-library/Text/Content/Number.tsx b/src/component-library/Text/Content/Number.tsx index cdec96d72..5ddb52a20 100644 --- a/src/component-library/Text/Content/Number.tsx +++ b/src/component-library/Text/Content/Number.tsx @@ -20,6 +20,17 @@ export const Number: React.FC = ( 0 ) + if(number === Infinity) return ( + + Infinity + + ) if (isNaN(+number)) return (