Skip to content

Commit

Permalink
refactor(app, api-client, react-api-client): unify analysis and run r…
Browse files Browse the repository at this point in the history
…ecord for CommandText use (#15125)

AUTH-380
  • Loading branch information
ncdiehl11 authored and Carlos-fernandez committed May 20, 2024
1 parent e5513f0 commit d7161f2
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 219 deletions.
2 changes: 2 additions & 0 deletions api-client/src/runs/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
Liquid,
LoadedLabware,
LoadedModule,
LoadedPipette,
Expand Down Expand Up @@ -45,6 +46,7 @@ export interface LegacyGoodRunData {
errors: RunError[]
pipettes: LoadedPipette[]
labware: LoadedLabware[]
liquids: Liquid[]
modules: LoadedModule[]
protocolId?: string
labwareOffsets?: LabwareOffset[]
Expand Down
29 changes: 13 additions & 16 deletions app/src/organisms/CommandText/LoadCommandText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import {
LoadLabwareRunTimeCommand,
getPipetteNameSpecs,
} from '@opentrons/shared-data'

import type {
RunTimeCommand,
CompletedProtocolAnalysis,
RobotType,
} from '@opentrons/shared-data'
import {
getLabwareName,
getPipetteNameOnMount,
Expand All @@ -20,23 +14,26 @@ import {
getLiquidDisplayName,
} from './utils'

import type { RunTimeCommand, RobotType } from '@opentrons/shared-data'
import type { CommandTextData } from './types'

interface LoadCommandTextProps {
command: RunTimeCommand
robotSideAnalysis: CompletedProtocolAnalysis
commandTextData: CommandTextData
robotType: RobotType
}

export const LoadCommandText = ({
command,
robotSideAnalysis,
commandTextData,
robotType,
}: LoadCommandTextProps): JSX.Element | null => {
const { t } = useTranslation('run_details')

switch (command.commandType) {
case 'loadPipette': {
const pipetteModel = getPipetteNameOnMount(
robotSideAnalysis,
commandTextData,
command.params.mount
)
return t('load_pipette_protocol_setup', {
Expand Down Expand Up @@ -64,7 +61,7 @@ export const LoadCommandText = ({
'moduleId' in command.params.location
) {
const moduleModel = getModuleModel(
robotSideAnalysis,
commandTextData,
command.params.location.moduleId
)
const moduleName =
Expand All @@ -80,7 +77,7 @@ export const LoadCommandText = ({
: 1,
labware: command.result?.definition.metadata.displayName,
slot_name: getModuleDisplayLocation(
robotSideAnalysis,
commandTextData,
command.params.location.moduleId
),
module_name: moduleName,
Expand All @@ -91,7 +88,7 @@ export const LoadCommandText = ({
) {
const labwareId = command.params.location.labwareId
const labwareName = command.result?.definition.metadata.displayName
const matchingAdapter = robotSideAnalysis.commands.find(
const matchingAdapter = commandTextData.commands.find(
(command): command is LoadLabwareRunTimeCommand =>
command.commandType === 'loadLabware' &&
command.result?.labwareId === labwareId
Expand All @@ -112,7 +109,7 @@ export const LoadCommandText = ({
})
} else if (adapterLoc != null && 'moduleId' in adapterLoc) {
const moduleModel = getModuleModel(
robotSideAnalysis,
commandTextData,
adapterLoc?.moduleId ?? ''
)
const moduleName =
Expand All @@ -122,7 +119,7 @@ export const LoadCommandText = ({
adapter_name: adapterName,
module_name: moduleName,
slot_name: getModuleDisplayLocation(
robotSideAnalysis,
commandTextData,
adapterLoc?.moduleId ?? ''
),
})
Expand All @@ -148,8 +145,8 @@ export const LoadCommandText = ({
case 'loadLiquid': {
const { liquidId, labwareId } = command.params
return t('load_liquids_info_protocol_setup', {
liquid: getLiquidDisplayName(robotSideAnalysis, liquidId),
labware: getLabwareName(robotSideAnalysis, labwareId),
liquid: getLiquidDisplayName(commandTextData, liquidId),
labware: getLabwareName(commandTextData, labwareId),
})
}
default: {
Expand Down
21 changes: 11 additions & 10 deletions app/src/organisms/CommandText/MoveLabwareCommandText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@ import { getLabwareName } from './utils'
import { getLabwareDisplayLocation } from './utils/getLabwareDisplayLocation'
import { getFinalLabwareLocation } from './utils/getFinalLabwareLocation'
import type {
CompletedProtocolAnalysis,
MoveLabwareRunTimeCommand,
RobotType,
} from '@opentrons/shared-data'
import type { CommandTextData } from './types'

interface MoveLabwareCommandTextProps {
command: MoveLabwareRunTimeCommand
robotSideAnalysis: CompletedProtocolAnalysis
commandTextData: CommandTextData
robotType: RobotType
}
export function MoveLabwareCommandText(
props: MoveLabwareCommandTextProps
): JSX.Element {
const { t } = useTranslation('protocol_command_text')
const { command, robotSideAnalysis, robotType } = props
const { command, commandTextData, robotType } = props
const { labwareId, newLocation, strategy } = command.params

const allPreviousCommands = robotSideAnalysis.commands.slice(
const allPreviousCommands = commandTextData.commands.slice(
0,
robotSideAnalysis.commands.findIndex(c => c.id === command.id)
commandTextData.commands.findIndex(c => c.id === command.id)
)
const oldLocation = getFinalLabwareLocation(labwareId, allPreviousCommands)
const newDisplayLocation = getLabwareDisplayLocation(
robotSideAnalysis,
commandTextData,
newLocation,
t,
robotType
Expand All @@ -40,11 +41,11 @@ export function MoveLabwareCommandText(

return strategy === 'usingGripper'
? t('move_labware_using_gripper', {
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(commandTextData, labwareId),
old_location:
oldLocation != null
? getLabwareDisplayLocation(
robotSideAnalysis,
commandTextData,
oldLocation,
t,
robotType
Expand All @@ -53,11 +54,11 @@ export function MoveLabwareCommandText(
new_location: location,
})
: t('move_labware_manually', {
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(commandTextData, labwareId),
old_location:
oldLocation != null
? getLabwareDisplayLocation(
robotSideAnalysis,
commandTextData,
oldLocation,
t,
robotType
Expand Down
40 changes: 19 additions & 21 deletions app/src/organisms/CommandText/PipettingCommandText.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { useTranslation } from 'react-i18next'

import {
CompletedProtocolAnalysis,
getLabwareDefURI,
RobotType,
} from '@opentrons/shared-data'
import { getLabwareDefURI } from '@opentrons/shared-data'

import { getLabwareDefinitionsFromCommands } from '../LabwarePositionCheck/utils/labware'
import { getLoadedLabware } from './utils/accessors'
Expand All @@ -17,17 +13,19 @@ import {
import type {
PipetteName,
PipettingRunTimeCommand,
RobotType,
} from '@opentrons/shared-data'
import type { CommandTextData } from './types'

interface PipettingCommandTextProps {
command: PipettingRunTimeCommand
robotSideAnalysis: CompletedProtocolAnalysis
commandTextData: CommandTextData
robotType: RobotType
}

export const PipettingCommandText = ({
command,
robotSideAnalysis,
commandTextData,
robotType,
}: PipettingCommandTextProps): JSX.Element | null => {
const { t } = useTranslation('protocol_command_text')
Expand All @@ -36,9 +34,9 @@ export const PipettingCommandText = ({
'labwareId' in command.params ? command.params.labwareId : ''
const wellName = 'wellName' in command.params ? command.params.wellName : ''

const allPreviousCommands = robotSideAnalysis.commands.slice(
const allPreviousCommands = commandTextData.commands.slice(
0,
robotSideAnalysis.commands.findIndex(c => c.id === command.id)
commandTextData.commands.findIndex(c => c.id === command.id)
)
const labwareLocation = getFinalLabwareLocation(
labwareId,
Expand All @@ -47,7 +45,7 @@ export const PipettingCommandText = ({
const displayLocation =
labwareLocation != null
? getLabwareDisplayLocation(
robotSideAnalysis,
commandTextData,
labwareLocation,
t,
robotType
Expand All @@ -58,7 +56,7 @@ export const PipettingCommandText = ({
const { volume, flowRate } = command.params
return t('aspirate', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(commandTextData, labwareId),
labware_location: displayLocation,
volume: volume,
flow_rate: flowRate,
Expand All @@ -69,15 +67,15 @@ export const PipettingCommandText = ({
return pushOut
? t('dispense_push_out', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(commandTextData, labwareId),
labware_location: displayLocation,
volume: volume,
flow_rate: flowRate,
push_out_volume: pushOut,
})
: t('dispense', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(commandTextData, labwareId),
labware_location: displayLocation,
volume: volume,
flow_rate: flowRate,
Expand All @@ -87,36 +85,36 @@ export const PipettingCommandText = ({
const { flowRate } = command.params
return t('blowout', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(commandTextData, labwareId),
labware_location: displayLocation,
flow_rate: flowRate,
})
}
case 'dropTip': {
const loadedLabware = getLoadedLabware(robotSideAnalysis, labwareId)
const loadedLabware = getLoadedLabware(commandTextData, labwareId)
const labwareDefinitions = getLabwareDefinitionsFromCommands(
robotSideAnalysis.commands
commandTextData.commands
)
const labwareDef = labwareDefinitions.find(
lw => getLabwareDefURI(lw) === loadedLabware?.definitionUri
)
return labwareDef?.parameters.isTiprack
? t('return_tip', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(commandTextData, labwareId),
labware_location: displayLocation,
})
: t('drop_tip', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(commandTextData, labwareId),
})
}
case 'pickUpTip': {
const pipetteId = command.params.pipetteId
const pipetteName:
| PipetteName
| undefined = robotSideAnalysis.pipettes.find(
pip => pip.id === pipetteId
| undefined = commandTextData.pipettes.find(
pipette => pipette.id === pipetteId
)?.pipetteName

return t('pickup_tip', {
Expand All @@ -126,7 +124,7 @@ export const PipettingCommandText = ({
wellName,
pipetteName
),
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(commandTextData, labwareId),
labware_location: displayLocation,
})
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/organisms/CommandText/__fixtures__/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import robotSideAnalysis from './mockRobotSideAnalysis.json'
import type { CompletedProtocolAnalysis } from '@opentrons/shared-data'
import type { CommandTextData } from '../types'

export const mockRobotSideAnalysis: CompletedProtocolAnalysis = robotSideAnalysis as CompletedProtocolAnalysis

export const mockCommandTextData: CommandTextData = {
commands: mockRobotSideAnalysis.commands,
pipettes: mockRobotSideAnalysis.pipettes,
labware: mockRobotSideAnalysis.labware,
modules: mockRobotSideAnalysis.modules,
liquids: mockRobotSideAnalysis.liquids,
}
Loading

0 comments on commit d7161f2

Please sign in to comment.