Skip to content

Commit

Permalink
refactor(app): split local-resources/instruments/hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Oct 21, 2024
1 parent 1627096 commit e2d67e8
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 123 deletions.
123 changes: 0 additions & 123 deletions app/src/local-resources/instruments/hooks.ts

This file was deleted.

5 changes: 5 additions & 0 deletions app/src/local-resources/instruments/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './useGripperDispalyName'
export * from './useHomePipettes'
export * from './usePipetteModelSpecs'
export * from './usePipetteNameSpecs'
export * from './usePipetteSpecsv2'
19 changes: 19 additions & 0 deletions app/src/local-resources/instruments/hooks/useGripperDispalyName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { getGripperDisplayName, GRIPPER_MODELS } from '@opentrons/shared-data'
import { useIsOEMMode } from '/app/resources/robot-settings'

import type { GripperModel } from '@opentrons/shared-data'

export function useGripperDisplayName(gripperModel: GripperModel): string {
const isOEMMode = useIsOEMMode()

let brandedDisplayName = ''

// check to only call display name helper for a gripper model
if (GRIPPER_MODELS.includes(gripperModel)) {
brandedDisplayName = getGripperDisplayName(gripperModel)
}

const anonymizedDisplayName = brandedDisplayName.replace('Flex ', '')

return isOEMMode ? anonymizedDisplayName : brandedDisplayName
}
39 changes: 39 additions & 0 deletions app/src/local-resources/instruments/hooks/useHomePipettes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useRobotControlCommands } from '/app/resources/maintenance_runs'

import type { CreateCommand } from '@opentrons/shared-data'

import type {
UseRobotControlCommandsProps,
UseRobotControlCommandsResult,
} from '/app/resources/maintenance_runs'

export interface UseHomePipettesResult {
isHoming: UseRobotControlCommandsResult['isExecuting']
homePipettes: UseRobotControlCommandsResult['executeCommands']
}

export type UseHomePipettesProps = Pick<
UseRobotControlCommandsProps,
'pipetteInfo' | 'onSettled'
>

// Home pipettes except for plungers.
export function useHomePipettes(
props: UseHomePipettesProps
): UseHomePipettesResult {
const { executeCommands, isExecuting } = useRobotControlCommands({
...props,
commands: [HOME_EXCEPT_PLUNGERS],
continuePastCommandFailure: true,
})

return {
isHoming: isExecuting,
homePipettes: executeCommands,
}
}

const HOME_EXCEPT_PLUNGERS: CreateCommand = {
commandType: 'home' as const,
params: { axes: ['leftZ', 'rightZ', 'x', 'y'] },
}
24 changes: 24 additions & 0 deletions app/src/local-resources/instruments/hooks/usePipetteModelSpecs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getPipetteModelSpecs } from '@opentrons/shared-data'

import { usePipetteNameSpecs } from './usePipetteNameSpecs'

import type {
PipetteModel,
PipetteModelSpecs,
PipetteName,
} from '@opentrons/shared-data'

export function usePipetteModelSpecs(
model: PipetteModel
): PipetteModelSpecs | null {
const modelSpecificFields = getPipetteModelSpecs(model)
const pipetteNameSpecs = usePipetteNameSpecs(
modelSpecificFields?.name as PipetteName
)

if (modelSpecificFields == null || pipetteNameSpecs == null) {
return null
}

return { ...modelSpecificFields, displayName: pipetteNameSpecs.displayName }
}
26 changes: 26 additions & 0 deletions app/src/local-resources/instruments/hooks/usePipetteNameSpecs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getPipetteNameSpecs } from '@opentrons/shared-data'

import { useIsOEMMode } from '/app/resources/robot-settings'

import type { PipetteName, PipetteNameSpecs } from '@opentrons/shared-data'

export function usePipetteNameSpecs(
name: PipetteName
): PipetteNameSpecs | null {
const isOEMMode = useIsOEMMode()
const pipetteNameSpecs = getPipetteNameSpecs(name)

if (pipetteNameSpecs == null) {
return null
}

const brandedDisplayName = pipetteNameSpecs.displayName
const anonymizedDisplayName = pipetteNameSpecs.displayName.replace(
'Flex ',
''
)

const displayName = isOEMMode ? anonymizedDisplayName : brandedDisplayName

return { ...pipetteNameSpecs, displayName }
}
27 changes: 27 additions & 0 deletions app/src/local-resources/instruments/hooks/usePipetteSpecsv2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getPipetteSpecsV2 } from '@opentrons/shared-data'

import { useIsOEMMode } from '/app/resources/robot-settings'

import type {
PipetteModel,
PipetteName,
PipetteV2Specs,
} from '@opentrons/shared-data'

export function usePipetteSpecsV2(
name?: PipetteName | PipetteModel
): PipetteV2Specs | null {
const isOEMMode = useIsOEMMode()
const pipetteSpecs = getPipetteSpecsV2(name)

if (pipetteSpecs == null) {
return null
}

const brandedDisplayName = pipetteSpecs.displayName
const anonymizedDisplayName = pipetteSpecs.displayName.replace('Flex ', '')

const displayName = isOEMMode ? anonymizedDisplayName : brandedDisplayName

return { ...pipetteSpecs, displayName }
}

0 comments on commit e2d67e8

Please sign in to comment.