Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
gabalafou committed Mar 26, 2024
1 parent 8847ffb commit ed12797
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/features/metadata/components/EnvBuildStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const LogLink = ({ logArtifact }: { logArtifact: Artifact }) => {
);
};

export interface IEnvBuildStatusProps {
interface IEnvBuildStatusProps {
build: Build;
}

Expand Down
41 changes: 13 additions & 28 deletions src/utils/helpers/buildMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@ const STATUS_OPTIONS: { [key: Build["status"]]: string } = {

const TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;

const isCompleted = ({
status,
ended_on,
scheduled_on
}: Pick<Build, "status" | "ended_on" | "scheduled_on">) => {
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 (status === "COMPLETED") {
if (duration > 0) {
return `Completed in ${duration} min`;
}
return "Completed";
}
return STATUS_OPTIONS[status];
};

const dateToTimezone = (date: string) => {
if (!date) {
return "";
Expand Down Expand Up @@ -65,11 +43,18 @@ export const buildStatus = ({
scheduled_on
}: Build): string => {
switch (status) {
case "BUILDING":
case "QUEUED":
return "Building";
default: {
return isCompleted({ status, ended_on, scheduled_on });
}
case "COMPLETED":
if (ended_on && scheduled_on) {
const startTime = new Date(scheduled_on);
const endTime = new Date(ended_on);
let duration = (endTime.valueOf() - startTime.valueOf()) / 60000;
duration = Math.round(duration);
if (duration > 0) {
return `Completed in ${duration} min`;
}
}
return "Completed";
default:
return STATUS_OPTIONS[status];
}
};

0 comments on commit ed12797

Please sign in to comment.