Skip to content

Commit 729ea85

Browse files
fix(protocol-designer): Fix some possible type bugs in the lastSelected state (#20124)
1 parent 3a0a6dc commit 729ea85

File tree

5 files changed

+41
-42
lines changed

5 files changed

+41
-42
lines changed

protocol-designer/src/ui/steps/actions/actions.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,22 +281,24 @@ export const selectAllSteps =
281281
getState: GetState
282282
) => {
283283
const allStepIds = stepFormSelectors.getOrderedStepIds(getState())
284-
const selectStepAction: SelectMultipleStepsAction = {
285-
type: 'SELECT_MULTIPLE_STEPS',
286-
payload: {
287-
stepIds: allStepIds,
288-
// @ts-expect-error(sa, 2021-6-15): find could return undefined, need to null check PipetteSpecsV2
289-
lastSelected: last(allStepIds),
290-
},
291-
}
292-
dispatch(selectStepAction)
293-
// dispatch an analytics event to indicate all steps have been selected
294-
// because there is no 'SELECT_ALL_STEPS' action that middleware can catch
295-
const selectAllStepsEvent: AnalyticsEvent = {
296-
name: SELECT_ALL_STEPS_EVENT,
297-
properties: {},
284+
if (allStepIds.length > 0) {
285+
const lastStepId = last(allStepIds)!
286+
const selectStepAction: SelectMultipleStepsAction = {
287+
type: 'SELECT_MULTIPLE_STEPS',
288+
payload: {
289+
stepIds: allStepIds,
290+
lastSelected: lastStepId,
291+
},
292+
}
293+
dispatch(selectStepAction)
294+
// dispatch an analytics event to indicate all steps have been selected
295+
// because there is no 'SELECT_ALL_STEPS' action that middleware can catch
296+
const selectAllStepsEvent: AnalyticsEvent = {
297+
name: SELECT_ALL_STEPS_EVENT,
298+
properties: {},
299+
}
300+
dispatch(analyticsEvent(selectAllStepsEvent))
298301
}
299-
dispatch(analyticsEvent(selectAllStepsEvent))
300302
}
301303
export const EXIT_BATCH_EDIT_MODE_BUTTON_PRESS: 'EXIT_BATCH_EDIT_MODE_BUTTON_PRESS' =
302304
'EXIT_BATCH_EDIT_MODE_BUTTON_PRESS'

protocol-designer/src/ui/steps/actions/thunks/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ export const duplicateMultipleSteps: (
231231
stepIds => (dispatch, getState) => {
232232
const orderedStepIds = getOrderedStepIds(getState())
233233
const lastSelectedItemId = getMultiSelectLastSelected(getState())
234-
// @ts-expect-error(sa, 2021-6-15): lastSelectedItemId might be null, which you cannot pass to indexOf
235-
const indexOfLastSelected = orderedStepIds.indexOf(lastSelectedItemId)
234+
const indexOfLastSelected = orderedStepIds.indexOf(lastSelectedItemId!)
236235
stepIds.sort(
237236
(a, b) => orderedStepIds.indexOf(a) - orderedStepIds.indexOf(b)
238237
)
@@ -254,8 +253,7 @@ export const duplicateMultipleSteps: (
254253
type: 'SELECT_MULTIPLE_STEPS',
255254
payload: {
256255
stepIds: duplicateIds,
257-
// @ts-expect-error(sa, 2021-6-15): last might return undefined
258-
lastSelected: last(duplicateIds),
256+
lastSelected: last(duplicateIds)!,
259257
},
260258
}
261259
dispatch(duplicateMultipleStepsAction)

step-generation/src/__tests__/thermocyclerUpdates.test.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222

2323
import type {
2424
ModuleOnlyParams,
25+
TCProfileParams,
2526
TemperatureParams,
2627
ThermocyclerSetTargetBlockTemperatureParams,
2728
} from '@opentrons/shared-data/protocol/types/schemaV6/command/module'
@@ -216,12 +217,12 @@ describe('thermocycler state updaters', () => {
216217
testName: 'forThermocyclerOpenLid should set lidOpen to true',
217218
},
218219
]
219-
const profileCases: TestCases<any> = [
220+
const profileCases: TestCases<TCProfileParams> = [
220221
{
221222
params: {
222223
moduleId,
223224
profile: [],
224-
volume: 10,
225+
blockMaxVolumeUl: 10,
225226
},
226227
moduleStateBefore: {},
227228
expectedUpdate: {},
@@ -233,19 +234,19 @@ describe('thermocycler state updaters', () => {
233234
moduleId,
234235
profile: [
235236
{
236-
holdTime: 10,
237-
temperature: 50,
237+
holdSeconds: 10,
238+
celsius: 50,
238239
},
239240
{
240-
holdTime: 10,
241-
temperature: 30,
241+
holdSeconds: 10,
242+
celsius: 30,
242243
},
243244
{
244-
holdTime: 10,
245-
temperature: 0,
245+
holdSeconds: 10,
246+
celsius: 0,
246247
},
247248
],
248-
volume: 10,
249+
blockMaxVolumeUl: 10,
249250
},
250251
moduleStateBefore: {
251252
blockTargetTemp: 42,
@@ -261,19 +262,19 @@ describe('thermocycler state updaters', () => {
261262
moduleId,
262263
profile: [
263264
{
264-
holdTime: 10,
265-
temperature: 0,
265+
holdSeconds: 10,
266+
celsius: 0,
266267
},
267268
{
268-
holdTime: 10,
269-
temperature: 50,
269+
holdSeconds: 10,
270+
celsius: 50,
270271
},
271272
{
272-
holdTime: 10,
273-
temperature: 20,
273+
holdSeconds: 10,
274+
celsius: 20,
274275
},
275276
],
276-
volume: 10,
277+
blockMaxVolumeUl: 10,
277278
},
278279
moduleStateBefore: {
279280
blockTargetTemp: 42,
@@ -289,11 +290,11 @@ describe('thermocycler state updaters', () => {
289290
moduleId,
290291
profile: [
291292
{
292-
holdTime: 10,
293-
temperature: 30,
293+
holdSeconds: 10,
294+
celsius: 30,
294295
},
295296
],
296-
volume: 10,
297+
blockMaxVolumeUl: 10,
297298
},
298299
moduleStateBefore: {
299300
blockTargetTemp: 42,

step-generation/src/getNextRobotStateAndWarnings/thermocyclerUpdates.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ export const forThermocyclerRunProfile = (
139139
const moduleState = _getThermocyclerModuleState(robotState, moduleId)
140140

141141
if (profile.length > 0) {
142-
// @ts-expect-error (sa, 2021-05-03): last might return undefined
143-
moduleState.blockTargetTemp = last(profile).temperature
142+
moduleState.blockTargetTemp = last(profile)!.celsius
144143
}
145144
}

step-generation/src/utils/commandCreatorsTimeline.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export const commandCreatorsTimeline = (
2121
const prevRobotState =
2222
acc.timeline.length === 0
2323
? initialRobotState
24-
: // @ts-expect-error(SA, 2021-05-03): last might return undefined
25-
last(acc.timeline).robotState
24+
: last(acc.timeline)!.robotState
2625

2726
if (acc.errors != null) {
2827
// error short-circuit

0 commit comments

Comments
 (0)