From 11719a08b8f842bccdfe0cd3a50d6fd27aeefb2c Mon Sep 17 00:00:00 2001 From: Jamey Huffnagle <jamey.huffnagle@opentrons.com> Date: Tue, 14 Jan 2025 10:32:14 -0500 Subject: [PATCH] refactor(app): refactor ODD protocol card copy when run data is not "ok" --- .../RobotDashboard/RecentRunProtocolCard.tsx | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/organisms/ODD/RobotDashboard/RecentRunProtocolCard.tsx b/app/src/organisms/ODD/RobotDashboard/RecentRunProtocolCard.tsx index e522fb1dae7..a91bb4fbda1 100644 --- a/app/src/organisms/ODD/RobotDashboard/RecentRunProtocolCard.tsx +++ b/app/src/organisms/ODD/RobotDashboard/RecentRunProtocolCard.tsx @@ -158,15 +158,22 @@ export function ProtocolWithLastRun({ [RUN_STATUS_SUCCEEDED]: t('completed'), [RUN_STATUS_FAILED]: t('failed'), } - // TODO(BC, 2023-06-05): see if addSuffix false allow can remove usage of .replace here - const formattedLastRunTime = formatDistance( - // Fallback to current date if completedAt is null, though this should never happen since runs must be completed to appear in dashboard - new Date(runData.completedAt ?? new Date()), - new Date(), - { - addSuffix: true, + const formattedLastRunTime = + runData.completedAt != null + ? formatDistance(new Date(runData.completedAt), new Date(), { + addSuffix: true, + }).replace('about ', '') + : null + const buildLastRunCopy = (): string => { + if (formattedLastRunTime != null) { + return i18n.format( + `${terminationTypeMap[runData.status] ?? ''} ${formattedLastRunTime}`, + 'capitalize' + ) + } else { + return '' } - ).replace('about ', '') + } return isProtocolFetching || isLookingForHardware ? ( <Skeleton @@ -227,10 +234,7 @@ export function ProtocolWithLastRun({ lineHeight={TYPOGRAPHY.lineHeight28} color={COLORS.grey60} > - {i18n.format( - `${terminationTypeMap[runData.status] ?? ''} ${formattedLastRunTime}`, - 'capitalize' - )} + {buildLastRunCopy()} </LegacyStyledText> </Flex> )