From 130bc206830dc8e5315fb92ab2fe3de41a454e0c Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Tue, 9 Apr 2024 09:27:47 +0300 Subject: [PATCH] Fix: time to production showing NaN when no data (#6799) Before: Screenshot 2024-04-08 at 16 20 48 After: Screenshot 2024-04-08 at 16 45 47 --------- Signed-off-by: andreas-unleash --- .../insights/hooks/useFilteredFlagsSummary.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/component/insights/hooks/useFilteredFlagsSummary.ts b/frontend/src/component/insights/hooks/useFilteredFlagsSummary.ts index 8bfbe7885128..eab5630e8912 100644 --- a/frontend/src/component/insights/hooks/useFilteredFlagsSummary.ts +++ b/frontend/src/component/insights/hooks/useFilteredFlagsSummary.ts @@ -48,18 +48,24 @@ export const useFilteredFlagsSummary = ( const timesToProduction: number[] = lastWeekSummary .filter(validTimeToProduction) - .map((item) => item.timeToProduction!); // Non-null assertion is safe due to filter + .map((item) => item.timeToProduction!); // Calculate median timeToProduction for lastWeekSummary timesToProduction.sort((a, b) => a - b); const midIndex = Math.floor(timesToProduction.length / 2); - const medianTimeToProduction = + const medianTimeToProductionCalculation = timesToProduction.length % 2 === 0 ? (timesToProduction[midIndex - 1] + timesToProduction[midIndex]) / 2 : timesToProduction[midIndex]; + const medianTimeToProduction = Number.isNaN( + medianTimeToProductionCalculation, + ) + ? undefined + : medianTimeToProductionCalculation; + const flagsPerUserCalculation = sum.total / users.total; const flagsPerUser = Number.isNaN(flagsPerUserCalculation) ? 'N/A'