-
Notifications
You must be signed in to change notification settings - Fork 175
/
URLDeck.tsx
134 lines (121 loc) · 3.99 KB
/
URLDeck.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import * as React from 'react'
import styles from './URLDeck.css'
import {
RobotWorkSpace,
LabwareNameOverlay,
LabwareRender,
ModuleItem,
RobotCoordsForeignDiv,
} from '@opentrons/components'
import { getLatestLabwareDef } from './getLabware'
import { getDeckDefinitions } from '@opentrons/components/src/hardware-sim/Deck/getDeckDefinitions'
import type { ModuleModel, DeckSlotId } from '@opentrons/shared-data'
// URI-encoded JSON expected as URL param "data" (eg `?data=...`)
interface UrlData {
labware: Record<
DeckSlotId,
{
labwareType: string
name: string | null | undefined
}
>
modules: Record<DeckSlotId, ModuleModel>
}
const DECK_DEF = getDeckDefinitions().ot2_standard
const DECK_LAYER_BLOCKLIST = [
'calibrationMarkings',
'fixedBase',
'doorStops',
'metalFrame',
'removalHandle',
'removableDeckOutline',
'screwHoles',
]
function getDataFromUrl(): UrlData | null {
try {
const urlData = new URLSearchParams(window.location.search).get('data')
if (!urlData) {
console.error('No "data" param in URL')
return null
}
return JSON.parse(urlData)
} catch (e) {
console.error('Failed to parse "data" URL param.', e)
return null
}
}
export class URLDeck extends React.Component<{}> {
urlData: UrlData | null
constructor() {
// @ts-expect-error(sa, 2021-7-8): call super with props
super()
this.urlData = getDataFromUrl()
}
render(): JSX.Element {
const labwareBySlot = this.urlData?.labware
const modulesBySlot = this.urlData?.modules
return (
<RobotWorkSpace
deckDef={DECK_DEF}
deckLayerBlocklist={DECK_LAYER_BLOCKLIST}
viewBox={`-35 -35 ${488} ${390}`} // TODO: put these in variables
margin="0 4rem"
>
{({ deckSlotsById }): Array<JSX.Element | null> =>
Object.keys(deckSlotsById).map((slotId): JSX.Element | null => {
const slot = deckSlotsById[slotId]
if (!slot.matingSurfaceUnitVector) return null // if slot has no mating surface, don't render anything in it
const moduleModel = modulesBySlot && modulesBySlot[slotId]
const labware = labwareBySlot && labwareBySlot[slotId]
const labwareDefV2 =
labware && getLatestLabwareDef(labware.labwareType)
let labwareDisplayType: string | null = null
if (labwareDefV2) {
labwareDisplayType = labwareDefV2.metadata.displayName
} else {
labwareDisplayType = labware?.labwareType || null
}
return (
<React.Fragment key={slotId}>
{moduleModel && (
<g
transform={`translate(${slot.position[0]}, ${slot.position[1]})`}
>
<ModuleItem
model={moduleModel}
mode={'default'}
slot={slot}
/>
</g>
)}
{labware && (
<g
transform={`translate(${slot.position[0]}, ${slot.position[1]})`}
>
{labwareDefV2 ? (
<LabwareRender definition={labwareDefV2} />
) : null}
</g>
)}
{labware && (
<RobotCoordsForeignDiv
x={slot.position[0]}
y={slot.position[1]}
width={slot.boundingBox.xDimension}
height={slot.boundingBox.yDimension}
>
<LabwareNameOverlay
className={styles.labware_name_overlay}
title={labware.name || labwareDisplayType || ''}
subtitle={labware.name ? labwareDisplayType : null}
/>
</RobotCoordsForeignDiv>
)}
</React.Fragment>
)
})
}
</RobotWorkSpace>
)
}
}