Skip to content

Commit

Permalink
shinier types
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Jul 18, 2024
1 parent 5ea832e commit e1b7e3a
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { useTranslation } from 'react-i18next'
import * as utils from './utils'

import type { TFunction } from 'i18next'
import type { RunTimeCommand } from '@opentrons/shared-data/command'
import type { RobotType } from '@opentrons/shared-data/lib/js'
import type { RunTimeCommand, RobotType } from '@opentrons/shared-data'
import type { CommandTextData } from '../../types'
import type { GetDirectTranslationCommandText } from './utils/getDirectTranslationCommandText'

export interface UseCommandTextStringParams {
command: RunTimeCommand | null
Expand Down Expand Up @@ -52,7 +52,9 @@ export function useCommandTextString(
case 'heaterShaker/deactivateShaker':
case 'heaterShaker/waitForTemperature':
return {
commandText: utils.getDirectTranslationCommandText(fullParams),
commandText: utils.getDirectTranslationCommandText(
fullParams as GetDirectTranslationCommandText
),
}

case 'aspirate':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import type { CommentRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetCommentCommandText = Omit<GetCommandText, 'command'> & {
command: CommentRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getCommentCommandText({
command,
}: GetCommentCommandText): string {
}: HandlesCommands<CommentRunTimeCommand>): string {
const { message } = command.params

return message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { getPipetteNameSpecs } from '@opentrons/shared-data'

import type { ConfigureForVolumeRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetConfigureForVolumeCommandText = Omit<GetCommandText, 'command'> & {
command: ConfigureForVolumeRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getConfigureForVolumeCommandText({
command,
commandTextData,
t,
}: GetConfigureForVolumeCommandText): string {
}: HandlesCommands<ConfigureForVolumeRunTimeCommand>): string {
const { volume, pipetteId } = command.params
const pipetteName = commandTextData?.pipettes.find(
pip => pip.id === pipetteId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { getPipetteNameSpecs } from '@opentrons/shared-data'

import type { ConfigureNozzleLayoutRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetConfigureNozzleLayoutCommandText = Omit<GetCommandText, 'command'> & {
command: ConfigureNozzleLayoutRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getConfigureNozzleLayoutCommandText({
command,
commandTextData,
t,
}: GetConfigureNozzleLayoutCommandText): string {
}: HandlesCommands<ConfigureNozzleLayoutRunTimeCommand>): string {
const { configurationParams, pipetteId } = command.params
const pipetteName = commandTextData?.pipettes.find(
pip => pip.id === pipetteId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import type { CustomRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetCustomCommandText = Omit<GetCommandText, 'command'> & {
command: CustomRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getCustomCommandText({
command,
}: GetCustomCommandText): string {
}: HandlesCommands<CustomRunTimeCommand>): string {
const { legacyCommandText } = command.params ?? {}
const sanitizedCommandText =
typeof legacyCommandText === 'object'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { DeprecatedDelayRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetDelayCommandText = Omit<GetCommandText, 'command'> & {
command: DeprecatedDelayRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getDelayCommandText({
command,
t,
}: GetDelayCommandText): string {
}: HandlesCommands<DeprecatedDelayRunTimeCommand>): string {
const { message = '' } = command.params

if ('waitForResume' in command.params) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'
import type { HandlesCommands } from './types'

const SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE: {
[commandType in RunTimeCommand['commandType']]?: string
Expand All @@ -24,10 +24,17 @@ const SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE: {
'heaterShaker/waitForTemperature': 'waiting_for_hs_to_reach',
}

type HandledCommands = Extract<
RunTimeCommand,
{ commandType: keyof typeof SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE }
>

export type GetDirectTranslationCommandText = HandlesCommands<HandledCommands>

export function getDirectTranslationCommandText({
command,
t,
}: GetCommandText): string {
}: GetDirectTranslationCommandText): string {
const simpleTKey =
command != null
? SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE[command.commandType]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { HeaterShakerSetAndWaitForShakeSpeedRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetHSShakeSpeedCommandText = Omit<GetCommandText, 'command'> & {
command: HeaterShakerSetAndWaitForShakeSpeedRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getHSShakeSpeedCommandText({
command,
t,
}: GetHSShakeSpeedCommandText): string {
}: HandlesCommands<HeaterShakerSetAndWaitForShakeSpeedRunTimeCommand>): string {
const { rpm } = command.params

return t('set_and_await_hs_shake', { rpm })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ import {
} from '../../../utils'

import type { MoveLabwareRunTimeCommand } from '@opentrons/shared-data'
import type { GetCommandText } from '..'

type GetMoveToWellCommandText = Omit<GetCommandText, 'command'> & {
command: MoveLabwareRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getMoveLabwareCommandText({
command,
t,
commandTextData,
robotType,
}: GetMoveToWellCommandText): string {
}: HandlesCommands<MoveLabwareRunTimeCommand>): string {
const { labwareId, newLocation, strategy } = command.params

const allPreviousCommands = commandTextData?.commands.slice(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { MoveRelativeRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetMoveRelativeRunTimeCommand = Omit<GetCommandText, 'command'> & {
command: MoveRelativeRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getMoveRelativeCommandText({
command,
t,
}: GetMoveRelativeRunTimeCommand): string {
}: HandlesCommands<MoveRelativeRunTimeCommand>): string {
const { axis, distance } = command.params

return t('move_relative', { axis, distance })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { getAddressableAreaDisplayName } from '../../../utils'

import type { MoveToAddressableAreaForDropTipRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetMoveToAddressableAreaForDropTipCommandText = Omit<
GetCommandText,
'command'
> & {
command: MoveToAddressableAreaForDropTipRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getMoveToAddressableAreaForDropTipCommandText({
command,
commandTextData,
t,
}: GetMoveToAddressableAreaForDropTipCommandText): string {
}: HandlesCommands<MoveToAddressableAreaForDropTipRunTimeCommand>): string {
const addressableAreaDisplayName =
commandTextData != null
? getAddressableAreaDisplayName(commandTextData, command.id, t)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { getAddressableAreaDisplayName } from '../../../utils'

import type { MoveToAddressableAreaRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetMoveToAddressableAreaCommandText = Omit<GetCommandText, 'command'> & {
command: MoveToAddressableAreaRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getMoveToAddressableAreaCommandText({
command,
commandTextData,
t,
}: GetMoveToAddressableAreaCommandText): string {
}: HandlesCommands<MoveToAddressableAreaRunTimeCommand>): string {
const addressableAreaDisplayName =
commandTextData != null
? getAddressableAreaDisplayName(commandTextData, command.id, t)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { MoveToCoordinatesRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetMoveToCoordinatesCommandText = Omit<GetCommandText, 'command'> & {
command: MoveToCoordinatesRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getMoveToCoordinatesCommandText({
command,
t,
}: GetMoveToCoordinatesCommandText): string {
}: HandlesCommands<MoveToCoordinatesRunTimeCommand>): string {
const { coordinates } = command.params

return t('move_to_coordinates', coordinates)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { MoveToSlotRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetMoveToSlotCommandText = Omit<GetCommandText, 'command'> & {
command: MoveToSlotRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getMoveToSlotCommandText({
command,
t,
}: GetMoveToSlotCommandText): string {
}: HandlesCommands<MoveToSlotRunTimeCommand>): string {
const { slotName } = command.params

return t('move_to_slot', { slot_name: slotName })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import type { MoveToWellRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'
import {
getFinalLabwareLocation,
getLabwareDisplayLocation,
getLabwareName,
} from '../../../utils'
import type { TFunction } from 'i18next'

type GetMoveToWellCommandText = Omit<GetCommandText, 'command'> & {
command: MoveToWellRunTimeCommand
}
import type { TFunction } from 'i18next'
import type { MoveToWellRunTimeCommand } from '@opentrons/shared-data/command'
import type { HandlesCommands } from './types'

export function getMoveToWellCommandText({
command,
t,
commandTextData,
robotType,
}: GetMoveToWellCommandText): string {
}: HandlesCommands<MoveToWellRunTimeCommand>): string {
const { wellName, labwareId } = command.params
const allPreviousCommands = commandTextData?.commands.slice(
0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { getPipetteNameSpecs } from '@opentrons/shared-data'

import type { PrepareToAspirateRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetPrepareToAspirateCommandText = Omit<GetCommandText, 'command'> & {
command: PrepareToAspirateRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getPrepareToAspirateCommandText({
command,
commandTextData,
t,
}: GetPrepareToAspirateCommandText): string {
}: HandlesCommands<PrepareToAspirateRunTimeCommand>): string {
const { pipetteId } = command.params
const pipetteName = commandTextData?.pipettes.find(
pip => pip.id === pipetteId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import type { TCRunProfileRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText, GetCommandTextResult } from '..'

type GetTCRunProfileCommandText = Omit<GetCommandText, 'command'> & {
command: TCRunProfileRunTimeCommand
}
import type { GetCommandTextResult } from '..'
import type { HandlesCommands } from './types'

export function getTCRunProfileCommandText({
command,
t,
}: GetTCRunProfileCommandText): GetCommandTextResult {
}: HandlesCommands<TCRunProfileRunTimeCommand>): GetCommandTextResult {
const { profile } = command.params

const stepTexts = profile.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import type {
TCSetTargetBlockTemperatureCreateCommand,
TCSetTargetLidTemperatureCreateCommand,
HeaterShakerSetTargetTemperatureCreateCommand,
RunTimeCommand,
} from '@opentrons/shared-data'
import type { GetCommandText } from '..'
import type { HandlesCommands } from './types'

export type TemperatureCreateCommand =
| TemperatureModuleSetTargetTemperatureCreateCommand
Expand All @@ -24,9 +25,12 @@ const T_KEYS_BY_COMMAND_TYPE: {
'heaterShaker/setTargetTemperature': 'setting_hs_temp',
}

type GetTemperatureCommandText = Omit<GetCommandText, 'command'> & {
command: TemperatureCreateCommand
}
type HandledCommands = Extract<
RunTimeCommand,
{ commandType: keyof typeof T_KEYS_BY_COMMAND_TYPE }
>

type GetTemperatureCommandText = HandlesCommands<HandledCommands>

export const getTemperatureCommandText = ({
command,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { WaitForDurationRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetWaitForDurationCommandText = Omit<GetCommandText, 'command'> & {
command: WaitForDurationRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getWaitForDurationCommandText({
command,
t,
}: GetWaitForDurationCommandText): string {
}: HandlesCommands<WaitForDurationRunTimeCommand>): string {
const { seconds, message } = command.params

return t('wait_for_duration', { seconds, message: message ?? '' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { WaitForResumeRunTimeCommand } from '@opentrons/shared-data/command'
import type { GetCommandText } from '..'

type GetWaitForResumeCommandText = Omit<GetCommandText, 'command'> & {
command: WaitForResumeRunTimeCommand
}
import type { HandlesCommands } from './types'

export function getWaitForResumeCommandText({
command,
t,
}: GetWaitForResumeCommandText): string {
}: HandlesCommands<WaitForResumeRunTimeCommand>): string {
return command.params?.message != null && command.params.message !== ''
? command.params.message
: t('wait_for_resume')
Expand Down
Loading

0 comments on commit e1b7e3a

Please sign in to comment.