Skip to content

Commit

Permalink
Fix: time to production showing NaN when no data (#6799)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
andreas-unleash committed Apr 9, 2024
1 parent 451d475 commit 130bc20
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions frontend/src/component/insights/hooks/useFilteredFlagsSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 130bc20

Please sign in to comment.