From f7936ca2137b922707e428ba8a882689fea4773d Mon Sep 17 00:00:00 2001 From: Jamey Huffnagle Date: Thu, 18 Jul 2024 17:43:11 -0400 Subject: [PATCH] shinier types --- .../utils/getCommentCommandText.ts | 8 ++------ .../utils/getConfigureForVolumeCommandText.ts | 8 ++------ .../utils/getConfigureNozzleLayoutCommandText.ts | 8 ++------ .../utils/getCustomCommandText.ts | 8 ++------ .../utils/getDelayCommandText.ts | 8 ++------ .../utils/getDirectTranslationCommandText.ts | 11 +++++++++-- .../utils/getHSShakeSpeedCommandText.ts | 8 ++------ .../utils/getMoveLabwareCommandText.ts | 8 ++------ .../utils/getMoveRelativeCommandText.ts | 8 ++------ .../getMoveToAddressabelAreaForDropTipCommandText.ts | 11 ++--------- .../utils/getMoveToAddressableAreaCommandText.ts | 8 ++------ .../utils/getMoveToCoordinatesCommandText.ts | 8 ++------ .../utils/getMoveToSlotCommandText.ts | 8 ++------ .../utils/getMoveToWellCommandText.ts | 11 ++++------- .../utils/getPrepareToAspirateCommandText.ts | 8 ++------ .../utils/getTCRunProfileCommandText.ts | 9 +++------ .../utils/getTemperatureCommandText.ts | 12 ++++++++---- .../utils/getWaitForDurationCommandText.ts | 8 ++------ .../utils/getWaitForResumeCommandText.ts | 8 ++------ .../hooks/useCommandTextString/utils/types.ts | 7 +++++++ 20 files changed, 61 insertions(+), 112 deletions(-) create mode 100644 app/src/molecules/Command/hooks/useCommandTextString/utils/types.ts diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getCommentCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getCommentCommandText.ts index ced58a0927fc..3a1b7ce7e8a5 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getCommentCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getCommentCommandText.ts @@ -1,13 +1,9 @@ import type { CommentRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetCommentCommandText = Omit & { - command: CommentRunTimeCommand -} +import type { HandlesCommands } from './types' export function getCommentCommandText({ command, -}: GetCommentCommandText): string { +}: HandlesCommands): string { const { message } = command.params return message diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureForVolumeCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureForVolumeCommandText.ts index bc48312017bb..a521d67749c6 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureForVolumeCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureForVolumeCommandText.ts @@ -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 & { - command: ConfigureForVolumeRunTimeCommand -} +import type { HandlesCommands } from './types' export function getConfigureForVolumeCommandText({ command, commandTextData, t, -}: GetConfigureForVolumeCommandText): string { +}: HandlesCommands): string { const { volume, pipetteId } = command.params const pipetteName = commandTextData?.pipettes.find( pip => pip.id === pipetteId diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureNozzleLayoutCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureNozzleLayoutCommandText.ts index 2c7f633c48eb..3185ac284953 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureNozzleLayoutCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureNozzleLayoutCommandText.ts @@ -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 & { - command: ConfigureNozzleLayoutRunTimeCommand -} +import type { HandlesCommands } from './types' export function getConfigureNozzleLayoutCommandText({ command, commandTextData, t, -}: GetConfigureNozzleLayoutCommandText): string { +}: HandlesCommands): string { const { configurationParams, pipetteId } = command.params const pipetteName = commandTextData?.pipettes.find( pip => pip.id === pipetteId diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getCustomCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getCustomCommandText.ts index ad4d0ca498f7..da6d5a1d506e 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getCustomCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getCustomCommandText.ts @@ -1,13 +1,9 @@ import type { CustomRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetCustomCommandText = Omit & { - command: CustomRunTimeCommand -} +import type { HandlesCommands } from './types' export function getCustomCommandText({ command, -}: GetCustomCommandText): string { +}: HandlesCommands): string { const { legacyCommandText } = command.params ?? {} const sanitizedCommandText = typeof legacyCommandText === 'object' diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getDelayCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getDelayCommandText.ts index 75c75503fc78..8bb24d99661f 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getDelayCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getDelayCommandText.ts @@ -1,14 +1,10 @@ import type { DeprecatedDelayRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetDelayCommandText = Omit & { - command: DeprecatedDelayRunTimeCommand -} +import type { HandlesCommands } from './types' export function getDelayCommandText({ command, t, -}: GetDelayCommandText): string { +}: HandlesCommands): string { const { message = '' } = command.params if ('waitForResume' in command.params) { diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getDirectTranslationCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getDirectTranslationCommandText.ts index bef1369f41ec..f2b9dce37403 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getDirectTranslationCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getDirectTranslationCommandText.ts @@ -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 @@ -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 } +> + +type GetDirectTranslationCommandText = HandlesCommands + export function getDirectTranslationCommandText({ command, t, -}: GetCommandText): string { +}: GetDirectTranslationCommandText): string { const simpleTKey = command != null ? SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE[command.commandType] diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getHSShakeSpeedCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getHSShakeSpeedCommandText.ts index 06e9f0d17226..3710e7f0930b 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getHSShakeSpeedCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getHSShakeSpeedCommandText.ts @@ -1,14 +1,10 @@ import type { HeaterShakerSetAndWaitForShakeSpeedRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetHSShakeSpeedCommandText = Omit & { - command: HeaterShakerSetAndWaitForShakeSpeedRunTimeCommand -} +import type { HandlesCommands } from './types' export function getHSShakeSpeedCommandText({ command, t, -}: GetHSShakeSpeedCommandText): string { +}: HandlesCommands): string { const { rpm } = command.params return t('set_and_await_hs_shake', { rpm }) diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveLabwareCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveLabwareCommandText.ts index ab02f7f931af..71a0ac3e7d63 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveLabwareCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveLabwareCommandText.ts @@ -7,18 +7,14 @@ import { } from '../../../utils' import type { MoveLabwareRunTimeCommand } from '@opentrons/shared-data' -import type { GetCommandText } from '..' - -type GetMoveToWellCommandText = Omit & { - command: MoveLabwareRunTimeCommand -} +import type { HandlesCommands } from './types' export function getMoveLabwareCommandText({ command, t, commandTextData, robotType, -}: GetMoveToWellCommandText): string { +}: HandlesCommands): string { const { labwareId, newLocation, strategy } = command.params const allPreviousCommands = commandTextData?.commands.slice( diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveRelativeCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveRelativeCommandText.ts index 90277171556d..7f3f8bf0aaa3 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveRelativeCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveRelativeCommandText.ts @@ -1,14 +1,10 @@ import type { MoveRelativeRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetMoveRelativeRunTimeCommand = Omit & { - command: MoveRelativeRunTimeCommand -} +import type { HandlesCommands } from './types' export function getMoveRelativeCommandText({ command, t, -}: GetMoveRelativeRunTimeCommand): string { +}: HandlesCommands): string { const { axis, distance } = command.params return t('move_relative', { axis, distance }) diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressabelAreaForDropTipCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressabelAreaForDropTipCommandText.ts index 5bb91e70ba9b..5788fbbdf62c 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressabelAreaForDropTipCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressabelAreaForDropTipCommandText.ts @@ -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): string { const addressableAreaDisplayName = commandTextData != null ? getAddressableAreaDisplayName(commandTextData, command.id, t) diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressableAreaCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressableAreaCommandText.ts index 561cdc1b83de..e8366120a23a 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressableAreaCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressableAreaCommandText.ts @@ -1,17 +1,13 @@ import { getAddressableAreaDisplayName } from '../../../utils' import type { MoveToAddressableAreaRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetMoveToAddressableAreaCommandText = Omit & { - command: MoveToAddressableAreaRunTimeCommand -} +import type { HandlesCommands } from './types' export function getMoveToAddressableAreaCommandText({ command, commandTextData, t, -}: GetMoveToAddressableAreaCommandText): string { +}: HandlesCommands): string { const addressableAreaDisplayName = commandTextData != null ? getAddressableAreaDisplayName(commandTextData, command.id, t) diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToCoordinatesCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToCoordinatesCommandText.ts index da647a506a9d..a3dc5ace9fe3 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToCoordinatesCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToCoordinatesCommandText.ts @@ -1,14 +1,10 @@ import type { MoveToCoordinatesRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetMoveToCoordinatesCommandText = Omit & { - command: MoveToCoordinatesRunTimeCommand -} +import type { HandlesCommands } from './types' export function getMoveToCoordinatesCommandText({ command, t, -}: GetMoveToCoordinatesCommandText): string { +}: HandlesCommands): string { const { coordinates } = command.params return t('move_to_coordinates', coordinates) diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToSlotCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToSlotCommandText.ts index 3f83caf2d02b..b66f5d785135 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToSlotCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToSlotCommandText.ts @@ -1,14 +1,10 @@ import type { MoveToSlotRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetMoveToSlotCommandText = Omit & { - command: MoveToSlotRunTimeCommand -} +import type { HandlesCommands } from './types' export function getMoveToSlotCommandText({ command, t, -}: GetMoveToSlotCommandText): string { +}: HandlesCommands): string { const { slotName } = command.params return t('move_to_slot', { slot_name: slotName }) diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToWellCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToWellCommandText.ts index 836b1ac16a37..8c191f34b40b 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToWellCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToWellCommandText.ts @@ -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 & { - 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): string { const { wellName, labwareId } = command.params const allPreviousCommands = commandTextData?.commands.slice( 0, diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getPrepareToAspirateCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getPrepareToAspirateCommandText.ts index 90b08e0c0ba5..8ed186e14846 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getPrepareToAspirateCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getPrepareToAspirateCommandText.ts @@ -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 & { - command: PrepareToAspirateRunTimeCommand -} +import type { HandlesCommands } from './types' export function getPrepareToAspirateCommandText({ command, commandTextData, t, -}: GetPrepareToAspirateCommandText): string { +}: HandlesCommands): string { const { pipetteId } = command.params const pipetteName = commandTextData?.pipettes.find( pip => pip.id === pipetteId diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getTCRunProfileCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getTCRunProfileCommandText.ts index da3299943028..2d279fca8509 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getTCRunProfileCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getTCRunProfileCommandText.ts @@ -1,14 +1,11 @@ import type { TCRunProfileRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText, GetCommandTextResult } from '..' - -type GetTCRunProfileCommandText = Omit & { - command: TCRunProfileRunTimeCommand -} +import type { GetCommandTextResult } from '..' +import type { HandlesCommands } from './types' export function getTCRunProfileCommandText({ command, t, -}: GetTCRunProfileCommandText): GetCommandTextResult { +}: HandlesCommands): GetCommandTextResult { const { profile } = command.params const stepTexts = profile.map( diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getTemperatureCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getTemperatureCommandText.ts index 6800451f6b94..ee60a76c2897 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getTemperatureCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getTemperatureCommandText.ts @@ -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 @@ -24,9 +25,12 @@ const T_KEYS_BY_COMMAND_TYPE: { 'heaterShaker/setTargetTemperature': 'setting_hs_temp', } -type GetTemperatureCommandText = Omit & { - command: TemperatureCreateCommand -} +type HandledCommands = Extract< + RunTimeCommand, + { commandType: keyof typeof T_KEYS_BY_COMMAND_TYPE } +> + +type GetTemperatureCommandText = HandlesCommands export const getTemperatureCommandText = ({ command, diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForDurationCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForDurationCommandText.ts index a53b7fb29deb..d3b3136be1fc 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForDurationCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForDurationCommandText.ts @@ -1,14 +1,10 @@ import type { WaitForDurationRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetWaitForDurationCommandText = Omit & { - command: WaitForDurationRunTimeCommand -} +import type { HandlesCommands } from './types' export function getWaitForDurationCommandText({ command, t, -}: GetWaitForDurationCommandText): string { +}: HandlesCommands): string { const { seconds, message } = command.params return t('wait_for_duration', { seconds, message: message ?? '' }) diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForResumeCommandText.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForResumeCommandText.ts index 874a3002f16b..f1c7b7fcef66 100644 --- a/app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForResumeCommandText.ts +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForResumeCommandText.ts @@ -1,14 +1,10 @@ import type { WaitForResumeRunTimeCommand } from '@opentrons/shared-data/command' -import type { GetCommandText } from '..' - -type GetWaitForResumeCommandText = Omit & { - command: WaitForResumeRunTimeCommand -} +import type { HandlesCommands } from './types' export function getWaitForResumeCommandText({ command, t, -}: GetWaitForResumeCommandText): string { +}: HandlesCommands): string { return command.params?.message != null && command.params.message !== '' ? command.params.message : t('wait_for_resume') diff --git a/app/src/molecules/Command/hooks/useCommandTextString/utils/types.ts b/app/src/molecules/Command/hooks/useCommandTextString/utils/types.ts new file mode 100644 index 000000000000..37dde8c783a4 --- /dev/null +++ b/app/src/molecules/Command/hooks/useCommandTextString/utils/types.ts @@ -0,0 +1,7 @@ +import type { RunTimeCommand } from '@opentrons/shared-data' +import type { GetCommandText } from '..' + +export type HandlesCommands = Omit< + GetCommandText, + 'command' +> & { command: T }