Skip to content

Commit e1b7e3a

Browse files
committed
shinier types
1 parent 5ea832e commit e1b7e3a

21 files changed

+66
-115
lines changed

app/src/molecules/Command/hooks/useCommandTextString/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { useTranslation } from 'react-i18next'
22
import * as utils from './utils'
33

44
import type { TFunction } from 'i18next'
5-
import type { RunTimeCommand } from '@opentrons/shared-data/command'
6-
import type { RobotType } from '@opentrons/shared-data/lib/js'
5+
import type { RunTimeCommand, RobotType } from '@opentrons/shared-data'
76
import type { CommandTextData } from '../../types'
7+
import type { GetDirectTranslationCommandText } from './utils/getDirectTranslationCommandText'
88

99
export interface UseCommandTextStringParams {
1010
command: RunTimeCommand | null
@@ -52,7 +52,9 @@ export function useCommandTextString(
5252
case 'heaterShaker/deactivateShaker':
5353
case 'heaterShaker/waitForTemperature':
5454
return {
55-
commandText: utils.getDirectTranslationCommandText(fullParams),
55+
commandText: utils.getDirectTranslationCommandText(
56+
fullParams as GetDirectTranslationCommandText
57+
),
5658
}
5759

5860
case 'aspirate':

app/src/molecules/Command/hooks/useCommandTextString/utils/getCommentCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import type { CommentRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
3-
4-
type GetCommentCommandText = Omit<GetCommandText, 'command'> & {
5-
command: CommentRunTimeCommand
6-
}
2+
import type { HandlesCommands } from './types'
73

84
export function getCommentCommandText({
95
command,
10-
}: GetCommentCommandText): string {
6+
}: HandlesCommands<CommentRunTimeCommand>): string {
117
const { message } = command.params
128

139
return message

app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureForVolumeCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { getPipetteNameSpecs } from '@opentrons/shared-data'
22

33
import type { ConfigureForVolumeRunTimeCommand } from '@opentrons/shared-data/command'
4-
import type { GetCommandText } from '..'
5-
6-
type GetConfigureForVolumeCommandText = Omit<GetCommandText, 'command'> & {
7-
command: ConfigureForVolumeRunTimeCommand
8-
}
4+
import type { HandlesCommands } from './types'
95

106
export function getConfigureForVolumeCommandText({
117
command,
128
commandTextData,
139
t,
14-
}: GetConfigureForVolumeCommandText): string {
10+
}: HandlesCommands<ConfigureForVolumeRunTimeCommand>): string {
1511
const { volume, pipetteId } = command.params
1612
const pipetteName = commandTextData?.pipettes.find(
1713
pip => pip.id === pipetteId

app/src/molecules/Command/hooks/useCommandTextString/utils/getConfigureNozzleLayoutCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { getPipetteNameSpecs } from '@opentrons/shared-data'
22

33
import type { ConfigureNozzleLayoutRunTimeCommand } from '@opentrons/shared-data/command'
4-
import type { GetCommandText } from '..'
5-
6-
type GetConfigureNozzleLayoutCommandText = Omit<GetCommandText, 'command'> & {
7-
command: ConfigureNozzleLayoutRunTimeCommand
8-
}
4+
import type { HandlesCommands } from './types'
95

106
export function getConfigureNozzleLayoutCommandText({
117
command,
128
commandTextData,
139
t,
14-
}: GetConfigureNozzleLayoutCommandText): string {
10+
}: HandlesCommands<ConfigureNozzleLayoutRunTimeCommand>): string {
1511
const { configurationParams, pipetteId } = command.params
1612
const pipetteName = commandTextData?.pipettes.find(
1713
pip => pip.id === pipetteId

app/src/molecules/Command/hooks/useCommandTextString/utils/getCustomCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import type { CustomRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
3-
4-
type GetCustomCommandText = Omit<GetCommandText, 'command'> & {
5-
command: CustomRunTimeCommand
6-
}
2+
import type { HandlesCommands } from './types'
73

84
export function getCustomCommandText({
95
command,
10-
}: GetCustomCommandText): string {
6+
}: HandlesCommands<CustomRunTimeCommand>): string {
117
const { legacyCommandText } = command.params ?? {}
128
const sanitizedCommandText =
139
typeof legacyCommandText === 'object'

app/src/molecules/Command/hooks/useCommandTextString/utils/getDelayCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import type { DeprecatedDelayRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
3-
4-
type GetDelayCommandText = Omit<GetCommandText, 'command'> & {
5-
command: DeprecatedDelayRunTimeCommand
6-
}
2+
import type { HandlesCommands } from './types'
73

84
export function getDelayCommandText({
95
command,
106
t,
11-
}: GetDelayCommandText): string {
7+
}: HandlesCommands<DeprecatedDelayRunTimeCommand>): string {
128
const { message = '' } = command.params
139

1410
if ('waitForResume' in command.params) {

app/src/molecules/Command/hooks/useCommandTextString/utils/getDirectTranslationCommandText.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { RunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
2+
import type { HandlesCommands } from './types'
33

44
const SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE: {
55
[commandType in RunTimeCommand['commandType']]?: string
@@ -24,10 +24,17 @@ const SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE: {
2424
'heaterShaker/waitForTemperature': 'waiting_for_hs_to_reach',
2525
}
2626

27+
type HandledCommands = Extract<
28+
RunTimeCommand,
29+
{ commandType: keyof typeof SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE }
30+
>
31+
32+
export type GetDirectTranslationCommandText = HandlesCommands<HandledCommands>
33+
2734
export function getDirectTranslationCommandText({
2835
command,
2936
t,
30-
}: GetCommandText): string {
37+
}: GetDirectTranslationCommandText): string {
3138
const simpleTKey =
3239
command != null
3340
? SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE[command.commandType]

app/src/molecules/Command/hooks/useCommandTextString/utils/getHSShakeSpeedCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import type { HeaterShakerSetAndWaitForShakeSpeedRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
3-
4-
type GetHSShakeSpeedCommandText = Omit<GetCommandText, 'command'> & {
5-
command: HeaterShakerSetAndWaitForShakeSpeedRunTimeCommand
6-
}
2+
import type { HandlesCommands } from './types'
73

84
export function getHSShakeSpeedCommandText({
95
command,
106
t,
11-
}: GetHSShakeSpeedCommandText): string {
7+
}: HandlesCommands<HeaterShakerSetAndWaitForShakeSpeedRunTimeCommand>): string {
128
const { rpm } = command.params
139

1410
return t('set_and_await_hs_shake', { rpm })

app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveLabwareCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ import {
77
} from '../../../utils'
88

99
import type { MoveLabwareRunTimeCommand } from '@opentrons/shared-data'
10-
import type { GetCommandText } from '..'
11-
12-
type GetMoveToWellCommandText = Omit<GetCommandText, 'command'> & {
13-
command: MoveLabwareRunTimeCommand
14-
}
10+
import type { HandlesCommands } from './types'
1511

1612
export function getMoveLabwareCommandText({
1713
command,
1814
t,
1915
commandTextData,
2016
robotType,
21-
}: GetMoveToWellCommandText): string {
17+
}: HandlesCommands<MoveLabwareRunTimeCommand>): string {
2218
const { labwareId, newLocation, strategy } = command.params
2319

2420
const allPreviousCommands = commandTextData?.commands.slice(

app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveRelativeCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import type { MoveRelativeRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
3-
4-
type GetMoveRelativeRunTimeCommand = Omit<GetCommandText, 'command'> & {
5-
command: MoveRelativeRunTimeCommand
6-
}
2+
import type { HandlesCommands } from './types'
73

84
export function getMoveRelativeCommandText({
95
command,
106
t,
11-
}: GetMoveRelativeRunTimeCommand): string {
7+
}: HandlesCommands<MoveRelativeRunTimeCommand>): string {
128
const { axis, distance } = command.params
139

1410
return t('move_relative', { axis, distance })

app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressabelAreaForDropTipCommandText.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import { getAddressableAreaDisplayName } from '../../../utils'
22

33
import type { MoveToAddressableAreaForDropTipRunTimeCommand } from '@opentrons/shared-data/command'
4-
import type { GetCommandText } from '..'
5-
6-
type GetMoveToAddressableAreaForDropTipCommandText = Omit<
7-
GetCommandText,
8-
'command'
9-
> & {
10-
command: MoveToAddressableAreaForDropTipRunTimeCommand
11-
}
4+
import type { HandlesCommands } from './types'
125

136
export function getMoveToAddressableAreaForDropTipCommandText({
147
command,
158
commandTextData,
169
t,
17-
}: GetMoveToAddressableAreaForDropTipCommandText): string {
10+
}: HandlesCommands<MoveToAddressableAreaForDropTipRunTimeCommand>): string {
1811
const addressableAreaDisplayName =
1912
commandTextData != null
2013
? getAddressableAreaDisplayName(commandTextData, command.id, t)

app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToAddressableAreaCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { getAddressableAreaDisplayName } from '../../../utils'
22

33
import type { MoveToAddressableAreaRunTimeCommand } from '@opentrons/shared-data/command'
4-
import type { GetCommandText } from '..'
5-
6-
type GetMoveToAddressableAreaCommandText = Omit<GetCommandText, 'command'> & {
7-
command: MoveToAddressableAreaRunTimeCommand
8-
}
4+
import type { HandlesCommands } from './types'
95

106
export function getMoveToAddressableAreaCommandText({
117
command,
128
commandTextData,
139
t,
14-
}: GetMoveToAddressableAreaCommandText): string {
10+
}: HandlesCommands<MoveToAddressableAreaRunTimeCommand>): string {
1511
const addressableAreaDisplayName =
1612
commandTextData != null
1713
? getAddressableAreaDisplayName(commandTextData, command.id, t)

app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToCoordinatesCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import type { MoveToCoordinatesRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
3-
4-
type GetMoveToCoordinatesCommandText = Omit<GetCommandText, 'command'> & {
5-
command: MoveToCoordinatesRunTimeCommand
6-
}
2+
import type { HandlesCommands } from './types'
73

84
export function getMoveToCoordinatesCommandText({
95
command,
106
t,
11-
}: GetMoveToCoordinatesCommandText): string {
7+
}: HandlesCommands<MoveToCoordinatesRunTimeCommand>): string {
128
const { coordinates } = command.params
139

1410
return t('move_to_coordinates', coordinates)

app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToSlotCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import type { MoveToSlotRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
3-
4-
type GetMoveToSlotCommandText = Omit<GetCommandText, 'command'> & {
5-
command: MoveToSlotRunTimeCommand
6-
}
2+
import type { HandlesCommands } from './types'
73

84
export function getMoveToSlotCommandText({
95
command,
106
t,
11-
}: GetMoveToSlotCommandText): string {
7+
}: HandlesCommands<MoveToSlotRunTimeCommand>): string {
128
const { slotName } = command.params
139

1410
return t('move_to_slot', { slot_name: slotName })

app/src/molecules/Command/hooks/useCommandTextString/utils/getMoveToWellCommandText.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
import type { MoveToWellRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
31
import {
42
getFinalLabwareLocation,
53
getLabwareDisplayLocation,
64
getLabwareName,
75
} from '../../../utils'
8-
import type { TFunction } from 'i18next'
96

10-
type GetMoveToWellCommandText = Omit<GetCommandText, 'command'> & {
11-
command: MoveToWellRunTimeCommand
12-
}
7+
import type { TFunction } from 'i18next'
8+
import type { MoveToWellRunTimeCommand } from '@opentrons/shared-data/command'
9+
import type { HandlesCommands } from './types'
1310

1411
export function getMoveToWellCommandText({
1512
command,
1613
t,
1714
commandTextData,
1815
robotType,
19-
}: GetMoveToWellCommandText): string {
16+
}: HandlesCommands<MoveToWellRunTimeCommand>): string {
2017
const { wellName, labwareId } = command.params
2118
const allPreviousCommands = commandTextData?.commands.slice(
2219
0,

app/src/molecules/Command/hooks/useCommandTextString/utils/getPrepareToAspirateCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { getPipetteNameSpecs } from '@opentrons/shared-data'
22

33
import type { PrepareToAspirateRunTimeCommand } from '@opentrons/shared-data/command'
4-
import type { GetCommandText } from '..'
5-
6-
type GetPrepareToAspirateCommandText = Omit<GetCommandText, 'command'> & {
7-
command: PrepareToAspirateRunTimeCommand
8-
}
4+
import type { HandlesCommands } from './types'
95

106
export function getPrepareToAspirateCommandText({
117
command,
128
commandTextData,
139
t,
14-
}: GetPrepareToAspirateCommandText): string {
10+
}: HandlesCommands<PrepareToAspirateRunTimeCommand>): string {
1511
const { pipetteId } = command.params
1612
const pipetteName = commandTextData?.pipettes.find(
1713
pip => pip.id === pipetteId

app/src/molecules/Command/hooks/useCommandTextString/utils/getTCRunProfileCommandText.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import type { TCRunProfileRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText, GetCommandTextResult } from '..'
3-
4-
type GetTCRunProfileCommandText = Omit<GetCommandText, 'command'> & {
5-
command: TCRunProfileRunTimeCommand
6-
}
2+
import type { GetCommandTextResult } from '..'
3+
import type { HandlesCommands } from './types'
74

85
export function getTCRunProfileCommandText({
96
command,
107
t,
11-
}: GetTCRunProfileCommandText): GetCommandTextResult {
8+
}: HandlesCommands<TCRunProfileRunTimeCommand>): GetCommandTextResult {
129
const { profile } = command.params
1310

1411
const stepTexts = profile.map(

app/src/molecules/Command/hooks/useCommandTextString/utils/getTemperatureCommandText.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import type {
44
TCSetTargetBlockTemperatureCreateCommand,
55
TCSetTargetLidTemperatureCreateCommand,
66
HeaterShakerSetTargetTemperatureCreateCommand,
7+
RunTimeCommand,
78
} from '@opentrons/shared-data'
8-
import type { GetCommandText } from '..'
9+
import type { HandlesCommands } from './types'
910

1011
export type TemperatureCreateCommand =
1112
| TemperatureModuleSetTargetTemperatureCreateCommand
@@ -24,9 +25,12 @@ const T_KEYS_BY_COMMAND_TYPE: {
2425
'heaterShaker/setTargetTemperature': 'setting_hs_temp',
2526
}
2627

27-
type GetTemperatureCommandText = Omit<GetCommandText, 'command'> & {
28-
command: TemperatureCreateCommand
29-
}
28+
type HandledCommands = Extract<
29+
RunTimeCommand,
30+
{ commandType: keyof typeof T_KEYS_BY_COMMAND_TYPE }
31+
>
32+
33+
type GetTemperatureCommandText = HandlesCommands<HandledCommands>
3034

3135
export const getTemperatureCommandText = ({
3236
command,

app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForDurationCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import type { WaitForDurationRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
3-
4-
type GetWaitForDurationCommandText = Omit<GetCommandText, 'command'> & {
5-
command: WaitForDurationRunTimeCommand
6-
}
2+
import type { HandlesCommands } from './types'
73

84
export function getWaitForDurationCommandText({
95
command,
106
t,
11-
}: GetWaitForDurationCommandText): string {
7+
}: HandlesCommands<WaitForDurationRunTimeCommand>): string {
128
const { seconds, message } = command.params
139

1410
return t('wait_for_duration', { seconds, message: message ?? '' })

app/src/molecules/Command/hooks/useCommandTextString/utils/getWaitForResumeCommandText.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import type { WaitForResumeRunTimeCommand } from '@opentrons/shared-data/command'
2-
import type { GetCommandText } from '..'
3-
4-
type GetWaitForResumeCommandText = Omit<GetCommandText, 'command'> & {
5-
command: WaitForResumeRunTimeCommand
6-
}
2+
import type { HandlesCommands } from './types'
73

84
export function getWaitForResumeCommandText({
95
command,
106
t,
11-
}: GetWaitForResumeCommandText): string {
7+
}: HandlesCommands<WaitForResumeRunTimeCommand>): string {
128
return command.params?.message != null && command.params.message !== ''
139
? command.params.message
1410
: t('wait_for_resume')

0 commit comments

Comments
 (0)