Skip to content

Commit 1d30e93

Browse files
authored
feat(protocol-designer): stepForm skeleton (#16284)
closes AUTH-828
1 parent 0b3a345 commit 1d30e93

File tree

16 files changed

+740
-5
lines changed

16 files changed

+740
-5
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import * as React from 'react'
2+
import get from 'lodash/get'
3+
import { useTranslation } from 'react-i18next'
4+
5+
import {
6+
ALIGN_CENTER,
7+
Flex,
8+
Icon,
9+
PrimaryButton,
10+
SPACING,
11+
StyledText,
12+
Toolbox,
13+
} from '@opentrons/components'
14+
import { stepIconsByType } from '../../../../form-types'
15+
import {
16+
CommentTools,
17+
HeaterShakerTools,
18+
MagnetTools,
19+
MixTools,
20+
MoveLabwareTools,
21+
MoveLiquidTools,
22+
PauseTools,
23+
TemperatureTools,
24+
ThermocyclerTools,
25+
} from './StepTools'
26+
import type { StepFieldName } from '../../../../steplist/fieldLevel'
27+
import type { FormData, StepType } from '../../../../form-types'
28+
import type { FieldPropsByName, FocusHandlers, StepFormProps } from './types'
29+
30+
type StepFormMap = {
31+
[K in StepType]?: React.ComponentType<StepFormProps> | null
32+
}
33+
34+
const STEP_FORM_MAP: StepFormMap = {
35+
mix: MixTools,
36+
pause: PauseTools,
37+
moveLabware: MoveLabwareTools,
38+
moveLiquid: MoveLiquidTools,
39+
magnet: MagnetTools,
40+
temperature: TemperatureTools,
41+
thermocycler: ThermocyclerTools,
42+
heaterShaker: HeaterShakerTools,
43+
comment: CommentTools,
44+
}
45+
46+
interface StepFormToolboxProps {
47+
canSave: boolean
48+
dirtyFields: string[]
49+
focusHandlers: FocusHandlers
50+
focusedField: StepFieldName | null
51+
formData: FormData
52+
propsForFields: FieldPropsByName
53+
handleClose: () => void
54+
// TODO: add abiltiy to delete step?
55+
handleDelete: () => void
56+
handleSave: () => void
57+
}
58+
59+
export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
60+
const {
61+
formData,
62+
focusHandlers,
63+
canSave,
64+
handleClose,
65+
handleSave,
66+
propsForFields,
67+
} = props
68+
const { t, i18n } = useTranslation(['application', 'shared'])
69+
const icon = stepIconsByType[formData.stepType]
70+
71+
const Tools: typeof STEP_FORM_MAP[keyof typeof STEP_FORM_MAP] = get(
72+
STEP_FORM_MAP,
73+
formData.stepType
74+
)
75+
76+
if (!Tools) {
77+
// early-exit if step form doesn't exist, this is a good check for when new steps
78+
// are added
79+
return (
80+
<div>
81+
<div>Todo: support {formData && formData.stepType} step</div>
82+
</div>
83+
)
84+
}
85+
86+
return (
87+
<>
88+
{/* TODO: update alerts */}
89+
{/* <Alerts
90+
focusedField={focusedField}
91+
dirtyFields={dirtyFields}
92+
componentType="Form"
93+
/> */}
94+
95+
<Toolbox
96+
onCloseClick={handleClose}
97+
closeButtonText={t('shared:cancel')}
98+
confirmButton={
99+
<PrimaryButton onClick={handleSave} disabled={!canSave} width="100%">
100+
{t('shared:save')}
101+
</PrimaryButton>
102+
}
103+
height="calc(100vh - 64px)"
104+
title={
105+
<Flex gridGap={SPACING.spacing8} alignItems={ALIGN_CENTER}>
106+
<Icon size="1rem" name={icon} />
107+
<StyledText desktopStyle="bodyLargeSemiBold">
108+
{i18n.format(t(`stepType.${formData.stepType}`), 'capitalize')}
109+
</StyledText>
110+
</Flex>
111+
}
112+
>
113+
<Tools {...{ formData, propsForFields, focusHandlers }} />
114+
</Toolbox>
115+
</>
116+
)
117+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as React from 'react'
2+
3+
export function CommentTools(): JSX.Element {
4+
return <div>TODO: wire this up</div>
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as React from 'react'
2+
3+
export function HeaterShakerTools(): JSX.Element {
4+
return <div>TODO: wire this up</div>
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as React from 'react'
2+
3+
export function MagnetTools(): JSX.Element {
4+
return <div>TODO: wire this up</div>
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as React from 'react'
2+
3+
export function MixTools(): JSX.Element {
4+
return <div>TODO: wire this up</div>
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as React from 'react'
2+
3+
export function MoveLabwareTools(): JSX.Element {
4+
return <div>TODO: wire this up</div>
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as React from 'react'
2+
3+
export function MoveLiquidTools(): JSX.Element {
4+
return <div>TODO: wire this up</div>
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as React from 'react'
2+
3+
export function PauseTools(): JSX.Element {
4+
return <div>TODO: wire this up</div>
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as React from 'react'
2+
3+
export function TemperatureTools(): JSX.Element {
4+
return <div>TODO: wire this up</div>
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as React from 'react'
2+
3+
export function ThermocyclerTools(): JSX.Element {
4+
return <div>TODO: wire this up</div>
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export { CommentTools } from './CommentTools'
2+
export { HeaterShakerTools } from './HeaterShakerTools'
3+
export { MagnetTools } from './MagnetTools'
4+
export { MixTools } from './MixTools'
5+
export { MoveLabwareTools } from './MoveLabwareTools'
6+
export { MoveLiquidTools } from './MoveLiquidTools'
7+
export { PauseTools } from './PauseTools'
8+
export { TemperatureTools } from './TemperatureTools'
9+
export { ThermocyclerTools } from './ThermocyclerTools'

0 commit comments

Comments
 (0)