Skip to content

Commit 119b67c

Browse files
committed
refactor(app): prettify the historical run log offsets accordion
1 parent b7ba137 commit 119b67c

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

app/src/organisms/Desktop/Devices/HistoricalProtocolRunDrawer.tsx

+41-19
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,24 @@ import {
1515
InfoScreen,
1616
JUSTIFY_FLEX_START,
1717
LegacyStyledText,
18+
MODULE_ICON_NAME_BY_TYPE,
1819
OVERFLOW_HIDDEN,
1920
SPACING,
2021
TYPOGRAPHY,
2122
} from '@opentrons/components'
2223
import {
24+
FLEX_STACKER_MODULE_TYPE,
2325
getLabwareDefURI,
2426
getLabwareDisplayName,
2527
getLoadedLabwareDefinitionsByUri,
26-
getModuleDisplayName,
28+
getModuleType,
2729
} from '@opentrons/shared-data'
2830
import { useCsvFileQuery } from '@opentrons/react-api-client'
2931
import { DownloadCsvFileLink } from './DownloadCsvFileLink'
3032
import { useMostRecentCompletedAnalysis } from '/app/resources/runs'
3133
import { useDeckCalibrationData } from './hooks'
3234
import { OffsetVector } from '/app/molecules/OffsetVector'
33-
import type { RunData } from '@opentrons/api-client'
35+
import type { LabwareOffset, RunData } from '@opentrons/api-client'
3436

3537
interface HistoricalProtocolRunDrawerProps {
3638
run: RunData
@@ -42,9 +44,11 @@ export function HistoricalProtocolRunDrawer(
4244
): JSX.Element | null {
4345
const { i18n, t } = useTranslation('run_details')
4446
const { run, robotName } = props
45-
const allLabwareOffsets = run.labwareOffsets?.sort(
46-
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
47-
)
47+
const allLabwareOffsets: LabwareOffset[] =
48+
run.labwareOffsets?.sort(
49+
(a, b) =>
50+
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
51+
) ?? []
4852
const runDataFileIds =
4953
'runTimeParameters' in run
5054
? run.runTimeParameters.reduce<string[]>((acc, parameter) => {
@@ -60,17 +64,22 @@ export function HistoricalProtocolRunDrawer(
6064
runDataFileIds.push(...run.outputFileIds)
6165
}
6266

63-
const uniqueLabwareOffsets = allLabwareOffsets?.filter(
67+
const uniqueLabwareOffsets = allLabwareOffsets.filter(
6468
(offset, index, array) => {
6569
return (
6670
array.findIndex(
6771
firstOffset =>
68-
firstOffset.location.slotName === offset.location.slotName &&
69-
firstOffset.definitionUri === offset.definitionUri
70-
) === index && !isEqual(offset.vector, { x: 0, y: 0, z: 0 })
72+
isEqual(firstOffset.locationSequence, offset.locationSequence) &&
73+
isEqual(firstOffset.definitionUri, offset.definitionUri)
74+
) === index
7175
)
7276
}
7377
)
78+
const sortedUniqueLwOffsets = uniqueLabwareOffsets.sort((a, b) =>
79+
a.location.slotName.localeCompare(b.location.slotName, 'en', {
80+
numeric: true,
81+
})
82+
)
7483

7584
const deckCalibrationData = useDeckCalibrationData(robotName)
7685
.deckCalibrationData
@@ -82,11 +91,10 @@ export function HistoricalProtocolRunDrawer(
8291

8392
const isOutOfDate =
8493
typeof lastModifiedDeckCal === 'string' &&
85-
uniqueLabwareOffsets != null &&
86-
uniqueLabwareOffsets.length > 0 &&
94+
sortedUniqueLwOffsets.length > 0 &&
8795
new Date(lastModifiedDeckCal).getTime() >
8896
new Date(
89-
uniqueLabwareOffsets[uniqueLabwareOffsets?.length - 1].createdAt
97+
sortedUniqueLwOffsets[sortedUniqueLwOffsets?.length - 1].createdAt
9098
).getTime()
9199
const outOfDateBanner = isOutOfDate ? (
92100
<Banner
@@ -153,7 +161,7 @@ export function HistoricalProtocolRunDrawer(
153161
)
154162

155163
const labwareOffsets =
156-
uniqueLabwareOffsets == null || uniqueLabwareOffsets.length === 0 ? (
164+
sortedUniqueLwOffsets == null || sortedUniqueLwOffsets.length === 0 ? (
157165
<InfoScreen content={t('no_offsets_available')} />
158166
) : (
159167
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing4}>
@@ -198,7 +206,7 @@ export function HistoricalProtocolRunDrawer(
198206
</Box>
199207
</Flex>
200208
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing4}>
201-
{uniqueLabwareOffsets.map((offset, index) => {
209+
{sortedUniqueLwOffsets.map((offset, index) => {
202210
const labwareDefinitions =
203211
protocolDetails?.commands != null
204212
? getLoadedLabwareDefinitionsByUri(protocolDetails?.commands)
@@ -227,11 +235,25 @@ export function HistoricalProtocolRunDrawer(
227235
alignItems={ALIGN_CENTER}
228236
>
229237
<DeckInfoLabel deckLabel={offset.location.slotName} />
230-
<LegacyStyledText as="p">
231-
{offset.location.moduleModel != null
232-
? getModuleDisplayName(offset.location.moduleModel)
233-
: null}
234-
</LegacyStyledText>
238+
{offset.locationSequence?.some(
239+
seq => seq.kind === 'onLabware'
240+
) && (
241+
<DeckInfoLabel
242+
iconName={
243+
MODULE_ICON_NAME_BY_TYPE[FLEX_STACKER_MODULE_TYPE]
244+
}
245+
key="stacked-icon"
246+
/>
247+
)}
248+
{offset.location.moduleModel && (
249+
<DeckInfoLabel
250+
iconName={
251+
MODULE_ICON_NAME_BY_TYPE[
252+
getModuleType(offset.location.moduleModel)
253+
]
254+
}
255+
/>
256+
)}
235257
</Flex>
236258
<Box width="33%">
237259
<LegacyStyledText as="p" title={labwareName}>

0 commit comments

Comments
 (0)