Skip to content

Commit

Permalink
clean up LabwareSelectionModal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Oct 18, 2023
1 parent be731ef commit c2a8c9d
Showing 1 changed file with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const LabwareSelectionModal = (props: Props): JSX.Element | null => {
has96Channel,
} = props
const defs = getOnlyLatestDefs()
const URIs = Object.keys(defs)
const [selectedCategory, setSelectedCategory] = React.useState<string | null>(
null
)
Expand Down Expand Up @@ -233,6 +234,21 @@ export const LabwareSelectionModal = (props: Props): JSX.Element | null => {
return `Slot ${slot} Labware`
}

const getLabwareAdapterItem = (index: number, labwareDefUri?: string) => {

Check failure on line 237 in protocol-designer/src/components/LabwareSelectionModal/LabwareSelectionModal.tsx

View workflow job for this annotation

GitHub Actions / js checks

Missing return type on function

Check failure on line 237 in protocol-designer/src/components/LabwareSelectionModal/LabwareSelectionModal.tsx

View workflow job for this annotation

GitHub Actions / js checks

Missing return type on function
const labwareDef = labwareDefUri != null ? defs[labwareDefUri] : null
return labwareDef != null ? (
<LabwareItem
key={`${labwareDef.parameters.loadName}_${index}`}
icon="check-decagram"
labwareDef={labwareDef}
selectLabware={selectLabware}
onMouseEnter={() => setPreviewedLabware(labwareDef)}
// @ts-expect-error(sa, 2021-6-22): setPreviewedLabware expects an argument (even if nullsy)
onMouseLeave={() => setPreviewedLabware()}
/>
) : null
}

const customLabwareURIs: string[] = React.useMemo(
() => Object.keys(customLabwareDefs),
[customLabwareDefs]
Expand Down Expand Up @@ -347,6 +363,7 @@ export const LabwareSelectionModal = (props: Props): JSX.Element | null => {
moduleCompatibility = 'notCompatible'
}
}

return (
<>
<Portal>
Expand Down Expand Up @@ -432,31 +449,19 @@ export const LabwareSelectionModal = (props: Props): JSX.Element | null => {
onClick={makeToggleCategory(adapterCompatibleLabware)}
inert={false}
>
{has96Channel
? permittedTipracks
{has96Channel && adapterLoadName === ADAPTER_96_CHANNEL
? permittedTipracks.map((tiprackDefUri, index) => {
const labwareDefUri = URIs.find(
defUri => defUri === tiprackDefUri
)
return getLabwareAdapterItem(index, labwareDefUri)
})
: getLabwareCompatibleWithAdapter(adapterLoadName).map(
(adapterDefUri, index) => {
const latestDefs = getOnlyLatestDefs()

const URIs = Object.keys(latestDefs)
const labwareDefUri = URIs.find(
defUri => defUri === adapterDefUri
)
const labwareDef = labwareDefUri
? latestDefs[labwareDefUri]
: null

return labwareDef != null ? (
<LabwareItem
key={index}
icon="check-decagram"
labwareDef={labwareDef}
selectLabware={selectLabware}
onMouseEnter={() => setPreviewedLabware(labwareDef)}
// @ts-expect-error(sa, 2021-6-22): setPreviewedLabware expects an argument (even if nullsy)
onMouseLeave={() => setPreviewedLabware()}
/>
) : null
return getLabwareAdapterItem(index, labwareDefUri)
}
)}
</PDTitledList>
Expand Down

0 comments on commit c2a8c9d

Please sign in to comment.