From e1b26a68e5525662dcbbda4faccc3cd0139b75a3 Mon Sep 17 00:00:00 2001 From: Terry Sutton Date: Tue, 10 May 2022 15:26:47 -0230 Subject: [PATCH] Fixes the NaN errors on the billing table --- studio/hooks/queries/useProjectPaygStatistics.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/studio/hooks/queries/useProjectPaygStatistics.ts b/studio/hooks/queries/useProjectPaygStatistics.ts index 08f9d9efc9c..37b11a69ec5 100644 --- a/studio/hooks/queries/useProjectPaygStatistics.ts +++ b/studio/hooks/queries/useProjectPaygStatistics.ts @@ -50,18 +50,22 @@ function getPaygStats(data: any): PaygStats { let dataModified: any = [] data.map((x: any) => { - dataModified.push({ ...x, total_egress_modified: x.total_egress - x.total_storage_egress }) + dataModified.push({ ...x, total_egress_modified: x.total_egress == undefined ? 0 : x.total_egress - x.total_storage_egress == undefined ? 0 : x.total_storage_egress }) }) chargeableProducts.forEach((product) => { product.features.forEach((feature) => { + // calculate max - const max = _get(maxBy(dataModified, feature.attribute), feature.attribute) + const max = _get(maxBy(dataModified, feature.attribute), feature.attribute) ?? 0 + // calculate sum let sum = 0 dataModified.map((x: any) => { - sum = sum + x[feature.attribute] + const featureAttribute = x[feature.attribute] == undefined ? 0 : x[feature.attribute] + sum = sum + featureAttribute }) + // set sum and max under attribute name paygStats[feature.attribute] = { sum,