Skip to content

Commit 453410e

Browse files
authored
refactor(app): refactor ODD protocol card copy when run data is not "ok" (#17261)
Closes RQA-3851 When protocol cards have not ok run data, we can't retrieve the completedAt timestamp, and the fallback has been the current date, which is confusing copy. After speaking with Design, the plan is to remove copy if we can't retrieve the completedAt timestamp.
1 parent 061ab89 commit 453410e

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

app/src/organisms/ODD/RobotDashboard/RecentRunProtocolCard.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,22 @@ export function ProtocolWithLastRun({
158158
[RUN_STATUS_SUCCEEDED]: t('completed'),
159159
[RUN_STATUS_FAILED]: t('failed'),
160160
}
161-
// TODO(BC, 2023-06-05): see if addSuffix false allow can remove usage of .replace here
162-
const formattedLastRunTime = formatDistance(
163-
// Fallback to current date if completedAt is null, though this should never happen since runs must be completed to appear in dashboard
164-
new Date(runData.completedAt ?? new Date()),
165-
new Date(),
166-
{
167-
addSuffix: true,
161+
const formattedLastRunTime =
162+
runData.completedAt != null
163+
? formatDistance(new Date(runData.completedAt), new Date(), {
164+
addSuffix: true,
165+
}).replace('about ', '')
166+
: null
167+
const buildLastRunCopy = (): string => {
168+
if (formattedLastRunTime != null) {
169+
return i18n.format(
170+
`${terminationTypeMap[runData.status] ?? ''} ${formattedLastRunTime}`,
171+
'capitalize'
172+
)
173+
} else {
174+
return ''
168175
}
169-
).replace('about ', '')
176+
}
170177

171178
return isProtocolFetching || isLookingForHardware ? (
172179
<Skeleton
@@ -227,10 +234,7 @@ export function ProtocolWithLastRun({
227234
lineHeight={TYPOGRAPHY.lineHeight28}
228235
color={COLORS.grey60}
229236
>
230-
{i18n.format(
231-
`${terminationTypeMap[runData.status] ?? ''} ${formattedLastRunTime}`,
232-
'capitalize'
233-
)}
237+
{buildLastRunCopy()}
234238
</LegacyStyledText>
235239
</Flex>
236240
)

0 commit comments

Comments
 (0)