Skip to content

Commit

Permalink
feat(protocol-designer): add designerApplication labware, pipettes, m…
Browse files Browse the repository at this point in the history
…odules keys

closes AUTH-1407
  • Loading branch information
jerader committed Feb 5, 2025
1 parent 9d28971 commit 0fee111
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 126 deletions.
82 changes: 82 additions & 0 deletions protocol-designer/src/file-data/__tests__/utils.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { describe, it, expect } from 'vitest'
import {
fixture96Plate,
fixtureP1000SingleV2Specs,
} from '@opentrons/shared-data'
import {
getLabwareLoadInfo,
getModulesLoadInfo,
getPipettesLoadInfo,
} from '../selectors/utils'
import type { LabwareDefinition2, PipetteName } from '@opentrons/shared-data'

describe('getPipettesLoadInfo', () => {
it('returns pipettes from pipette entities', () => {
const pipId = '1'
const results = {
[pipId]: {
pipetteName: fixtureP1000SingleV2Specs.displayName,
},
}
expect(
getPipettesLoadInfo({
pipId: {
spec: fixtureP1000SingleV2Specs,
tiprackLabwareDef: [],
name: fixtureP1000SingleV2Specs.displayName as PipetteName,
id: pipId,
tiprackDefURI: [],
},
})
).toEqual(results)
})
})

describe('getModuleLoadInfo', () => {
it('returns modules from module entities', () => {
const moduleId = '1'
const results = {
[moduleId]: {
model: 'magneticModuleV2',
},
}
expect(
getModulesLoadInfo({
moduleId: {
id: moduleId,
model: 'magneticModuleV2',
type: 'magneticModuleType',
},
})
).toEqual(results)
})
})

describe('getLabwareLoadInfo', () => {
it('returns labwares from labware entities', () => {
const labwareId = '1'
const uri = 'mockUri'
const results = {
[labwareId]: {
displayName: 'nick name',
labwareDefURI: uri,
},
}
const labwareNicknamesById: Record<string, string> = {
[labwareId]: 'nick name',
}

expect(
getLabwareLoadInfo(
{
labwareId: {
id: labwareId,
labwareDefURI: uri,
def: fixture96Plate as LabwareDefinition2,
},
},
labwareNicknamesById
)
).toEqual(results)
})
})
43 changes: 11 additions & 32 deletions protocol-designer/src/file-data/selectors/fileCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ import { selectors as ingredSelectors } from '../../labware-ingred/selectors'
import { selectors as stepFormSelectors } from '../../step-forms'
import { selectors as uiLabwareSelectors } from '../../ui/labware'
import { swatchColors } from '../../organisms/DefineLiquidsModal/swatchColors'
import {
DEFAULT_MM_TOUCH_TIP_OFFSET_FROM_TOP,
DEFAULT_MM_BLOWOUT_OFFSET_FROM_TOP,
DEFAULT_MM_OFFSET_FROM_BOTTOM,
} from '../../constants'
import { getStepGroups } from '../../step-forms/selectors'
import { getFileMetadata, getRobotType } from './fileFields'
import { getInitialRobotState, getRobotStateTimeline } from './commands'
import { getLoadCommands } from './utils'
import {
getLabwareLoadInfo,
getLoadCommands,
getModulesLoadInfo,
getPipettesLoadInfo,
} 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 @@ -45,23 +44,9 @@ 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'

// DesignerApplication type for version 8_5
export interface DesignerApplicationDataV8_5 {
ingredients: LiquidEntities
ingredLocations: {
[labwareId: string]: {
[wellName: string]: { [liquidId: string]: { volume: number } }
}
}
savedStepForms: Record<string, any>
orderedStepIds: string[]
pipetteTiprackAssignments: Record<string, string[]>
dismissedWarnings: DismissedWarningState
}
import type { PDMetadata } from '../../file-types'

// 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 @@ -159,15 +144,6 @@ export const createFile: Selector<ProtocolFile> = createSelector(
version: applicationVersion,
data: {
_internalAppBuildDate,
defaultValues: {
// TODO: Ian 2019-06-13 load these into redux and always get them from redux, not constants.js
// This `defaultValues` key is not yet read by anything, but is populated here for auditability
// and so that later we can do #3587 without a PD migration
aspirate_mmFromBottom: DEFAULT_MM_OFFSET_FROM_BOTTOM,
dispense_mmFromBottom: DEFAULT_MM_OFFSET_FROM_BOTTOM,
touchTip_mmFromTop: DEFAULT_MM_TOUCH_TIP_OFFSET_FROM_TOP,
blowout_mmFromTop: DEFAULT_MM_BLOWOUT_OFFSET_FROM_TOP,
},
pipetteTiprackAssignments: mapValues(
pipetteEntities,
(p: typeof pipetteEntities[keyof typeof pipetteEntities]): string[] =>
Expand All @@ -178,6 +154,9 @@ export const createFile: Selector<ProtocolFile> = createSelector(
ingredLocations,
savedStepForms,
orderedStepIds: savedOrderedStepIds,
pipettes: getPipettesLoadInfo(pipetteEntities),
modules: getModulesLoadInfo(moduleEntities),
labware: getLabwareLoadInfo(labwareEntities, labwareNicknamesById),
},
}

Expand Down Expand Up @@ -268,7 +247,7 @@ export const createFile: Selector<ProtocolFile> = createSelector(
commandAnnotations,
}

const protocolBase: ProtocolBase<DesignerApplicationDataV8_5> = {
const protocolBase: ProtocolBase<PDMetadata> = {
$otSharedSchema: '#/protocol/schemas/8',
schemaVersion: 8,
metadata: {
Expand Down
47 changes: 44 additions & 3 deletions protocol-designer/src/file-data/selectors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import map from 'lodash/map'
import reduce from 'lodash/reduce'
import { getLoadLiquidCommands } from '../../load-file/migration/utils/getLoadLiquidCommands'
import { COLUMN_4_SLOTS, uuid } from '@opentrons/step-generation'

import type {
AddressableAreaName,
CreateCommand,
Expand All @@ -21,9 +20,13 @@ import type {
ModuleEntities,
TimelineFrame,
LiquidEntities,
PipetteEntity,
ModuleEntity,
LabwareEntity,
} from '@opentrons/step-generation'
import type { Labware, Modules, Pipettes } from '../../file-types'

interface Pipettes {
interface MappedPipettes {
[pipetteId: string]: { name: PipetteName }
}

Expand All @@ -36,7 +39,7 @@ export const getLoadCommands = (
liquidEntities: LiquidEntities,
ingredLocations: LabwareLiquidState
): CreateCommand[] => {
const pipettes: Pipettes = mapValues(
const pipettes: MappedPipettes = mapValues(
initialRobotState.pipettes,
(
pipette: typeof initialRobotState.pipettes[keyof typeof initialRobotState.pipettes],
Expand Down Expand Up @@ -196,3 +199,41 @@ export const getLoadCommands = (
...loadLiquidCommands,
]
}

export const getPipettesLoadInfo = (
pipetteEntities: PipetteEntities
): Pipettes => {
return Object.values(pipetteEntities).reduce<Pipettes>(
(acc, pipetteEntity: PipetteEntity) => ({
...acc,
[pipetteEntity.id]: { pipetteName: pipetteEntity.name },
}),
{}
)
}

export const getModulesLoadInfo = (moduleEntities: ModuleEntities): Modules => {
return Object.values(moduleEntities).reduce<Modules>(
(acc, moduleEntity: ModuleEntity) => ({
...acc,
[moduleEntity.id]: { model: moduleEntity.model },
}),
{}
)
}

export const getLabwareLoadInfo = (
labwareEntities: LabwareEntities,
labwareNicknamesById: Record<string, string>
): Labware => {
return Object.values(labwareEntities).reduce<Labware>(
(acc, labwareEntity: LabwareEntity) => ({
...acc,
[labwareEntity.id]: {
displayName: labwareNicknamesById[labwareEntity.id],
labwareDefURI: labwareEntity.labwareDefURI,
},
}),
{}
)
}
41 changes: 24 additions & 17 deletions protocol-designer/src/file-types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import type {
ModuleModel,
PipetteName,
ProtocolFile,
} from '@opentrons/shared-data'
import type { LiquidEntities } from '@opentrons/step-generation'
import type { RootState as IngredRoot } from './labware-ingred/reducers'
import type { RootState as StepformRoot } from './step-forms'
import type { RootState as DismissRoot } from './dismiss'
import type { ProtocolFile as ProtocolFileV3 } from '@opentrons/shared-data/protocol/types/schemaV3'
import type { ProtocolFile as ProtocolFileV4 } from '@opentrons/shared-data/protocol/types/schemaV4'
import type { ProtocolFile as ProtocolFileV5 } from '@opentrons/shared-data/protocol/types/schemaV5'
import type { ProtocolFile as ProtocolFileV6 } from '@opentrons/shared-data/protocol/types/schemaV6'
import type { LiquidEntities } from '@opentrons/step-generation'
export interface PipetteLoadInfo {
pipetteName: PipetteName
}
export interface ModuleLoadInfo {
model: ModuleModel
}
export interface LabwareLoadInfo {
displayName: string // either labwareDef displayName or user defined nickName
labwareDefURI: string // the labware definition URI
}

export type Pipettes = Record<string, PipetteLoadInfo>
export type Modules = Record<string, ModuleLoadInfo>
export type Labware = Record<string, LabwareLoadInfo>
export interface PDMetadata {
// pipetteId to tiprackModel
pipetteTiprackAssignments: Record<string, string[]>
Expand All @@ -15,19 +29,12 @@ export interface PDMetadata {
ingredLocations: IngredRoot['ingredLocations']
savedStepForms: StepformRoot['savedStepForms']
orderedStepIds: StepformRoot['orderedStepIds']
defaultValues: {
aspirate_mmFromBottom: number | null
dispense_mmFromBottom: number | null
touchTip_mmFromTop: number | null
blowout_mmFromTop: number | null
}
pipettes: Pipettes
modules: Modules
labware: Labware
}
// NOTE: PD currently supports saving both v3 and v4, depending on whether it has modules
export type PDProtocolFile =
| ProtocolFileV3<PDMetadata>
| ProtocolFileV4<PDMetadata>
| ProtocolFileV5<PDMetadata>
| ProtocolFileV6<PDMetadata>

export type PDProtocolFile = ProtocolFile<PDMetadata> & PDMetadata

export function getPDMetadata(file: PDProtocolFile): PDMetadata {
const metadata = file.designerApplication?.data
Expand Down
12 changes: 10 additions & 2 deletions protocol-designer/src/load-file/migration/8_5_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ import floor from 'lodash/floor'
import { swatchColors } from '../../organisms/DefineLiquidsModal/swatchColors'
import { getMigratedPositionFromTop } from './utils/getMigrationPositionFromTop'
import { getAdditionalEquipmentLocationUpdate } from './utils/getAdditionalEquipmentLocationUpdate'
import { getEquipmentLoadInfoFromCommands } from './utils/getEquipmentLoadInfoFromCommands'
import type {
LoadLabwareCreateCommand,
ProtocolFile,
} from '@opentrons/shared-data'
import type { LiquidEntities } from '@opentrons/step-generation'
import type { DesignerApplicationDataV8_5 } from '../../file-data/selectors'
import type { DesignerApplicationData } from './utils/getLoadLiquidCommands'
import type { PDMetadata } from '../../file-types'

export const migrateFile = (
appData: ProtocolFile<DesignerApplicationData>
): ProtocolFile<DesignerApplicationDataV8_5> => {
): ProtocolFile<PDMetadata> => {
const {
designerApplication,
commands,
labwareDefinitions,
liquids,
robot,
} = appData

if (designerApplication == null || designerApplication?.data == null) {
throw Error('The designerApplication key in your file is corrupt.')
}
Expand Down Expand Up @@ -156,13 +158,19 @@ export const migrateFile = (
},
{}
)
const equipmentLoadInfoFromCommands = getEquipmentLoadInfoFromCommands(
commands,
labwareDefinitions
)

return {
...appData,
designerApplication: {
...designerApplication,
data: {
...designerApplication.data,
ingredients: migratedIngredients,
...equipmentLoadInfoFromCommands,
savedStepForms: {
...designerApplication.data.savedStepForms,
...updatedInitialStep,
Expand Down
Loading

0 comments on commit 0fee111

Please sign in to comment.