From 47a6ff7f71b3db4dd28d0fb6770bc47d79a91b69 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Wed, 20 Jan 2021 19:40:50 -0500 Subject: [PATCH] Add fields and reword card --- .../jenkins/src/components/Cards/Cards.tsx | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/plugins/jenkins/src/components/Cards/Cards.tsx b/plugins/jenkins/src/components/Cards/Cards.tsx index 31acedc180..447afff266 100644 --- a/plugins/jenkins/src/components/Cards/Cards.tsx +++ b/plugins/jenkins/src/components/Cards/Cards.tsx @@ -14,6 +14,7 @@ * limitations under the License. */ import React from 'react'; +import { DateTime, Duration } from 'luxon'; import { Link, Theme, makeStyles, LinearProgress } from '@material-ui/core'; import { InfoCard, StructuredMetadataTable } from '@backstage/core'; import ExternalLinkIcon from '@material-ui/icons/Launch'; @@ -30,28 +31,37 @@ const useStyles = makeStyles({ const WidgetContent = ({ loading, - lastRun, + latestRun, }: { loading?: boolean; - lastRun: any; + latestRun: any; branch: string; }) => { const classes = useStyles(); - if (loading || !lastRun) return ; - + if (loading || !latestRun) return ; + const displayDate = DateTime.fromMillis(latestRun.timestamp).toRelative(); + // TODO This works, but hard codes as minutes. Would prefer something smarter/relative. + const durationInMinutes = Math.round( + Duration.fromMillis(latestRun.duration).as('minutes'), + ); + const displayDuration = `${durationInMinutes} minute${ + durationInMinutes > 1 ? 's' : '' + }`; return ( ), - build: lastRun.fullDisplayName, - url: ( - + build: latestRun.fullDisplayName, + 'latest run': displayDate, + duration: displayDuration, + link: ( + See more on Jenkins{' '} @@ -70,10 +80,10 @@ export const LatestRunCard = ({ }) => { const { owner, repo } = useProjectSlugFromEntity(); const [{ builds, loading }] = useBuilds(owner, repo, branch); - const lastRun = builds ?? {}; + const latestRun = builds ?? {}; return ( - - + + ); };