Skip to content

Commit

Permalink
deal with deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
b-cooper committed Oct 24, 2018
1 parent cbadcfd commit 509a92a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions protocol-designer/src/pipettes/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export const editPipettes = (payload: EditPipettesFields) =>

const nextPipettesSlice = createNewPipettesSlice(state.pipettes.pipettes, payload.left, payload.right)

each(savedForms, formData => {
each(savedForms, (formData, stepId) => {
const formPipetteMount = findKey(prevPipettesByMount, (pipetteData) => (
(pipetteData && pipetteData.id) === formData.pipette
))
if (formData.pipette && formPipetteMount) {
const nextPipetteId = nextPipettesSlice.byMount[formPipetteMount]
const nextChannels = nextPipettesSlice.byId[nextPipetteId] && nextPipettesSlice.byId[nextPipetteId].channels
dispatch(steplistActions.changeSavedStepForm({
stepId: formData.id,
stepId,
update: {
...reconcileFormPipette(formData, state, nextPipetteId, nextChannels),
pipette: nextPipetteId,
pipette: nextPipetteId || null,
},
}))
}
Expand Down
9 changes: 5 additions & 4 deletions protocol-designer/src/pipettes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {getPipette, getLabware} from '@opentrons/shared-data'

import type {Mount} from '@opentrons/components'
import type {PipetteData} from '../step-generation'
import type {PipetteFields} from '../load-file'
import type {PipetteReducerState} from './types'

export function createPipette (
Expand Down Expand Up @@ -38,7 +39,7 @@ export function createPipette (
}

// TODO: BC type left and right here with form mount values
export const createNewPipettesSlice = (state: PipetteReducerState, left: any, right: any): PipetteReducerState => {
export const createNewPipettesSlice = (state: PipetteReducerState, left: PipetteFields, right: PipetteFields): PipetteReducerState => {
const prevLeftPipette = state.byMount.left && state.byId[state.byMount.left]
const prevRightPipette = state.byMount.right && state.byId[state.byMount.right]

Expand All @@ -59,11 +60,11 @@ export const createNewPipettesSlice = (state: PipetteReducerState, left: any, ri
const leftId = newLeftPipette ? newLeftPipette.id : state.byMount.left
const rightId = newRightPipette ? newRightPipette.id : state.byMount.right

const leftPipette = newLeftPipette || (leftId ? state.byId[leftId] : null)
const rightPipette = newRightPipette || (rightId ? state.byId[rightId] : null)
const leftPipette = newLeftPipette || (leftId && left.pipetteModel ? state.byId[leftId] : null)
const rightPipette = newRightPipette || (rightId && left.pipetteModel ? state.byId[rightId] : null)

return {
byMount: {left: leftId || null, right: rightId || null},
byMount: {left: (left.pipetteModel ? leftId : null), right: (right.pipetteModel ? rightId : null)},
byId: ([leftPipette, rightPipette]).reduce((acc: {[pipetteId: string]: PipetteData}, pipette: ?PipetteData) => {
return pipette ? {...acc, [pipette.id]: pipette} : acc
}, {}),
Expand Down

0 comments on commit 509a92a

Please sign in to comment.