From 8815cdc0044e1e648eece5922a76f4a5d228f266 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Mon, 8 Feb 2021 19:29:19 -0500 Subject: [PATCH 1/4] Smater duration display --- plugins/jenkins/src/components/Cards/Cards.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/jenkins/src/components/Cards/Cards.tsx b/plugins/jenkins/src/components/Cards/Cards.tsx index 447afff266..772632668c 100644 --- a/plugins/jenkins/src/components/Cards/Cards.tsx +++ b/plugins/jenkins/src/components/Cards/Cards.tsx @@ -40,13 +40,13 @@ const WidgetContent = ({ const classes = useStyles(); 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' : '' - }`; + const displayDuration = + (latestRun.building ? 'Running for ' : '') + + DateTime.local() + .minus(Duration.fromMillis(latestRun.duration)) + .toRelative() + ?.replace(' ago', ''); + return ( Date: Mon, 8 Feb 2021 19:30:16 -0500 Subject: [PATCH 2/4] Add changeset --- .changeset/hip-pets-sell.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hip-pets-sell.md diff --git a/.changeset/hip-pets-sell.md b/.changeset/hip-pets-sell.md new file mode 100644 index 0000000000..7773d8d008 --- /dev/null +++ b/.changeset/hip-pets-sell.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-jenkins': patch +--- + +Improve display of duration in latest build card From a621697f47303b39e0bbe8064895cc7c02baaaca Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 10 Feb 2021 22:00:07 +0100 Subject: [PATCH 3/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rémi Doreau <32459935+ayshiff@users.noreply.github.com> --- plugins/jenkins/src/components/Cards/Cards.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/jenkins/src/components/Cards/Cards.tsx b/plugins/jenkins/src/components/Cards/Cards.tsx index 772632668c..c7efde6523 100644 --- a/plugins/jenkins/src/components/Cards/Cards.tsx +++ b/plugins/jenkins/src/components/Cards/Cards.tsx @@ -44,7 +44,7 @@ const WidgetContent = ({ (latestRun.building ? 'Running for ' : '') + DateTime.local() .minus(Duration.fromMillis(latestRun.duration)) - .toRelative() + .toRelative({ locale: "en" }) ?.replace(' ago', ''); return ( From ea1ac7b6ec932e9aabd8721a6fffb83636ff58d5 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Wed, 10 Feb 2021 19:17:41 -0500 Subject: [PATCH 4/4] Fix prettier --- plugins/jenkins/src/components/Cards/Cards.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/jenkins/src/components/Cards/Cards.tsx b/plugins/jenkins/src/components/Cards/Cards.tsx index c7efde6523..6fc544bcea 100644 --- a/plugins/jenkins/src/components/Cards/Cards.tsx +++ b/plugins/jenkins/src/components/Cards/Cards.tsx @@ -44,7 +44,7 @@ const WidgetContent = ({ (latestRun.building ? 'Running for ' : '') + DateTime.local() .minus(Duration.fromMillis(latestRun.duration)) - .toRelative({ locale: "en" }) + .toRelative({ locale: 'en' }) ?.replace(' ago', ''); return (