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 2 commits
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
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
41 changes: 19 additions & 22 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,37 +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
)?.pipetteName
| undefined = commandTextData.pipettes.find(pip => pip.id === pipetteId)
ncdiehl11 marked this conversation as resolved.
Show resolved Hide resolved
?.pipetteName

return t('pickup_tip', {
well_range: getWellRange(
Expand All @@ -126,7 +123,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
Loading