-
Notifications
You must be signed in to change notification settings - Fork 176
/
ModuleOverflowMenu.tsx
92 lines (84 loc) · 2.58 KB
/
ModuleOverflowMenu.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import * as React from 'react'
import { Flex, POSITION_RELATIVE } from '@opentrons/components'
import { MenuList } from '../../atoms/MenuList'
import { MenuItem } from '../../atoms/MenuList/MenuItem'
import { useCurrentRunId } from '../ProtocolUpload/hooks'
import {
useIsOT3,
useRunStatuses,
useIsLegacySessionInProgress,
} from '../Devices/hooks'
import { useModuleOverflowMenu } from './hooks'
import type { AttachedModule } from '../../redux/modules/types'
interface ModuleOverflowMenuProps {
module: AttachedModule
handleSlideoutClick: () => void
handleAboutClick: () => void
handleTestShakeClick: () => void
handleWizardClick: () => void
isLoadedInRun: boolean
robotName: string
runId?: string
}
export const ModuleOverflowMenu = (
props: ModuleOverflowMenuProps
): JSX.Element | null => {
const {
module,
robotName,
runId,
handleSlideoutClick,
handleAboutClick,
handleTestShakeClick,
handleWizardClick,
isLoadedInRun,
} = props
const currentRunId = useCurrentRunId()
const { isRunTerminal, isRunStill } = useRunStatuses()
const isLegacySessionInProgress = useIsLegacySessionInProgress()
const isOT3 = useIsOT3(robotName)
const isIncompatibleWithOT3 =
isOT3 && module.moduleModel === 'thermocyclerModuleV1'
let isDisabled: boolean = false
if (runId != null && isLoadedInRun) {
isDisabled = !isRunStill
} else if ((runId != null || currentRunId != null) && !isLoadedInRun) {
isDisabled = !isRunTerminal && !isLegacySessionInProgress
}
if (isIncompatibleWithOT3) {
isDisabled = true
}
const { menuOverflowItemsByModuleType } = useModuleOverflowMenu(
module,
handleAboutClick,
handleTestShakeClick,
handleWizardClick,
handleSlideoutClick,
isDisabled,
isIncompatibleWithOT3
)
return (
<Flex position={POSITION_RELATIVE}>
<MenuList>
{menuOverflowItemsByModuleType[module.moduleType].map(
(item: any, index: number) => {
return (
<React.Fragment key={`${index}_${String(module.moduleType)}`}>
<MenuItem
key={`${index}_${String(module.moduleModel)}`}
onClick={() => item.onClick(item.isSecondary)}
data-testid={`module_setting_${String(module.moduleModel)}`}
disabled={item.disabledReason || isDisabled}
whiteSpace="nowrap"
>
{item.setSetting}
</MenuItem>
{item.menuButtons}
</React.Fragment>
)
}
)}
</MenuList>
</Flex>
)
}