Skip to content

Commit

Permalink
add more liquidEntities work
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Jan 30, 2025
1 parent 6e0e38a commit e97f363
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 155 deletions.
32 changes: 23 additions & 9 deletions protocol-designer/src/file-data/selectors/fileCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import { getFileMetadata, getRobotType } from './fileFields'
import { getInitialRobotState, getRobotStateTimeline } from './commands'
import { getLoadCommands } from './utils'

import type { SecondOrderCommandAnnotation } from '@opentrons/shared-data/commandAnnotation/types'
import type {
PipetteEntity,
LabwareEntities,
PipetteEntities,
LiquidEntities,
} from '@opentrons/step-generation'
import type {
CommandAnnotationV1Mixin,
Expand All @@ -43,10 +45,22 @@ import type {
ProtocolBase,
ProtocolFile,
} from '@opentrons/shared-data'
import type { DismissedWarningState } from '../../dismiss/reducers'
import type { LabwareDefByDefURI } from '../../labware-defs'
import type { Selector } from '../../types'
import type { DesignerApplicationData } from '../../load-file/migration/utils/getLoadLiquidCommands'
import type { SecondOrderCommandAnnotation } from '@opentrons/shared-data/commandAnnotation/types'

export interface DesignerApplicationDataV8 {
ingredients: LiquidEntities
ingredLocations: {
[labwareId: string]: {
[wellName: string]: { [liquidId: string]: { volume: number } }
}
}
savedStepForms: Record<string, any>
orderedStepIds: string[]
pipetteTiprackAssignments: Record<string, string[]>
dismissedWarnings: DismissedWarningState
}

// TODO: BC: 2018-02-21 uncomment this assert, causes test failures
// console.assert(!isEmpty(process.env.OT_PD_VERSION), 'Could not find application version!')
Expand Down Expand Up @@ -92,7 +106,7 @@ export const createFile: Selector<ProtocolFile> = createSelector(
getRobotStateTimeline,
getRobotType,
dismissSelectors.getAllDismissedWarnings,
ingredSelectors.getLiquidGroupsById,
stepFormSelectors.getLiquidEntities,
ingredSelectors.getLiquidsByLabwareId,
stepFormSelectors.getSavedStepForms,
stepFormSelectors.getOrderedStepIds,
Expand All @@ -108,7 +122,7 @@ export const createFile: Selector<ProtocolFile> = createSelector(
robotStateTimeline,
robotType,
dismissedWarnings,
ingredients,
liquidEntities,
ingredLocations,
savedStepForms,
orderedStepIds,
Expand All @@ -127,7 +141,7 @@ export const createFile: Selector<ProtocolFile> = createSelector(
moduleEntities,
labwareEntities,
labwareNicknamesById,
ingredients,
liquidEntities,
ingredLocations
)

Expand Down Expand Up @@ -159,20 +173,20 @@ export const createFile: Selector<ProtocolFile> = createSelector(
p.tiprackDefURI
),
dismissedWarnings,
ingredients,
ingredients: liquidEntities,
ingredLocations,
savedStepForms,
orderedStepIds: savedOrderedStepIds,
},
}

const liquids: ProtocolFile['liquids'] = reduce(
ingredients,
liquidEntities,
(acc, liquidData, liquidId) => {
return {
...acc,
[liquidId]: {
displayName: liquidData.name,
displayName: liquidData.displayName,
description: liquidData.description ?? '',
displayColor: liquidData.displayColor ?? swatchColors(liquidId),
},
Expand Down Expand Up @@ -253,7 +267,7 @@ export const createFile: Selector<ProtocolFile> = createSelector(
commandAnnotations,
}

const protocolBase: ProtocolBase<DesignerApplicationData> = {
const protocolBase: ProtocolBase<DesignerApplicationDataV8> = {
$otSharedSchema: '#/protocol/schemas/8',
schemaVersion: 8,
metadata: {
Expand Down
9 changes: 6 additions & 3 deletions protocol-designer/src/file-data/selectors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import type {
RobotState,
ModuleEntities,
TimelineFrame,
LiquidEntities,
} from '@opentrons/step-generation'
import type { LiquidGroupsById } from '../../labware-ingred/types'

interface Pipettes {
[pipetteId: string]: { name: PipetteName }
Expand All @@ -33,7 +33,7 @@ export const getLoadCommands = (
moduleEntities: ModuleEntities,
labwareEntities: LabwareEntities,
labwareNicknamesById: Record<string, string>,
ingredients: LiquidGroupsById,
liquidEntities: LiquidEntities,
ingredLocations: LabwareLiquidState
): CreateCommand[] => {
const pipettes: Pipettes = mapValues(
Expand Down Expand Up @@ -161,7 +161,10 @@ export const getLoadCommands = (
[]
)

const loadLiquidCommands = getLoadLiquidCommands(ingredients, ingredLocations)
const loadLiquidCommands = getLoadLiquidCommands(
liquidEntities,
ingredLocations
)

const loadModuleCommands = map(
initialRobotState.modules,
Expand Down
4 changes: 1 addition & 3 deletions protocol-designer/src/labware-ingred/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ export interface EditLiquidGroupAction {
}
// NOTE: with no ID, a new one is assigned
export const editLiquidGroup: (
args: IngredInputs & {
liquidGroupId: string | null | undefined
}
args: IngredInputs
) => ThunkAction<EditLiquidGroupAction> = args => (dispatch, getState) => {
const { liquidGroupId, ...payloadArgs } = args // NOTE: separate liquidGroupId for flow to understand unpacking :/

Expand Down
2 changes: 0 additions & 2 deletions protocol-designer/src/labware-ingred/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ export const ingredients: Reducer<IngredientsState, any> = handleActions(
LOAD_FILE: (
state: IngredientsState,
action: LoadFileAction
// TODO: get this info from loadLiquid
): IngredientsState => getPDMetadata(action.payload.file).ingredients,
},
{}
Expand Down Expand Up @@ -352,7 +351,6 @@ export const ingredLocations: Reducer<LocationsState, any> = handleActions(
LOAD_FILE: (
state: LocationsState,
action: LoadFileAction
// TODO: get this info from loadLiquid
): LocationsState => getPDMetadata(action.payload.file).ingredLocations,
},
{}
Expand Down
30 changes: 10 additions & 20 deletions protocol-designer/src/labware-ingred/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import max from 'lodash/max'
import reduce from 'lodash/reduce'
import type { Selector } from 'reselect'
import type { DropdownOption } from '@opentrons/components'
import type { LabwareLiquidState, LiquidEntity } from '@opentrons/step-generation'
import type {
LabwareLiquidState,
LiquidEntity,
} from '@opentrons/step-generation'
import type { CutoutId } from '@opentrons/shared-data'
import type {
RootState,
Expand All @@ -18,17 +21,16 @@ import type {
import type {
AllIngredGroupFields,
IngredInputs,
OrderedLiquids,
ZoomedIntoSlotInfoState,
} from './types'
import type { BaseState, DeckSlot } from './../types'

// TODO: Ian 2019-02-15 no RootSlice, use BaseState
interface RootSlice {
labwareIngred: RootState
}

const rootSelector = (state: RootSlice): RootState => state.labwareIngred

// NOTE: not intended for UI use! Use getLabwareNicknamesById for the string.
const getLabwareNameInfo: Selector<RootSlice, ContainersState> = createSelector(
rootSelector,
Expand All @@ -53,10 +55,10 @@ const getLiquidNamesById: Selector<
> = createSelector(
getLiquidGroupsById,
ingredGroups =>
mapValues(ingredGroups, (ingred: LiquidEntity) => ingred.displayName) as Record<
string,
string
>
mapValues(
ingredGroups,
(ingred: LiquidEntity) => ingred.displayName
) as Record<string, string>
)
const getLiquidSelectionOptions: Selector<
RootSlice,
Expand Down Expand Up @@ -104,17 +106,7 @@ const allIngredientGroupFields: Selector<
{}
)
)
const allIngredientNamesIds: Selector<
RootSlice,
OrderedLiquids
> = createSelector(getLiquidGroupsById, ingreds => {
return Object.keys(ingreds).map(ingredId => ({
ingredientId: ingredId,
name: ingreds[ingredId].displayName,
displayColor: ingreds[ingredId].displayColor,
liquidClass: ingreds[ingredId].liquidClass,
}))
})

const getLabwareSelectionMode: Selector<RootSlice, boolean> = createSelector(
rootSelector,
rootState => {
Expand Down Expand Up @@ -181,7 +173,6 @@ const getIsNewProtocol: Selector<RootSlice, boolean> = createSelector(
// TODO: prune selectors
export const selectors = {
rootSelector,
getLiquidGroupsById,
getLiquidsByLabwareId,
getLiquidNamesById,
getLabwareSelectionMode,
Expand All @@ -194,7 +185,6 @@ export const selectors = {
getSelectedLiquidGroupState,
getDrillDownLabwareId,
allIngredientGroupFields,
allIngredientNamesIds,
selectedAddLabwareSlot,
getDeckHasLiquid,
getLiquidDisplayColors,
Expand Down
16 changes: 5 additions & 11 deletions protocol-designer/src/labware-ingred/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { CutoutId, ModuleModel } from '@opentrons/shared-data'
import type { DeckSlot, LiquidEntity, LocationLiquidState } from '@opentrons/step-generation'
import type {
DeckSlot,
LiquidEntity,
LocationLiquidState,
} from '@opentrons/step-generation'
// TODO Ian 2018-02-19 make these shared in component library, standardize with Run App
// ===== LABWARE ===========
export interface DisplayLabware {
Expand All @@ -21,16 +25,6 @@ export interface WellContents {
}
export type ContentsByWell = Record<string, WellContents> | null
export type WellContentsByLabware = Record<string, ContentsByWell>
// ==== INGREDIENTS ====
// TODO(ND: 12/17/2024): add migration for liquids in >8.3.0
export type OrderedLiquids = Array<{
ingredientId: string
displayName?: string | null
displayColor?: string | null
liquidClass?: string | null
}>
// TODO: Ian 2018-10-15 audit & rename these confusing types

export type IngredInputs = LiquidEntity & {
volume?: number | null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import reduce from 'lodash/reduce'
import { uuid } from '../../../utils'
import type { LoadLiquidCreateCommand } from '@opentrons/shared-data/protocol/types/schemaV6/command/setup'
import type { DismissedWarningState } from '../../../dismiss/reducers'
import { DesignerApplicationDataV8 } from '../../../file-data/selectors'

Check failure on line 5 in protocol-designer/src/load-file/migration/utils/getLoadLiquidCommands.ts

View workflow job for this annotation

GitHub Actions / js checks

'DesignerApplicationDataV8' is defined but never used
import { LiquidEntities, LiquidEntity } from '@opentrons/step-generation'

Check failure on line 6 in protocol-designer/src/load-file/migration/utils/getLoadLiquidCommands.ts

View workflow job for this annotation

GitHub Actions / js checks

Import "LiquidEntities" is only used as types

Check failure on line 6 in protocol-designer/src/load-file/migration/utils/getLoadLiquidCommands.ts

View workflow job for this annotation

GitHub Actions / js checks

'LiquidEntity' is defined but never used

export interface DesignerApplicationData {
ingredients: Record<
Expand All @@ -24,7 +26,7 @@ export interface DesignerApplicationData {
}

export const getLoadLiquidCommands = (
ingredients?: DesignerApplicationData['ingredients'],
ingredients?: DesignerApplicationData['ingredients'] | LiquidEntities,
ingredLocations?: DesignerApplicationData['ingredLocations']
): LoadLiquidCreateCommand[] => {
let loadLiquidCommands: LoadLiquidCreateCommand[] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Toolbox,
TYPOGRAPHY,
} from '@opentrons/components'
import { getLiquidEntities } from '../../step-forms/selectors'
import { LINK_BUTTON_STYLE } from '../../atoms'
import { selectors as labwareIngredSelectors } from '../../labware-ingred/selectors'
import * as wellContentsSelectors from '../../top-selectors/well-contents'
Expand Down Expand Up @@ -64,7 +65,7 @@ export function LiquidToolbox(props: LiquidToolboxProps): JSX.Element {
const dispatch = useDispatch()
const [showDefineLiquidModal, setDefineLiquidModal] = useState<boolean>(false)
const [showBadFormState, setShowBadFormState] = useState<boolean>(false)
const liquids = useSelector(labwareIngredSelectors.allIngredientNamesIds)
const liquids = useSelector(getLiquidEntities)
const labwareId = useSelector(labwareIngredSelectors.getSelectedLabwareId)
const selectedWellGroups = useSelector(getSelectedWells)
const nickNames = useSelector(getLabwareNicknamesById)
Expand Down Expand Up @@ -236,11 +237,11 @@ export function LiquidToolbox(props: LiquidToolboxProps): JSX.Element {
const liquidInfo: LiquidInfo[] = uniqueLiquids
.map(liquid => {
const foundLiquid = Object.values(liquids).find(
id => id.ingredientId === liquid
id => id.liquidGroupId === liquid
)
return {
liquidIndex: liquid,
name: foundLiquid?.name ?? '',
name: foundLiquid?.displayName ?? '',
color: foundLiquid?.displayColor ?? '',
liquidClassDisplayName: getLiquidClassDisplayName(
foundLiquid?.liquidClass ?? null
Expand Down Expand Up @@ -347,8 +348,9 @@ export function LiquidToolbox(props: LiquidToolboxProps): JSX.Element {
render={({ field }) => {
const fullOptions: DropdownOption[] = liquidSelectionOptions.map(
option => {
const liquid = liquids.find(
liquid => liquid.ingredientId === option.value
const liquid = Object.values(liquids).find(
liquid =>
liquid.liquidGroupId === option.value
)

return {
Expand Down
Loading

0 comments on commit e97f363

Please sign in to comment.