Skip to content

Commit

Permalink
handle infinity in JSON responses
Browse files Browse the repository at this point in the history
  • Loading branch information
maany committed Dec 13, 2023
1 parent b78594d commit 403fdf1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/app/(rucio)/rule/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ export default function CreateRule() {
)

const processRSEAccountUsageLimitViewModelBatchResponse = (batch: BatchResponse<RSEAccountUsageLimitViewModel>) => {
// 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
Expand Down
2 changes: 1 addition & 1 deletion src/component-library/Pages/Rule/CreateRuleRSETable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
11 changes: 11 additions & 0 deletions src/component-library/Text/Content/Number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ export const Number: React.FC<ByteProps> = (
0
</span>
)
if(number === Infinity) return (
<span
className={twMerge(
className ?? "",
"text-yellow-500 text-bold", // placed here to override all other classes for Infinity
)}
{...otherprops}
>
Infinity
</span>
)
if (isNaN(+number)) return (
<span
className={twMerge(
Expand Down

0 comments on commit 403fdf1

Please sign in to comment.