From c9a400eab403d19221df3650f8a9c33014706dcb Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Thu, 7 Sep 2023 16:14:54 -0500 Subject: [PATCH] Display build time for environments --- src/utils/helpers/buildMapper.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/utils/helpers/buildMapper.ts b/src/utils/helpers/buildMapper.ts index d9fbb63c..85d7292b 100644 --- a/src/utils/helpers/buildMapper.ts +++ b/src/utils/helpers/buildMapper.ts @@ -20,8 +20,11 @@ const isQueued = (status: string) => { return BUILD_STATUS.includes(status); }; -const isCompleted = (status: string) => { +const isCompleted = (status: string, duration: number) => { if (status === "COMPLETED") { + if (duration > 0) { + return `Completed in ${duration} min`; + } return "Completed"; } return STATUS_OPTIONS[status]; @@ -39,11 +42,18 @@ const dateToTimezone = (date: string) => { export const buildMapper = (data: Build[], currentBuildId: number) => { return data.map(({ id, status, ended_on, scheduled_on }: Build) => { + let duration = 0; + if (ended_on && scheduled_on) { + const startTime = new Date(scheduled_on); + const endTime = new Date(ended_on); + duration = (endTime.valueOf() - startTime.valueOf()) / 60000; + duration = Math.round(duration); + } if (id === currentBuildId) { return { id, name: `${dateToTimezone(ended_on ?? scheduled_on)} - Active`, - status: isCompleted(status) + status: isCompleted(status, duration) }; } @@ -68,7 +78,7 @@ export const buildMapper = (data: Build[], currentBuildId: number) => { name: `${dateToTimezone(ended_on ?? scheduled_on)} - ${ STATUS_OPTIONS[status] }`, - status: isCompleted(status) + status: isCompleted(status, duration) }; }); };