@@ -18,92 +18,23 @@ import {
18
18
StyledText ,
19
19
useMenuHandleClickOutside ,
20
20
} from '@opentrons/components'
21
- import { getLabwareDefURI } from '@opentrons/shared-data'
22
21
import { Divider } from '/app/atoms/structure'
23
22
import { getTopPortalEl } from '/app/App/portal'
24
23
import { LabwareDetails } from '/app/organisms/Desktop/Labware/LabwareDetails'
25
-
24
+ import { getRequiredLabwareDetailsFromLoadCommands } from '/app/transformations/commands'
26
25
import type { MouseEventHandler } from 'react'
27
- import type {
28
- LoadLabwareRunTimeCommand ,
29
- LoadLidStackRunTimeCommand ,
30
- LoadLidRunTimeCommand ,
31
- LabwareDefinition2 ,
32
- } from '@opentrons/shared-data'
26
+ import type { RunTimeCommand } from '@opentrons/shared-data'
33
27
import type { LabwareDefAndDate } from '/app/local-resources/labware'
34
28
35
- interface ProtocolLabwareDetailsProps {
36
- loadLabwareCommands : Array <
37
- | LoadLabwareRunTimeCommand
38
- | LoadLidStackRunTimeCommand
39
- | LoadLidRunTimeCommand
40
- > | null
41
- }
42
-
43
- export const ProtocolLabwareDetails = (
44
- props : ProtocolLabwareDetailsProps
45
- ) : JSX . Element => {
46
- const { loadLabwareCommands } = props
29
+ export const ProtocolLabwareDetails = ( props : {
30
+ commands : RunTimeCommand [ ]
31
+ } ) : JSX . Element => {
32
+ const { commands } = props
47
33
const { t } = useTranslation ( 'protocol_details' )
48
34
49
- const labwareAndLidDetails =
50
- loadLabwareCommands != null
51
- ? [
52
- ...loadLabwareCommands
53
- . reduce ( ( acc , command ) => {
54
- if ( command . result ?. definition == null ) return acc
55
- else if ( command . commandType === 'loadLid' ) return acc
56
- else if ( command . commandType === 'loadLidStack' ) {
57
- if ( ! acc . has ( getLabwareDefURI ( command . result . definition ) ) ) {
58
- acc . set ( getLabwareDefURI ( command . result . definition ) , {
59
- ...command ,
60
- quantity : 0 ,
61
- } )
62
- }
63
- acc . get (
64
- getLabwareDefURI ( command . result ?. definition )
65
- ) . quantity += command . result ?. labwareIds . length
66
- return acc
67
- } else {
68
- let defUri = getLabwareDefURI ( command . result ?. definition )
69
- const lidCommand = loadLabwareCommands . find (
70
- c =>
71
- c . commandType === 'loadLid' &&
72
- c . params . location !== 'offDeck' &&
73
- c . params . location !== 'systemLocation' &&
74
- 'labwareId' in c . params . location &&
75
- c . params . location . labwareId === command . result ?. labwareId
76
- )
77
- if (
78
- lidCommand != null &&
79
- lidCommand . result ?. definition != null
80
- ) {
81
- defUri = `${ defUri } _${ getLabwareDefURI (
82
- lidCommand . result . definition
83
- ) } `
84
-
85
- if ( ! acc . has ( defUri ) ) {
86
- acc . set ( defUri , {
87
- ...command ,
88
- quantity : 0 ,
89
- lid : lidCommand . result . definition ,
90
- } )
91
- }
92
- } else {
93
- if ( ! acc . has ( defUri ) ) {
94
- acc . set ( defUri , {
95
- ...command ,
96
- quantity : 0 ,
97
- } )
98
- }
99
- }
100
- acc . get ( defUri ) . quantity ++
101
- return acc
102
- }
103
- } , new Map ( ) )
104
- . values ( ) ,
105
- ]
106
- : [ ]
35
+ const labwareAndLidDetails = getRequiredLabwareDetailsFromLoadCommands (
36
+ commands
37
+ )
107
38
108
39
return (
109
40
< >
@@ -130,11 +61,11 @@ export const ProtocolLabwareDetails = (
130
61
{ labwareAndLidDetails ?. map ( ( labware , index ) => (
131
62
< ProtocolLabwareDetailItem
132
63
key = { index }
133
- namespace = { labware . params . namespace }
134
- displayName = { labware . result ?. definition ?. metadata ? .displayName }
64
+ namespace = { labware . labwareDef . namespace }
65
+ displayName = { labware . labwareDef . metadata . displayName }
135
66
quantity = { labware . quantity }
136
- labware = { { definition : labware . result ?. definition } }
137
- lid = { labware . lid }
67
+ labware = { { definition : labware . labwareDef } }
68
+ lidDisplayName = { labware . lidDisplayName }
138
69
data-testid = { `ProtocolLabwareDetails_item_${ index } ` }
139
70
/>
140
71
) ) }
@@ -149,16 +80,16 @@ export const ProtocolLabwareDetails = (
149
80
interface ProtocolLabwareDetailItemProps {
150
81
namespace : string
151
82
displayName : string
152
- quantity : string
153
- lid ?: LabwareDefinition2
83
+ quantity : number
84
+ lidDisplayName ?: string
154
85
labware : LabwareDefAndDate
155
86
}
156
87
157
88
export const ProtocolLabwareDetailItem = (
158
89
props : ProtocolLabwareDetailItemProps
159
90
) : JSX . Element => {
160
91
const { t } = useTranslation ( 'protocol_details' )
161
- const { namespace, displayName, quantity, labware, lid } = props
92
+ const { namespace, displayName, quantity, labware, lidDisplayName } = props
162
93
return (
163
94
< >
164
95
< Divider width = "100%" />
@@ -192,13 +123,13 @@ export const ProtocolLabwareDetailItem = (
192
123
>
193
124
{ displayName }
194
125
</ StyledText >
195
- { lid != null ? (
126
+ { lidDisplayName != null ? (
196
127
< StyledText
197
128
desktopStyle = "bodyDefaultRegular"
198
129
color = { COLORS . grey60 }
199
130
paddingRight = { SPACING . spacing32 }
200
131
>
201
- { t ( 'with_lid_name' , { lid : lid . metadata . displayName } ) }
132
+ { t ( 'with_lid_name' , { lid : lidDisplayName } ) }
202
133
</ StyledText >
203
134
) : null }
204
135
</ Flex >
0 commit comments