-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(app): split local-resources/instruments/hooks
- Loading branch information
Showing
7 changed files
with
140 additions
and
123 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
app/src/local-resources/instruments/hooks/useGripperDispalyName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
app/src/local-resources/instruments/hooks/useHomePipettes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
app/src/local-resources/instruments/hooks/usePipetteModelSpecs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
app/src/local-resources/instruments/hooks/usePipetteNameSpecs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
app/src/local-resources/instruments/hooks/usePipetteSpecsv2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |