Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app, api-client, react-api-client): unify analysis and run record for CommandText use #15125

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
protocolData: CommandTextData
robotType: RobotType
}

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

switch (command.commandType) {
case 'loadPipette': {
const pipetteModel = getPipetteNameOnMount(
robotSideAnalysis,
protocolData,
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,
protocolData,
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,
protocolData,
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 = protocolData.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,
protocolData,
adapterLoc?.moduleId ?? ''
)
const moduleName =
Expand All @@ -122,7 +119,7 @@ export const LoadCommandText = ({
adapter_name: adapterName,
module_name: moduleName,
slot_name: getModuleDisplayLocation(
robotSideAnalysis,
protocolData,
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(protocolData, liquidId),
labware: getLabwareName(protocolData, labwareId),
})
}
default: {
Expand Down
31 changes: 11 additions & 20 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
protocolData: CommandTextData
robotType: RobotType
}
export function MoveLabwareCommandText(
props: MoveLabwareCommandTextProps
): JSX.Element {
const { t } = useTranslation('protocol_command_text')
const { command, robotSideAnalysis, robotType } = props
const { command, protocolData, robotType } = props
const { labwareId, newLocation, strategy } = command.params

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

return strategy === 'usingGripper'
? t('move_labware_using_gripper', {
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(protocolData, labwareId),
old_location:
oldLocation != null
? getLabwareDisplayLocation(
robotSideAnalysis,
oldLocation,
t,
robotType
)
? getLabwareDisplayLocation(protocolData, oldLocation, t, robotType)
: '',
new_location: location,
})
: t('move_labware_manually', {
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(protocolData, labwareId),
old_location:
oldLocation != null
? getLabwareDisplayLocation(
robotSideAnalysis,
oldLocation,
t,
robotType
)
? getLabwareDisplayLocation(protocolData, oldLocation, t, robotType)
: '',
new_location: location,
})
Expand Down
44 changes: 17 additions & 27 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, RobotType } from '@opentrons/shared-data'
ncdiehl11 marked this conversation as resolved.
Show resolved Hide resolved

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

interface PipettingCommandTextProps {
command: PipettingRunTimeCommand
robotSideAnalysis: CompletedProtocolAnalysis
protocolData: CommandTextData
ncdiehl11 marked this conversation as resolved.
Show resolved Hide resolved
robotType: RobotType
}

export const PipettingCommandText = ({
command,
robotSideAnalysis,
protocolData,
robotType,
}: PipettingCommandTextProps): JSX.Element | null => {
const { t } = useTranslation('protocol_command_text')
Expand All @@ -36,29 +33,24 @@ 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 = protocolData.commands.slice(
0,
robotSideAnalysis.commands.findIndex(c => c.id === command.id)
protocolData.commands.findIndex(c => c.id === command.id)
)
const labwareLocation = getFinalLabwareLocation(
labwareId,
allPreviousCommands
)
const displayLocation =
labwareLocation != null
? getLabwareDisplayLocation(
robotSideAnalysis,
labwareLocation,
t,
robotType
)
? getLabwareDisplayLocation(protocolData, labwareLocation, t, robotType)
: ''
switch (command.commandType) {
case 'aspirate': {
const { volume, flowRate } = command.params
return t('aspirate', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(protocolData, labwareId),
labware_location: displayLocation,
volume: volume,
flow_rate: flowRate,
Expand All @@ -69,15 +61,15 @@ export const PipettingCommandText = ({
return pushOut
? t('dispense_push_out', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(protocolData, labwareId),
labware_location: displayLocation,
volume: volume,
flow_rate: flowRate,
push_out_volume: pushOut,
})
: t('dispense', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(protocolData, labwareId),
labware_location: displayLocation,
volume: volume,
flow_rate: flowRate,
Expand All @@ -87,35 +79,33 @@ export const PipettingCommandText = ({
const { flowRate } = command.params
return t('blowout', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(protocolData, labwareId),
labware_location: displayLocation,
flow_rate: flowRate,
})
}
case 'dropTip': {
const loadedLabware = getLoadedLabware(robotSideAnalysis, labwareId)
const loadedLabware = getLoadedLabware(protocolData, labwareId)
const labwareDefinitions = getLabwareDefinitionsFromCommands(
robotSideAnalysis.commands
protocolData.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(protocolData, labwareId),
labware_location: displayLocation,
})
: t('drop_tip', {
well_name: wellName,
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(protocolData, labwareId),
})
}
case 'pickUpTip': {
const pipetteId = command.params.pipetteId
const pipetteName:
| PipetteName
| undefined = robotSideAnalysis.pipettes.find(
const pipetteName: PipetteName | undefined = protocolData.pipettes.find(
pip => pip.id === pipetteId
)?.pipetteName

Expand All @@ -126,7 +116,7 @@ export const PipettingCommandText = ({
wellName,
pipetteName
),
labware: getLabwareName(robotSideAnalysis, labwareId),
labware: getLabwareName(protocolData, labwareId),
labware_location: displayLocation,
})
}
Expand Down
Loading
Loading