Skip to content

Commit b8452e2

Browse files
committed
style feedback
1 parent 48f7ca4 commit b8452e2

6 files changed

Lines changed: 147 additions & 53 deletions

File tree

protocol-designer/src/step-forms/reducers/index.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,9 +1740,15 @@ interface SaveStepFormHelperResult {
17401740
function getVacuumConcurrentPauseKind(
17411741
form: FormData | null
17421742
): null | 'profile' | 'stateDuration' {
1743-
if (form == null) return null
1744-
if (getIsVacuumProfileForm(form)) return 'profile'
1745-
if (getIsVacuumStateWithDurationForm(form)) return 'stateDuration'
1743+
if (form == null) {
1744+
return null
1745+
}
1746+
if (getIsVacuumProfileForm(form)) {
1747+
return 'profile'
1748+
}
1749+
if (getIsVacuumStateWithDurationForm(form)) {
1750+
return 'stateDuration'
1751+
}
17461752
return null
17471753
}
17481754

@@ -1779,24 +1785,24 @@ function saveStepFormHelper(
17791785

17801786
const newThermoPauseForm: PauseFormData | null =
17811787
getThermocyclerFormType(newForm) === 'thermocyclerProfile'
1782-
? getThermocyclerProfilePauseForm(
1788+
? buildThermocyclerProfilePauseForm(
17831789
newForm as ThermocyclerFormData,
17841790
action.payload.concurrentGroupPauseStepId
17851791
)
17861792
: null
17871793
const newVacVacKind = getVacuumConcurrentPauseKind(newForm)
1788-
const newVacuumPauseForm: PauseFormData | null =
1789-
newVacVacKind === 'profile'
1790-
? getVacuumProfilePauseForm(
1791-
newForm as VacuumFormData,
1792-
action.payload.concurrentGroupPauseStepId
1793-
)
1794-
: newVacVacKind === 'stateDuration'
1795-
? getVacuumStateDurationPauseForm(
1796-
newForm as VacuumFormData,
1797-
action.payload.concurrentGroupPauseStepId
1798-
)
1799-
: null
1794+
let newVacuumPauseForm: PauseFormData | null = null
1795+
if (newVacVacKind === 'profile') {
1796+
newVacuumPauseForm = buildVacuumProfilePauseForm(
1797+
newForm as VacuumFormData,
1798+
action.payload.concurrentGroupPauseStepId
1799+
)
1800+
} else if (newVacVacKind === 'stateDuration') {
1801+
newVacuumPauseForm = buildVacuumStateDurationPauseForm(
1802+
newForm as VacuumFormData,
1803+
action.payload.concurrentGroupPauseStepId
1804+
)
1805+
}
18001806
const newPauseForms = [newThermoPauseForm, newVacuumPauseForm].filter(
18011807
(f): f is PauseFormData => f != null
18021808
)
@@ -1864,19 +1870,19 @@ function saveStepFormHelper(
18641870
const newVacKind = getVacuumConcurrentPauseKind(newForm)
18651871
const newPauseForm =
18661872
newVacKind === 'profile'
1867-
? getVacuumProfilePauseForm(
1873+
? buildVacuumProfilePauseForm(
18681874
newForm as VacuumFormData,
18691875
action.payload.concurrentGroupPauseStepId
18701876
)
1871-
: getVacuumStateDurationPauseForm(
1877+
: buildVacuumStateDurationPauseForm(
18721878
newForm as VacuumFormData,
18731879
action.payload.concurrentGroupPauseStepId
18741880
)
18751881
const orderWithoutOldPauses = originalOrderedStepIds.filter(
18761882
id => id === newForm.id || !pairedToRemove.has(id)
18771883
)
1878-
const vacIdx = orderWithoutOldPauses.indexOf(newForm.id)
1879-
if (vacIdx === -1) {
1884+
const vacuumStepIndex = orderWithoutOldPauses.indexOf(newForm.id)
1885+
if (vacuumStepIndex === -1) {
18801886
console.error(
18811887
'Error rearranging steps for a vacuum concurrent pairing change. Leaving the steps unchanged.'
18821888
)
@@ -1886,9 +1892,9 @@ function saveStepFormHelper(
18861892
}
18871893
}
18881894
const newOrderedStepIds = [
1889-
...orderWithoutOldPauses.slice(0, vacIdx + 1),
1895+
...orderWithoutOldPauses.slice(0, vacuumStepIndex + 1),
18901896
newPauseForm.id,
1891-
...orderWithoutOldPauses.slice(vacIdx + 1),
1897+
...orderWithoutOldPauses.slice(vacuumStepIndex + 1),
18921898
]
18931899
return {
18941900
newOrderedStepIds,
@@ -1905,11 +1911,11 @@ function saveStepFormHelper(
19051911
const newVacKind = getVacuumConcurrentPauseKind(newForm)
19061912
const newPauseForm =
19071913
newVacKind === 'profile'
1908-
? getVacuumProfilePauseForm(
1914+
? buildVacuumProfilePauseForm(
19091915
newForm as VacuumFormData,
19101916
action.payload.concurrentGroupPauseStepId
19111917
)
1912-
: getVacuumStateDurationPauseForm(
1918+
: buildVacuumStateDurationPauseForm(
19131919
newForm as VacuumFormData,
19141920
action.payload.concurrentGroupPauseStepId
19151921
)
@@ -1947,7 +1953,7 @@ function saveStepFormHelper(
19471953
// 1) Potentially find a new position to move it to, since we can't allow Thermocycler profiles to nest.
19481954
// 2) Create a hidden "wait for profile to complete" step that it will be permanently paired with.
19491955

1950-
const newPauseForm = getThermocyclerProfilePauseForm(
1956+
const newPauseForm = buildThermocyclerProfilePauseForm(
19511957
newForm as ThermocyclerFormData,
19521958
action.payload.concurrentGroupPauseStepId
19531959
)
@@ -2001,7 +2007,7 @@ function saveStepFormHelper(
20012007
}
20022008
}
20032009

2004-
function getThermocyclerProfilePauseForm(
2010+
function buildThermocyclerProfilePauseForm(
20052011
thermocyclerForm: ThermocyclerFormData,
20062012
id: string
20072013
): PauseFormData {
@@ -2016,7 +2022,7 @@ function getThermocyclerProfilePauseForm(
20162022
}
20172023
}
20182024

2019-
function getVacuumProfilePauseForm(
2025+
function buildVacuumProfilePauseForm(
20202026
vacuumForm: VacuumFormData,
20212027
id: string
20222028
): PauseFormData {
@@ -2031,7 +2037,7 @@ function getVacuumProfilePauseForm(
20312037
}
20322038
}
20332039

2034-
function getVacuumStateDurationPauseForm(
2040+
function buildVacuumStateDurationPauseForm(
20352041
vacuumForm: VacuumFormData,
20362042
id: string
20372043
): PauseFormData {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import {
4+
VACUUM_PROGRAM_PROFILE,
5+
VACUUM_PROGRAM_STATE,
6+
} from '@opentrons/step-generation'
7+
8+
import { getIsVacuumProfileForm } from '../utils/getIsVacuumProfileForm'
9+
10+
import type { FormData } from '/protocol-designer/form-types'
11+
12+
const baseVacuumForm = {
13+
stepType: 'vacuum' as const,
14+
id: 'vacuum-step-1',
15+
moduleId: 'vacuum-module-1',
16+
programType: VACUUM_PROGRAM_PROFILE,
17+
} as const satisfies Partial<FormData>
18+
19+
describe('getIsVacuumProfileForm', () => {
20+
it('returns true for vacuum step with profile program type', () => {
21+
expect(getIsVacuumProfileForm(baseVacuumForm as FormData)).toBe(true)
22+
})
23+
24+
it('returns false when form is null', () => {
25+
expect(getIsVacuumProfileForm(null)).toBe(false)
26+
})
27+
28+
it('returns false when vacuum uses state program or step is not vacuum', () => {
29+
expect(
30+
getIsVacuumProfileForm({
31+
...baseVacuumForm,
32+
programType: VACUUM_PROGRAM_STATE,
33+
} as FormData)
34+
).toBe(false)
35+
36+
expect(
37+
getIsVacuumProfileForm({
38+
id: 'c',
39+
stepType: 'comment',
40+
} as FormData)
41+
).toBe(false)
42+
})
43+
})
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import {
4+
VACUUM_PROGRAM_PROFILE,
5+
VACUUM_PROGRAM_STATE,
6+
} from '@opentrons/step-generation'
7+
8+
import { getIsVacuumStateWithDurationForm } from '../utils/getIsVacuumStateWithDurationForm'
9+
10+
import type { FormData } from '/protocol-designer/form-types'
11+
12+
const baseVacuumForm = {
13+
stepType: 'vacuum' as const,
14+
id: 'vacuum-step-1',
15+
moduleId: 'vacuum-module-1',
16+
programType: VACUUM_PROGRAM_STATE,
17+
pumpDurationCheckbox: true,
18+
pumpDurationTime: '00:01:00',
19+
} as const satisfies Partial<FormData>
20+
21+
describe('getIsVacuumStateWithDurationForm', () => {
22+
it('returns true for vacuum state program with pump duration enabled and a time set', () => {
23+
expect(getIsVacuumStateWithDurationForm(baseVacuumForm as FormData)).toBe(
24+
true
25+
)
26+
})
27+
28+
it('returns false when form is null', () => {
29+
expect(getIsVacuumStateWithDurationForm(null)).toBe(false)
30+
})
31+
32+
it('returns false when not vacuum state with duration (wrong program or duration off)', () => {
33+
expect(
34+
getIsVacuumStateWithDurationForm({
35+
...baseVacuumForm,
36+
programType: VACUUM_PROGRAM_PROFILE,
37+
} as FormData)
38+
).toBe(false)
39+
40+
expect(
41+
getIsVacuumStateWithDurationForm({
42+
...baseVacuumForm,
43+
pumpDurationCheckbox: false,
44+
} as FormData)
45+
).toBe(false)
46+
47+
expect(
48+
getIsVacuumStateWithDurationForm({
49+
...baseVacuumForm,
50+
pumpDurationTime: null,
51+
} as FormData)
52+
).toBe(false)
53+
})
54+
})

protocol-designer/src/step-forms/utils/getIsVacuumStateWithDurationForm.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import type { FormData } from '/protocol-designer/form-types'
99
export function getIsVacuumStateWithDurationForm(
1010
formData: FormData | null
1111
): boolean {
12-
if (formData?.stepType !== 'vacuum') return false
13-
if (formData.programType !== VACUUM_PROGRAM_STATE) return false
12+
if (formData?.stepType !== 'vacuum') {
13+
return false
14+
}
15+
if (formData.programType !== VACUUM_PROGRAM_STATE) {
16+
return false
17+
}
1418
return (
1519
formData.pumpDurationCheckbox === true && formData.pumpDurationTime != null
1620
)

protocol-designer/src/steplist/utils/stepHierarchy.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,8 @@ export type ConcurrentGroup =
7979
export function isConcurrentGroup(
8080
item: StandaloneStep | ConcurrentGroup
8181
): item is ConcurrentGroup {
82-
return (
83-
item.type === 'thermocyclerProfileGroup' ||
84-
item.type === 'vacuumProfileGroup' ||
85-
item.type === 'vacuumStateDurationGroup'
86-
)
82+
return item.type !== 'standaloneStep'
8783
}
88-
8984
function isVacuumStateWithPumpDuration(step: FormData): boolean {
9085
return (
9186
step.stepType === 'vacuum' &&
@@ -95,23 +90,16 @@ function isVacuumStateWithPumpDuration(step: FormData): boolean {
9590
)
9691
}
9792

98-
type OpenConcurrentGroup =
99-
| {
100-
kind: 'thermocycler'
101-
startId: StepIdType
102-
concurrentStepIds: StepIdType[]
103-
}
104-
| {
105-
kind: 'vacuumProfile'
106-
startId: StepIdType
107-
concurrentStepIds: StepIdType[]
108-
}
109-
| {
110-
kind: 'vacuumStateDuration'
111-
startId: StepIdType
112-
concurrentStepIds: StepIdType[]
113-
}
93+
type OpenConcurrentGroupKind =
94+
| 'thermocycler'
95+
| 'vacuumProfile'
96+
| 'vacuumStateDuration'
11497

98+
interface OpenConcurrentGroup {
99+
kind: OpenConcurrentGroupKind
100+
startId: StepIdType
101+
concurrentStepIds: StepIdType[]
102+
}
115103
/**
116104
* Given a flat array of steps, return the equivalent hierarchy.
117105
*/

step-generation/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,6 @@ export interface VacuumStopPumpArgs extends CommonArgs {
825825
commandCreatorFnName: 'vacuumStopPump'
826826
}
827827

828-
// Vacuum
829828
export interface VacuumPressureData {
830829
mode: typeof VACUUM_MODE_PRESSURE
831830
pressureMbar: string | null

0 commit comments

Comments
 (0)