Skip to content

Commit

Permalink
create EditMultipleLiquidGroups redux action to update id and pythonName
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Jan 30, 2025
1 parent d6b5964 commit ce1beb8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
71 changes: 52 additions & 19 deletions protocol-designer/src/labware-ingred/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { StepFieldName } from '../../form-types'
import type { DeckSlot, ThunkAction } from '../../types'
import type { Fixture, IngredInputs } from '../types'
import type { CutoutId, ModuleModel } from '@opentrons/shared-data'
import { getLiquidEntities } from '../../step-forms/selectors'

// ===== Labware selector actions =====
export interface OpenAddLabwareModalAction {
Expand Down Expand Up @@ -124,33 +125,65 @@ export const removeWellsContents: (
type: 'REMOVE_WELLS_CONTENTS',
payload,
})

export interface EditMultipleLiquidGroupsAction {
type: 'EDIT_MULTIPLE_LIQUID_GROUPS'
payload: Record<string, IngredInputs> // Updated liquid groups
}

export interface DeleteLiquidGroupAction {
type: 'DELETE_LIQUID_GROUP'
payload: string // liquid group id
}
export const deleteLiquidGroup: (
liquidGroupId: string
) => ThunkAction<DeleteLiquidGroupAction> = liquidGroupId => (
dispatch,
getState
) => {
const allLiquidGroupsOnDeck = selectors.getLiquidGroupsOnDeck(getState())
const liquidIsOnDeck = allLiquidGroupsOnDeck.includes(liquidGroupId)
// TODO: Ian 2018-10-22 we will eventually want to replace
// this window.confirm with a modal
const okToDelete = liquidIsOnDeck
? global.confirm(
'This liquid has been placed on the deck, are you sure you want to delete it?'
)
: true
) => ThunkAction<
DeleteLiquidGroupAction | EditMultipleLiquidGroupsAction
> = liquidGroupId => (dispatch, getState) => {
const allLiquidGroups = selectors.getLiquidGroupsOnDeck(getState())
const liquidEntities = getLiquidEntities(getState())
const liquidGroupIdNum = parseInt(liquidGroupId)
const allLiquidGroupIds = Object.keys(allLiquidGroups)
.map(id => parseInt(id))
.sort((a, b) => a - b)

if (okToDelete) {
return dispatch({
type: 'DELETE_LIQUID_GROUP',
payload: liquidGroupId,
})
}
if (!allLiquidGroupIds.includes(liquidGroupIdNum)) return

const okToDelete = global.confirm(
'This liquid has been placed on the deck, are you sure you want to delete it?'
)

if (!okToDelete) return

dispatch({
type: 'DELETE_LIQUID_GROUP',
payload: liquidGroupId,
})

const updatedLiquidGroups: Record<string, IngredInputs> = {}
console.log('liquidGroupIdNum', liquidGroupIdNum)
const filteredGroupIds = allLiquidGroupIds
.filter(id => id !== liquidGroupIdNum)
.sort((a, b) => a - b)

console.log('filteredGroupIds', filteredGroupIds)
filteredGroupIds.forEach((oldId, index) => {
const liquid = liquidEntities[oldId]
if (liquid) {
updatedLiquidGroups[index.toString()] = {
...liquid,
liquidGroupId: index.toString(),
pythonName: `liquid_${index}`,
}
}
})
console.log('updatedLiquidGroups', updatedLiquidGroups)
dispatch({
type: 'EDIT_MULTIPLE_LIQUID_GROUPS',
payload: updatedLiquidGroups,
})
}

// NOTE: assumes you want to set a uniform volume of the same liquid in one labware
export interface SetWellContentsPayload {
liquidGroupId: string
Expand Down
10 changes: 10 additions & 0 deletions protocol-designer/src/labware-ingred/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import type {
SelectFixtureAction,
ZoomedIntoSlotAction,
GenerateNewProtocolAction,
EditMultipleLiquidGroupsAction,
} from '../actions'
// REDUCERS
// modeLabwareSelection: boolean. If true, we're selecting labware to add to a slot
Expand Down Expand Up @@ -293,6 +294,15 @@ export const ingredients: Reducer<IngredientsState, any> = handleActions(
const liquidGroupId = action.payload
return omit(state, liquidGroupId)
},
EDIT_MULTIPLE_LIQUID_GROUPS: (
state: IngredientsState,
action: EditMultipleLiquidGroupsAction
): IngredientsState => {
return {
...state,
...action.payload,
}
},
LOAD_FILE: (
state: IngredientsState,
action: LoadFileAction
Expand Down
1 change: 0 additions & 1 deletion step-generation/src/commandCreators/compound/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const transfer: CommandCreator<TransferArgs> = (
invariantContext,
prevRobotState
) => {
console.log('invariantcontext', invariantContext)
/**
Transfer will iterate through a set of 1 or more source and destination wells.
For each pair, it will aspirate from the source well, then dispense into the destination well.
Expand Down

0 comments on commit ce1beb8

Please sign in to comment.