Skip to content

Commit

Permalink
fix(protocol-designer): make 8_2_2 migration to migrate HS set timer … (
Browse files Browse the repository at this point in the history
#17124)

…field

The `heaterShakerSetTimer` field's type is `heaterShakerSetTimer: 'true'
| 'false' | null` - this was written 3 years ago. However, despite this,
the field when checking the checkbox in the form in PD would populate it
as `true` or `false` booleans rather than the true/false strings.

2 weeks ago, right before 8.2.0 was released, there was a bug checking
the timer checkbox for the temperature module and it was because of this
boolean vs boolean strings issue. So I extended it onto the
heater-shaker set timer field as well because of its type. Unfortunately, that resulted in this
current error:

- protocols created in 8.2.0 and 8.2.1 have the `heaterShakerSetTimer`
field set to either `'true'` or `'false'` strings
- protocols created prior to 8.2.0 have the `heaterShakerSetTimer` field
set to `true` or `false` boolean
- my initial fix was to update the form field to check for `true` or `false` boolean but
that didn't fix any protocols created in 8.2.0 and 8.2.1.
- the extended fix unfortunately required a migration so now if `'true'`
or `'false'` strings are used in the field, they get migrated to `true`
or `false` boolean -- this i believe is the only way to fix all protocol
versions
  • Loading branch information
jerader authored Dec 17, 2024
1 parent e236cb6 commit 4bb6a9c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion protocol-designer/fixtures/protocol/8/doItAllV8.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"designerApplication": {
"name": "opentrons/protocol-designer",
"version": "8.2.0",
"version": "8.2.2",
"data": {
"_internalAppBuildDate": "Mon, 11 Nov 2024 20:18:16 GMT",
"defaultValues": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"designerApplication": {
"name": "opentrons/protocol-designer",
"version": "8.2.0",
"version": "8.2.2",
"data": {
"_internalAppBuildDate": "Mon, 11 Nov 2024 20:10:44 GMT",
"defaultValues": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"designerApplication": {
"name": "opentrons/protocol-designer",
"version": "8.2.0",
"version": "8.2.2",
"data": {
"_internalAppBuildDate": "Wed, 01 May 2024 13:32:34 GMT",
"defaultValues": {
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/src/form-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export interface HydratedTemperatureFormData {
targetTemperature: string | null
}
export interface HydratedHeaterShakerFormData {
heaterShakerSetTimer: 'true' | 'false' | null
heaterShakerSetTimer: boolean | null
heaterShakerTimer: string | null
id: string
latchOpen: boolean
Expand Down
51 changes: 51 additions & 0 deletions protocol-designer/src/load-file/migration/8_2_2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { ProtocolFile } from '@opentrons/shared-data'
import type { DesignerApplicationData } from './utils/getLoadLiquidCommands'

export const migrateFile = (
appData: ProtocolFile<DesignerApplicationData>
): ProtocolFile<DesignerApplicationData> => {
const { designerApplication } = appData

if (designerApplication == null || designerApplication?.data == null) {
throw Error('The designerApplication key in your file is corrupt.')
}
const savedStepForms = designerApplication.data
?.savedStepForms as DesignerApplicationData['savedStepForms']

const savedStepsWithUpdatedHeaterShakerTimerField = Object.values(
savedStepForms
).reduce((acc, form) => {
if (form.stepType === 'heaterShaker') {
const { id, heaterShakerSetTimer } = form
let newSetTimer = heaterShakerSetTimer

if (heaterShakerSetTimer === 'false') {
newSetTimer = false
} else if (heaterShakerSetTimer === 'true') {
newSetTimer = true
}
return {
...acc,
[id]: {
...form,
heaterShakerSetTimer: newSetTimer,
},
}
}
return acc
}, {})

return {
...appData,
designerApplication: {
...designerApplication,
data: {
...designerApplication.data,
savedStepForms: {
...designerApplication.data.savedStepForms,
...savedStepsWithUpdatedHeaterShakerTimerField,
},
},
},
}
}
4 changes: 4 additions & 0 deletions protocol-designer/src/load-file/migration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { migrateFile as migrateFileSeven } from './7_0_0'
import { migrateFile as migrateFileEight } from './8_0_0'
import { migrateFile as migrateFileEightOne } from './8_1_0'
import { migrateFile as migrateFileEightTwo } from './8_2_0'
import { migrateFile as migrateFileEightTwoPointTwo } from './8_2_2'

import type { PDProtocolFile } from '../../file-types'

export const OLDEST_MIGRATEABLE_VERSION = '1.0.0'
Expand Down Expand Up @@ -54,6 +56,8 @@ const allMigrationsByVersion: MigrationsByVersion = {
'8.1.0': migrateFileEightOne,
// @ts-expect-error
'8.2.0': migrateFileEightTwo,
// @ts-expect-error
'8.2.2': migrateFileEightTwoPointTwo,
}
export const migration = (
file: any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('heaterShakerFormToArgs', () => {
id: 'id',
stepDetails: 'step details',
moduleId: 'moduleId',
heaterShakerSetTimer: 'true',
heaterShakerSetTimer: true,
setHeaterShakerTemperature: true,
setShake: true,
latchOpen: false,
Expand All @@ -35,7 +35,7 @@ describe('heaterShakerFormToArgs', () => {
id: 'id',
stepDetails: 'step details',
moduleId: 'moduleId',
heaterShakerSetTimer: 'false',
heaterShakerSetTimer: false,
setHeaterShakerTemperature: true,
setShake: false,
latchOpen: false,
Expand Down

0 comments on commit 4bb6a9c

Please sign in to comment.