|
| 1 | +import { useTranslation } from 'react-i18next' |
| 2 | +import * as utils from './utils' |
| 3 | + |
| 4 | +import type { TFunction } from 'i18next' |
| 5 | +import type { RunTimeCommand } from '@opentrons/shared-data/command' |
| 6 | +import type { RobotType } from '@opentrons/shared-data/lib/js' |
| 7 | +import type { CommandTextData } from '../../types' |
| 8 | + |
| 9 | +export interface UseCommandTextStringParams { |
| 10 | + command: RunTimeCommand | null |
| 11 | + commandTextData: CommandTextData | null |
| 12 | + robotType: RobotType |
| 13 | +} |
| 14 | + |
| 15 | +export type GetCommandText = UseCommandTextStringParams & { t: TFunction } |
| 16 | +export interface GetCommandTextResult { |
| 17 | + /* The actual command text. Ex "Homing all gantry, pipette, and plunger axes" */ |
| 18 | + commandText: string |
| 19 | + /* The TC run profile steps. */ |
| 20 | + stepTexts?: string[] |
| 21 | +} |
| 22 | + |
| 23 | +// TODO(jh, 07-18-24): Move the testing that covers this from CommandText to a new file, and verify that all commands are |
| 24 | +// properly tested. |
| 25 | + |
| 26 | +// Get the full user-facing command text string from a given command. |
| 27 | +export function useCommandTextString( |
| 28 | + params: UseCommandTextStringParams |
| 29 | +): GetCommandTextResult { |
| 30 | + const { command } = params |
| 31 | + const { t } = useTranslation('protocol_command_text') |
| 32 | + |
| 33 | + const fullParams = { ...params, t } |
| 34 | + |
| 35 | + switch (command?.commandType) { |
| 36 | + case 'touchTip': |
| 37 | + case 'home': |
| 38 | + case 'savePosition': |
| 39 | + case 'magneticModule/engage': |
| 40 | + case 'magneticModule/disengage': |
| 41 | + case 'temperatureModule/deactivate': |
| 42 | + case 'thermocycler/waitForBlockTemperature': |
| 43 | + case 'thermocycler/waitForLidTemperature': |
| 44 | + case 'thermocycler/openLid': |
| 45 | + case 'thermocycler/closeLid': |
| 46 | + case 'thermocycler/deactivateBlock': |
| 47 | + case 'thermocycler/deactivateLid': |
| 48 | + case 'thermocycler/awaitProfileComplete': |
| 49 | + case 'heaterShaker/deactivateHeater': |
| 50 | + case 'heaterShaker/openLabwareLatch': |
| 51 | + case 'heaterShaker/closeLabwareLatch': |
| 52 | + case 'heaterShaker/deactivateShaker': |
| 53 | + case 'heaterShaker/waitForTemperature': |
| 54 | + return { |
| 55 | + commandText: utils.getDirectTranslationCommandText(fullParams), |
| 56 | + } |
| 57 | + |
| 58 | + case 'aspirate': |
| 59 | + case 'aspirateInPlace': |
| 60 | + case 'dispense': |
| 61 | + case 'dispenseInPlace': |
| 62 | + case 'blowout': |
| 63 | + case 'blowOutInPlace': |
| 64 | + case 'dropTip': |
| 65 | + case 'dropTipInPlace': |
| 66 | + case 'pickUpTip': |
| 67 | + return { |
| 68 | + commandText: utils.getPipettingCommandText(fullParams), |
| 69 | + } |
| 70 | + |
| 71 | + case 'loadLabware': |
| 72 | + case 'loadPipette': |
| 73 | + case 'loadModule': |
| 74 | + case 'loadLiquid': |
| 75 | + return { |
| 76 | + commandText: utils.getLoadCommandText(fullParams), |
| 77 | + } |
| 78 | + |
| 79 | + case 'temperatureModule/setTargetTemperature': |
| 80 | + case 'temperatureModule/waitForTemperature': |
| 81 | + case 'thermocycler/setTargetBlockTemperature': |
| 82 | + case 'thermocycler/setTargetLidTemperature': |
| 83 | + case 'heaterShaker/setTargetTemperature': |
| 84 | + return { |
| 85 | + commandText: utils.getTemperatureCommandText({ |
| 86 | + ...fullParams, |
| 87 | + command, |
| 88 | + }), |
| 89 | + } |
| 90 | + |
| 91 | + case 'thermocycler/runProfile': |
| 92 | + return utils.getTCRunProfileCommandText({ ...fullParams, command }) |
| 93 | + |
| 94 | + case 'heaterShaker/setAndWaitForShakeSpeed': |
| 95 | + return { |
| 96 | + commandText: utils.getHSShakeSpeedCommandText({ |
| 97 | + ...fullParams, |
| 98 | + command, |
| 99 | + }), |
| 100 | + } |
| 101 | + |
| 102 | + case 'moveToSlot': |
| 103 | + return { |
| 104 | + commandText: utils.getMoveToSlotCommandText({ ...fullParams, command }), |
| 105 | + } |
| 106 | + |
| 107 | + case 'moveRelative': |
| 108 | + return { |
| 109 | + commandText: utils.getMoveRelativeCommandText({ |
| 110 | + ...fullParams, |
| 111 | + command, |
| 112 | + }), |
| 113 | + } |
| 114 | + |
| 115 | + case 'moveToCoordinates': |
| 116 | + return { |
| 117 | + commandText: utils.getMoveToCoordinatesCommandText({ |
| 118 | + ...fullParams, |
| 119 | + command, |
| 120 | + }), |
| 121 | + } |
| 122 | + |
| 123 | + case 'moveToWell': |
| 124 | + return { |
| 125 | + commandText: utils.getMoveToWellCommandText({ ...fullParams, command }), |
| 126 | + } |
| 127 | + |
| 128 | + case 'moveLabware': |
| 129 | + return { |
| 130 | + commandText: utils.getMoveLabwareCommandText({ |
| 131 | + ...fullParams, |
| 132 | + command, |
| 133 | + }), |
| 134 | + } |
| 135 | + |
| 136 | + case 'configureForVolume': |
| 137 | + return { |
| 138 | + commandText: utils.getConfigureForVolumeCommandText({ |
| 139 | + ...fullParams, |
| 140 | + command, |
| 141 | + }), |
| 142 | + } |
| 143 | + |
| 144 | + case 'configureNozzleLayout': |
| 145 | + return { |
| 146 | + commandText: utils.getConfigureNozzleLayoutCommandText({ |
| 147 | + ...fullParams, |
| 148 | + command, |
| 149 | + }), |
| 150 | + } |
| 151 | + |
| 152 | + case 'prepareToAspirate': |
| 153 | + return { |
| 154 | + commandText: utils.getPrepareToAspirateCommandText({ |
| 155 | + ...fullParams, |
| 156 | + command, |
| 157 | + }), |
| 158 | + } |
| 159 | + |
| 160 | + case 'moveToAddressableArea': |
| 161 | + return { |
| 162 | + commandText: utils.getMoveToAddressableAreaCommandText({ |
| 163 | + ...fullParams, |
| 164 | + command, |
| 165 | + }), |
| 166 | + } |
| 167 | + |
| 168 | + case 'moveToAddressableAreaForDropTip': |
| 169 | + return { |
| 170 | + commandText: utils.getMoveToAddressableAreaForDropTipCommandText({ |
| 171 | + ...fullParams, |
| 172 | + command, |
| 173 | + }), |
| 174 | + } |
| 175 | + |
| 176 | + case 'waitForDuration': |
| 177 | + return { |
| 178 | + commandText: utils.getWaitForDurationCommandText({ |
| 179 | + ...fullParams, |
| 180 | + command, |
| 181 | + }), |
| 182 | + } |
| 183 | + |
| 184 | + case 'pause': // legacy pause command |
| 185 | + case 'waitForResume': |
| 186 | + return { |
| 187 | + commandText: utils.getWaitForResumeCommandText({ |
| 188 | + ...fullParams, |
| 189 | + command, |
| 190 | + }), |
| 191 | + } |
| 192 | + |
| 193 | + case 'delay': |
| 194 | + return { |
| 195 | + commandText: utils.getDelayCommandText({ ...fullParams, command }), |
| 196 | + } |
| 197 | + |
| 198 | + case 'comment': |
| 199 | + return { |
| 200 | + commandText: utils.getCommentCommandText({ ...fullParams, command }), |
| 201 | + } |
| 202 | + |
| 203 | + case 'custom': |
| 204 | + return { |
| 205 | + commandText: utils.getCustomCommandText({ ...fullParams, command }), |
| 206 | + } |
| 207 | + |
| 208 | + case null: |
| 209 | + return { commandText: '' } |
| 210 | + |
| 211 | + default: |
| 212 | + console.warn( |
| 213 | + 'CommandText encountered a command with an unrecognized commandType: ', |
| 214 | + command |
| 215 | + ) |
| 216 | + return { |
| 217 | + commandText: utils.getUnknownCommandText({ ...fullParams, command }), |
| 218 | + } |
| 219 | + } |
| 220 | +} |
0 commit comments