1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-26 01:17:00 +02:00

Fix: time to production showing NaN when no data (#6799)

Before: 

<img width="1398" alt="Screenshot 2024-04-08 at 16 20 48"
src="https://github.com/Unleash/unleash/assets/104830839/892860f8-80de-4750-bad2-0e17ac221f1f">


After: 

<img width="1243" alt="Screenshot 2024-04-08 at 16 45 47"
src="https://github.com/Unleash/unleash/assets/104830839/3247c90a-f92f-4d4f-b407-275549b308bf">

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
andreas-unleash 2024-04-09 09:27:47 +03:00 committed by GitHub
parent 451d475d21
commit 130bc20683
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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'