Skip to content

Commit

Permalink
refactor to remove cloneElement
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Nov 1, 2024
1 parent b277cae commit 88122b0
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions components/src/hardware-sim/Deck/DeckFromLayers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { cloneElement } from 'react'
import { OT2_ROBOT_TYPE } from '@opentrons/shared-data'
import {
FixedBase,
Expand All @@ -12,28 +11,28 @@ import {
RemovalHandle,
ScrewHoles,
} from './OT2Layers'
import { ALL_OT2_DECK_LAYERS } from './constants'

import type { RobotType } from '@opentrons/shared-data'
import { ALL_OT2_DECK_LAYERS } from './constants'

export interface DeckFromLayersProps {
robotType: RobotType
layerBlocklist: string[]
}

const OT2_LAYER_MAP: {
[layer in typeof ALL_OT2_DECK_LAYERS[number]]: JSX.Element
[layer in typeof ALL_OT2_DECK_LAYERS[number]]: () => JSX.Element
} = {
fixedBase: <FixedBase />,
fixedTrash: <FixedTrash />,
doorStops: <DoorStops />,
metalFrame: <MetalFrame />,
removableDeckOutline: <RemovableDeckOutline />,
slotRidges: <SlotRidges />,
slotNumbers: <SlotNumbers />,
calibrationMarkings: <CalibrationMarkings />,
removalHandle: <RemovalHandle />,
screwHoles: <ScrewHoles />,
fixedBase: () => <FixedBase />,
fixedTrash: () => <FixedTrash />,
doorStops: () => <DoorStops />,
metalFrame: () => <MetalFrame />,
removableDeckOutline: () => <RemovableDeckOutline />,
slotRidges: () => <SlotRidges />,
slotNumbers: () => <SlotNumbers />,
calibrationMarkings: () => <CalibrationMarkings />,
removalHandle: () => <RemovalHandle />,
screwHoles: () => <ScrewHoles />,
}

/**
Expand All @@ -48,10 +47,12 @@ export function DeckFromLayers(props: DeckFromLayersProps): JSX.Element | null {

return (
<g id="deckLayers">
{ALL_OT2_DECK_LAYERS.reduce<JSX.Element[]>((acc, layer) => {
if (layerBlocklist.includes(layer)) return acc
return [...acc, cloneElement(OT2_LAYER_MAP[layer], { key: layer })]
}, [])}
{ALL_OT2_DECK_LAYERS.filter(layer => !layerBlocklist.includes(layer)).map(
layer => {
const LayerComponent = OT2_LAYER_MAP[layer]
return <LayerComponent key={layer} />
}
)}
</g>
)
}

0 comments on commit 88122b0

Please sign in to comment.