Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app): migrate useHomePipettes to local-resources #16544

Open
wants to merge 3 commits into
base: edge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 0 additions & 80 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 './useGripperDisplayName'
export * from './useHomePipettes'
export * from './usePipetteModelSpecs'
export * from './usePipetteNameSpecs'
export * from './usePipetteSpecsv2'
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
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useRobotControlCommands } from '/app/resources/maintenance_runs'

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

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

interface UseHomePipettesResult {
export interface UseHomePipettesResult {
isHoming: UseRobotControlCommandsResult['isExecuting']
homePipettes: UseRobotControlCommandsResult['executeCommands']
}
Expand All @@ -15,7 +16,7 @@ export type UseHomePipettesProps = Pick<
UseRobotControlCommandsProps,
'pipetteInfo' | 'onSettled'
>
// TODO(jh, 09-12-24): Find a better place for this hook to live.

// Home pipettes except for plungers.
export function useHomePipettes(
props: UseHomePipettesProps
Expand Down
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 }
}
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 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import {
} from '@opentrons/components'

import { TextOnlyButton } from '/app/atoms/buttons'
import { useHomePipettes } from '/app/organisms/DropTipWizardFlows'
import { useHomePipettes } from '/app/local-resources/instruments'

import type { PipetteData } from '@opentrons/api-client'
import type { IconProps } from '@opentrons/components'
import type {
UseHomePipettesProps,
TipAttachmentStatusResult,
} from '/app/organisms/DropTipWizardFlows'
import type { UseHomePipettesProps } from '/app/local-resources/instruments'
import type { TipAttachmentStatusResult } from '/app/organisms/DropTipWizardFlows'

type UseProtocolDropTipModalProps = Pick<
UseHomePipettesProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { renderHook, act, screen, fireEvent } from '@testing-library/react'

import { renderWithProviders } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'
import { useHomePipettes } from '/app/organisms/DropTipWizardFlows'
import { useHomePipettes } from '/app/local-resources/instruments'
import {
useProtocolDropTipModal,
ProtocolDropTipModal,
} from '../ProtocolDropTipModal'

import type { Mock } from 'vitest'

vi.mock('/app/organisms/DropTipWizardFlows')
vi.mock('/app/local-resources/instruments')

describe('useProtocolDropTipModal', () => {
let props: Parameters<typeof useProtocolDropTipModal>[0]
Expand Down
5 changes: 3 additions & 2 deletions app/src/organisms/DropTipWizardFlows/TipsAttachedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import { FLEX_ROBOT_TYPE } from '@opentrons/shared-data'
import { SmallButton } from '/app/atoms/buttons'
import { OddModal } from '/app/molecules/OddModal'
import { DropTipWizardFlows, useDropTipWizardFlows } from '.'
import { useHomePipettes } from './hooks'
import { useHomePipettes } from '/app/local-resources/instruments'

import type { HostConfig } from '@opentrons/api-client'
import type { OddModalHeaderBaseProps } from '/app/molecules/OddModal/types'
import type { UseHomePipettesProps, PipetteWithTip } from './hooks'
import type { UseHomePipettesProps } from '/app/local-resources/instruments'
import type { PipetteWithTip } from './hooks'
import type { PipetteDetails } from '/app/resources/maintenance_runs'

type TipsAttachedModalProps = Pick<UseHomePipettesProps, 'onSettled'> & {
Expand Down
1 change: 0 additions & 1 deletion app/src/organisms/DropTipWizardFlows/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './errors'
export * from './useDropTipWithType'
export * from './useHomePipettes'
export * from './useTipAttachmentStatus'
export * from './useDropTipLocations'
export { useDropTipRouting } from './useDropTipRouting'
Expand Down
8 changes: 2 additions & 6 deletions app/src/organisms/DropTipWizardFlows/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export * from './DropTipWizardFlows'
export { useTipAttachmentStatus, useHomePipettes } from './hooks'
export { useTipAttachmentStatus } from './hooks'
export * from './TipsAttachedModal'

export type {
UseHomePipettesProps,
TipAttachmentStatusResult,
PipetteWithTip,
} from './hooks'
export type { TipAttachmentStatusResult, PipetteWithTip } from './hooks'
export type { FixitCommandTypeUtils } from './types'
Loading