-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol-designer): Implement presaved step form for TC state (#…
- Loading branch information
Showing
9 changed files
with
281 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
...ist/formLevel/getNextDefaultModuleId/__tests__/getNextDefaultThermocyclerModuleId.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
// @flow | ||
import { | ||
MAGNETIC_MODULE_TYPE, | ||
TEMPERATURE_MODULE_TYPE, | ||
THERMOCYCLER_MODULE_TYPE, | ||
MAGNETIC_MODULE_V1, | ||
TEMPERATURE_MODULE_V1, | ||
THERMOCYCLER_MODULE_V1, | ||
} from '@opentrons/shared-data' | ||
import { TEMPERATURE_DEACTIVATED } from '../../../../constants' | ||
import { getNextDefaultThermocyclerModuleId } from '../getNextDefaultThermocyclerModuleId' | ||
|
||
const getThermocycler = () => ({ | ||
id: 'tcId', | ||
type: THERMOCYCLER_MODULE_TYPE, | ||
model: THERMOCYCLER_MODULE_V1, | ||
slot: '_span781011', | ||
moduleState: { | ||
type: THERMOCYCLER_MODULE_TYPE, | ||
blockTargetTemp: null, | ||
lidTargetTemp: null, | ||
lidOpen: null, | ||
}, | ||
}) | ||
|
||
const getMag = () => ({ | ||
id: 'magId', | ||
type: MAGNETIC_MODULE_TYPE, | ||
model: MAGNETIC_MODULE_V1, | ||
slot: '_span781011', | ||
moduleState: { type: MAGNETIC_MODULE_TYPE, engaged: false }, | ||
}) | ||
|
||
const getTemp = () => ({ | ||
id: 'tempId', | ||
type: TEMPERATURE_MODULE_TYPE, | ||
model: TEMPERATURE_MODULE_V1, | ||
slot: '3', | ||
moduleState: { | ||
type: TEMPERATURE_MODULE_TYPE, | ||
status: TEMPERATURE_DEACTIVATED, | ||
targetTemperature: null, | ||
}, | ||
}) | ||
|
||
describe('getNextDefaultThermocyclerModuleId', () => { | ||
describe('NO previous forms', () => { | ||
const testCases = [ | ||
{ | ||
testMsg: 'temp and TC module present: use TC', | ||
equippedModulesById: { | ||
tempId: getTemp(), | ||
tcId: getThermocycler(), | ||
}, | ||
expected: 'tcId', | ||
}, | ||
{ | ||
testMsg: 'only TC module present: use TC', | ||
equippedModulesById: { | ||
tcId: getThermocycler(), | ||
}, | ||
expected: 'tcId', | ||
}, | ||
|
||
{ | ||
testMsg: 'only mag module present: return null', | ||
equippedModulesById: { | ||
magId: getMag(), | ||
}, | ||
expected: null, | ||
}, | ||
] | ||
|
||
testCases.forEach(({ testMsg, equippedModulesById, expected }) => { | ||
it(testMsg, () => { | ||
const savedForms = {} | ||
const orderedStepIds = [] | ||
|
||
const result = getNextDefaultThermocyclerModuleId( | ||
savedForms, | ||
orderedStepIds, | ||
equippedModulesById | ||
) | ||
|
||
expect(result).toBe(expected) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('previous forms', () => { | ||
const testCases = [ | ||
{ | ||
testMsg: 'temp and tc present, last step was tc: use tc mod', | ||
equippedModulesById: { | ||
tempId: getTemp(), | ||
tcId: getThermocycler(), | ||
}, | ||
savedForms: { | ||
tempStepId: { | ||
id: 'tempStepId', | ||
stepType: 'temperature', | ||
stepName: 'temperature', | ||
moduleId: 'tempId', | ||
}, | ||
tcStepId: { | ||
id: 'tcStepId', | ||
stepType: THERMOCYCLER_MODULE_TYPE, | ||
stepName: THERMOCYCLER_MODULE_TYPE, | ||
moduleId: 'tcId', | ||
}, | ||
}, | ||
orderedStepIds: ['tempStepId', 'tcStepId'], | ||
expected: 'tcId', | ||
}, | ||
{ | ||
testMsg: 'temp and mag present return null', | ||
equippedModulesById: { | ||
magId: { | ||
id: 'magId', | ||
type: MAGNETIC_MODULE_TYPE, | ||
model: MAGNETIC_MODULE_V1, | ||
slot: '_span781011', | ||
moduleState: { type: MAGNETIC_MODULE_TYPE, engaged: false }, | ||
}, | ||
tempId: { | ||
id: 'tempId', | ||
type: TEMPERATURE_MODULE_TYPE, | ||
model: TEMPERATURE_MODULE_V1, | ||
slot: '3', | ||
moduleState: { | ||
type: TEMPERATURE_MODULE_TYPE, | ||
status: TEMPERATURE_DEACTIVATED, | ||
targetTemperature: null, | ||
}, | ||
}, | ||
}, | ||
savedForms: { | ||
tempStepId: { | ||
id: 'tempStepId', | ||
stepType: 'temperature', | ||
stepName: 'temperature', | ||
moduleId: 'tempId', | ||
}, | ||
magStepId: { | ||
id: 'magStepId', | ||
stepType: 'magnet', | ||
stepName: 'magnet', | ||
moduleId: 'magdeckId', | ||
}, | ||
}, | ||
orderedStepIds: ['tempStepId', 'magStepId'], | ||
expected: null, | ||
}, | ||
] | ||
|
||
testCases.forEach( | ||
({ | ||
testMsg, | ||
savedForms = {}, | ||
equippedModulesById, | ||
orderedStepIds = [], | ||
expected, | ||
}) => { | ||
it(testMsg, () => { | ||
const result = getNextDefaultThermocyclerModuleId( | ||
savedForms, | ||
orderedStepIds, | ||
equippedModulesById | ||
) | ||
|
||
expect(result).toBe(expected) | ||
}) | ||
} | ||
) | ||
}) | ||
}) |
18 changes: 18 additions & 0 deletions
18
...signer/src/steplist/formLevel/getNextDefaultModuleId/getNextDefaultTemperatureModuleId.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @flow | ||
import findKey from 'lodash/findKey' | ||
|
||
import { TEMPERATURE_MODULE_TYPE } from '@opentrons/shared-data' | ||
|
||
import type { ModuleOnDeck } from '../../../step-forms' | ||
import type { StepIdType, FormData } from '../../../form-types' | ||
|
||
export function getNextDefaultTemperatureModuleId( | ||
savedForms: { [StepIdType]: FormData }, | ||
orderedStepIds: Array<StepIdType>, | ||
equippedModulesById: { [moduleId: string]: ModuleOnDeck } | ||
): string | null { | ||
return ( | ||
findKey(equippedModulesById, m => m.type === TEMPERATURE_MODULE_TYPE) || | ||
null | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
...igner/src/steplist/formLevel/getNextDefaultModuleId/getNextDefaultThermocyclerModuleId.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @flow | ||
import findKey from 'lodash/findKey' | ||
import { THERMOCYCLER_MODULE_TYPE } from '@opentrons/shared-data' | ||
|
||
import type { ModuleOnDeck } from '../../../step-forms' | ||
import type { StepIdType, FormData } from '../../../form-types' | ||
|
||
export function getNextDefaultThermocyclerModuleId( | ||
savedForms: { [StepIdType]: FormData }, | ||
orderedStepIds: Array<StepIdType>, | ||
equippedModulesById: { [moduleId: string]: ModuleOnDeck } | ||
): string | null { | ||
return ( | ||
findKey(equippedModulesById, m => m.type === THERMOCYCLER_MODULE_TYPE) || | ||
null | ||
) | ||
} |
37 changes: 3 additions & 34 deletions
37
protocol-designer/src/steplist/formLevel/getNextDefaultModuleId/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,4 @@ | ||
// @flow | ||
import findKey from 'lodash/findKey' | ||
import last from 'lodash/last' | ||
import { | ||
TEMPERATURE_MODULE_TYPE, | ||
THERMOCYCLER_MODULE_TYPE, | ||
} from '@opentrons/shared-data' | ||
import { getNextDefaultTemperatureModuleId } from './getNextDefaultTemperatureModuleId' | ||
import { getNextDefaultThermocyclerModuleId } from './getNextDefaultThermocyclerModuleId' | ||
|
||
import type { ModuleOnDeck } from '../../../step-forms' | ||
import type { StepIdType, FormData } from '../../../form-types' | ||
|
||
const isLastStepTemp = (lastModuleStep: FormData = {}): boolean => | ||
!!(lastModuleStep.moduleId && lastModuleStep.stepType === 'temperature') | ||
|
||
export function getNextDefaultTemperatureModuleId( | ||
savedForms: { [StepIdType]: FormData }, | ||
orderedStepIds: Array<StepIdType>, | ||
equippedModulesById: { [moduleId: string]: ModuleOnDeck } | ||
): string | null { | ||
const prevModuleSteps = orderedStepIds | ||
.map(stepId => savedForms[stepId]) | ||
.filter(form => form && form.moduleId) | ||
|
||
const lastModuleStep = last(prevModuleSteps) | ||
|
||
// TODO (ka 2019-12-20): Since we are hiding the thermocylcer module as an option for now, | ||
// should we simplify this to only return temperature modules? | ||
const nextDefaultModule: string | null = | ||
(isLastStepTemp(lastModuleStep) && lastModuleStep.moduleId) || | ||
findKey(equippedModulesById, m => m.type === TEMPERATURE_MODULE_TYPE) || | ||
findKey(equippedModulesById, m => m.type === THERMOCYCLER_MODULE_TYPE) || | ||
null | ||
|
||
return nextDefaultModule || null | ||
} | ||
export { getNextDefaultTemperatureModuleId, getNextDefaultThermocyclerModuleId } |
Oops, something went wrong.