Skip to content

Commit

Permalink
fix(app, app-shell, app-shell-odd): Fix host context for notifications (
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff authored Feb 26, 2024
1 parent 76a4b03 commit 5172fc1
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 38 deletions.
16 changes: 8 additions & 8 deletions app-shell-odd/src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ const RENDER_TIMEOUT = 10000 // 10 seconds
function unsubscribe(notifyParams: NotifyParams): Promise<void> {
const { hostname, topic } = notifyParams
return new Promise<void>(() => {
if (hostname in connectionStore) {
setTimeout(() => {
setTimeout(() => {
if (hostname in connectionStore) {
const { client } = connectionStore[hostname]
const subscriptions = connectionStore[hostname]?.subscriptions
const isLastSubscription = subscriptions[topic] <= 1
Expand All @@ -215,12 +215,12 @@ function unsubscribe(notifyParams: NotifyParams): Promise<void> {
} else {
subscriptions[topic] -= 1
}
}, RENDER_TIMEOUT)
} else {
log.info(
`Attempted to unsubscribe from unconnected hostname: ${hostname}`
)
}
} else {
log.info(
`Attempted to unsubscribe from unconnected hostname: ${hostname}`
)
}
}, RENDER_TIMEOUT)
})
}

Expand Down
16 changes: 8 additions & 8 deletions app-shell/src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ const RENDER_TIMEOUT = 10000 // 10 seconds
function unsubscribe(notifyParams: NotifyParams): Promise<void> {
const { hostname, topic } = notifyParams
return new Promise<void>(() => {
if (hostname in connectionStore) {
setTimeout(() => {
setTimeout(() => {
if (hostname in connectionStore) {
const { client } = connectionStore[hostname]
const subscriptions = connectionStore[hostname]?.subscriptions
const isLastSubscription = subscriptions[topic] <= 1
Expand All @@ -211,12 +211,12 @@ function unsubscribe(notifyParams: NotifyParams): Promise<void> {
} else {
subscriptions[topic] -= 1
}
}, RENDER_TIMEOUT)
} else {
log.info(
`Attempted to unsubscribe from unconnected hostname: ${hostname}`
)
}
} else {
log.info(
`Attempted to unsubscribe from unconnected hostname: ${hostname}`
)
}
}, RENDER_TIMEOUT)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { storedProtocolData as storedProtocolDataFixture } from '../../../redux/
import { useTrackCreateProtocolRunEvent } from '../../../organisms/Devices/hooks'
import { useCreateRunFromProtocol } from '../../ChooseRobotToRunProtocolSlideout/useCreateRunFromProtocol'
import { ChooseProtocolSlideout } from '../'
import { useNotifyService } from '../../../resources/useNotifyService'

jest.mock('../../ChooseRobotToRunProtocolSlideout/useCreateRunFromProtocol')
jest.mock('../../../redux/protocol-storage')
jest.mock('../../../organisms/Devices/hooks')
jest.mock('../../../redux/config')
jest.mock('../../../resources/useNotifyService')

const mockGetStoredProtocols = getStoredProtocols as jest.MockedFunction<
typeof getStoredProtocols
Expand All @@ -24,6 +26,9 @@ const mockUseCreateRunFromProtocol = useCreateRunFromProtocol as jest.MockedFunc
const mockUseTrackCreateProtocolRunEvent = useTrackCreateProtocolRunEvent as jest.MockedFunction<
typeof useTrackCreateProtocolRunEvent
>
const mockUseNotifyService = useNotifyService as jest.MockedFunction<
typeof useNotifyService
>

const render = (props: React.ComponentProps<typeof ChooseProtocolSlideout>) => {
return renderWithProviders(
Expand Down Expand Up @@ -52,6 +57,7 @@ describe('ChooseProtocolSlideout', () => {
mockUseTrackCreateProtocolRunEvent.mockReturnValue({
trackCreateProtocolRunEvent: mockTrackCreateProtocolRunEvent,
})
mockUseNotifyService.mockReturnValue({} as any)
})
afterEach(() => {
jest.resetAllMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import {
} from '../../../redux/discovery/__fixtures__'
import { getNetworkInterfaces } from '../../../redux/networking'
import { ChooseRobotSlideout } from '..'
import { useNotifyService } from '../../../resources/useNotifyService'

jest.mock('../../../redux/discovery')
jest.mock('../../../redux/robot-update')
jest.mock('../../../redux/networking')
jest.mock('../../../resources/useNotifyService')

const mockGetConnectableRobots = getConnectableRobots as jest.MockedFunction<
typeof getConnectableRobots
Expand All @@ -39,6 +41,9 @@ const mockStartDiscovery = startDiscovery as jest.MockedFunction<
const mockGetNetworkInterfaces = getNetworkInterfaces as jest.MockedFunction<
typeof getNetworkInterfaces
>
const mockUseNotifyService = useNotifyService as jest.MockedFunction<
typeof useNotifyService
>

const render = (props: React.ComponentProps<typeof ChooseRobotSlideout>) => {
return renderWithProviders(
Expand All @@ -61,6 +66,7 @@ describe('ChooseRobotSlideout', () => {
mockGetScanning.mockReturnValue(false)
mockStartDiscovery.mockReturnValue({ type: 'mockStartDiscovery' } as any)
mockGetNetworkInterfaces.mockReturnValue({ wifi: null, ethernet: null })
mockUseNotifyService.mockReturnValue({} as any)
})
afterEach(() => {
jest.resetAllMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { storedProtocolData as storedProtocolDataFixture } from '../../../redux/
import { useCreateRunFromProtocol } from '../useCreateRunFromProtocol'
import { useOffsetCandidatesForAnalysis } from '../../ApplyHistoricOffsets/hooks/useOffsetCandidatesForAnalysis'
import { ChooseRobotToRunProtocolSlideout } from '../'
import { useNotifyService } from '../../../resources/useNotifyService'

import type { State } from '../../../redux/types'

Expand All @@ -41,6 +42,7 @@ jest.mock('../../../redux/networking')
jest.mock('../../../redux/config')
jest.mock('../useCreateRunFromProtocol')
jest.mock('../../ApplyHistoricOffsets/hooks/useOffsetCandidatesForAnalysis')
jest.mock('../../../resources/useNotifyService')

const mockUseOffsetCandidatesForAnalysis = useOffsetCandidatesForAnalysis as jest.MockedFunction<
typeof useOffsetCandidatesForAnalysis
Expand Down Expand Up @@ -82,6 +84,9 @@ const mockUseTrackCreateProtocolRunEvent = useTrackCreateProtocolRunEvent as jes
const mockGetNetworkInterfaces = getNetworkInterfaces as jest.MockedFunction<
typeof getNetworkInterfaces
>
const mockUseNotifyService = useNotifyService as jest.MockedFunction<
typeof useNotifyService
>

const render = (
props: React.ComponentProps<typeof ChooseRobotToRunProtocolSlideout>
Expand Down Expand Up @@ -125,6 +130,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
})
mockUseCurrentRunId.mockReturnValue(null)
mockUseCurrentRunStatus.mockReturnValue(null)
mockUseNotifyService.mockReturnValue({} as any)
when(mockUseCreateRunFromProtocol)
.calledWith(
expect.any(Object),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { SetupLabwareList } from '../SetupLabwareList'
import { SetupLabwareMap } from '../SetupLabwareMap'
import { SetupLabware } from '..'
import { useNotifyRunQuery } from '../../../../../resources/runs/useNotifyRunQuery'

jest.mock('../SetupLabwareList')
jest.mock('../SetupLabwareMap')
Expand All @@ -27,6 +28,7 @@ jest.mock('../../../../RunTimeControl/hooks')
jest.mock('../../../../../redux/config')
jest.mock('../../../hooks')
jest.mock('../../../hooks/useLPCSuccessToast')
jest.mock('../../../../../resources/runs/useNotifyRunQuery')

const mockGetModuleTypesThatRequireExtraAttention = getModuleTypesThatRequireExtraAttention as jest.MockedFunction<
typeof getModuleTypesThatRequireExtraAttention
Expand Down Expand Up @@ -58,6 +60,9 @@ const mockSetupLabwareMap = SetupLabwareMap as jest.MockedFunction<
const mockUseLPCDisabledReason = useLPCDisabledReason as jest.MockedFunction<
typeof useLPCDisabledReason
>
const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction<
typeof useNotifyRunQuery
>
const ROBOT_NAME = 'otie'
const RUN_ID = '1'

Expand Down Expand Up @@ -110,6 +115,7 @@ describe('SetupLabware', () => {
<div> mock setup labware list</div>
)
when(mockUseLPCDisabledReason).mockReturnValue(null)
mockUseNotifyRunQuery.mockReturnValue({} as any)
})

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getTotalVolumePerLiquidLabwarePair,
} from '../utils'
import { LiquidsLabwareDetailsModal } from '../LiquidsLabwareDetailsModal'
import { useNotifyRunQuery } from '../../../../../resources/runs/useNotifyRunQuery'

const MOCK_LIQUIDS_IN_LOAD_ORDER = [
{
Expand Down Expand Up @@ -56,6 +57,7 @@ jest.mock('../../utils/getLocationInfoNames')
jest.mock('../LiquidsLabwareDetailsModal')
jest.mock('@opentrons/api-client')
jest.mock('../../../../../redux/analytics')
jest.mock('../../../../../resources/runs/useNotifyRunQuery')

const mockUseTrackEvent = useTrackEvent as jest.MockedFunction<
typeof useTrackEvent
Expand All @@ -78,6 +80,9 @@ const mockParseLabwareInfoByLiquidId = parseLabwareInfoByLiquidId as jest.Mocked
const mockLiquidsLabwareDetailsModal = LiquidsLabwareDetailsModal as jest.MockedFunction<
typeof LiquidsLabwareDetailsModal
>
const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction<
typeof useNotifyRunQuery
>

const render = (props: React.ComponentProps<typeof SetupLiquidsList>) => {
return renderWithProviders(<SetupLiquidsList {...props} />, {
Expand Down Expand Up @@ -107,6 +112,7 @@ describe('SetupLiquidsList', () => {
partialComponentPropsMatcher({ labwareId: '123', liquidId: '0' })
)
.mockReturnValue(<div>Mock liquids labwaqre details modal</div>)
mockUseNotifyRunQuery.mockReturnValue({} as any)
})

it('renders the total volume of the liquid, sample display name, and description', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { SetupLiquids } from '../SetupLiquids'
import { SetupModuleAndDeck } from '../SetupModuleAndDeck'
import { EmptySetupStep } from '../EmptySetupStep'
import { ProtocolRunSetup } from '../ProtocolRunSetup'
import { useNotifyRunQuery } from '../../../../resources/runs/useNotifyRunQuery'

jest.mock('@opentrons/api-client')
jest.mock('../../hooks')
Expand All @@ -56,6 +57,7 @@ jest.mock('@opentrons/shared-data/js/helpers/getSimplestFlexDeckConfig')
jest.mock('../../../../redux/config')
jest.mock('../../../../resources/deck_configuration/utils')
jest.mock('../../../../resources/deck_configuration/hooks')
jest.mock('../../../../resources/runs/useNotifyRunQuery')

const mockUseIsFlex = useIsFlex as jest.MockedFunction<typeof useIsFlex>
const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction<
Expand Down Expand Up @@ -113,6 +115,9 @@ const mockUseDeckConfigurationCompatibility = useDeckConfigurationCompatibility
const mockGetIsFixtureMismatch = getIsFixtureMismatch as jest.MockedFunction<
typeof getIsFixtureMismatch
>
const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction<
typeof useNotifyRunQuery
>

const ROBOT_NAME = 'otie'
const RUN_ID = '1'
Expand Down Expand Up @@ -184,6 +189,7 @@ describe('ProtocolRunSetup', () => {
.calledWith(ROBOT_NAME, RUN_ID)
.mockReturnValue({ missingModuleIds: [], remainingAttachedModules: [] })
when(mockGetIsFixtureMismatch).mockReturnValue(false)
mockUseNotifyRunQuery.mockReturnValue({} as any)
})
afterEach(() => {
resetAllWhenMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ import { mockTipRackDefinition } from '../../../../redux/custom-labware/__fixtur
import { useRunPipetteInfoByMount } from '../../hooks'
import { SetupPipetteCalibrationItem } from '../SetupPipetteCalibrationItem'
import { SetupInstrumentCalibration } from '../SetupInstrumentCalibration'
import { useNotifyRunQuery } from '../../../../resources/runs/useNotifyRunQuery'

import type { PipetteInfo } from '../../hooks'

jest.mock('../../hooks')
jest.mock('../SetupPipetteCalibrationItem')
jest.mock('../../../../resources/runs/useNotifyRunQuery')

const mockUseRunPipetteInfoByMount = useRunPipetteInfoByMount as jest.MockedFunction<
typeof useRunPipetteInfoByMount
>
const mockSetupPipetteCalibrationItem = SetupPipetteCalibrationItem as jest.MockedFunction<
typeof SetupPipetteCalibrationItem
>
const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction<
typeof useNotifyRunQuery
>

const ROBOT_NAME = 'otie'
const RUN_ID = '1'
Expand Down Expand Up @@ -56,6 +62,7 @@ describe('SetupPipetteCalibration', () => {
when(mockSetupPipetteCalibrationItem).mockReturnValue(
<div>Mock SetupPipetteCalibrationItem</div>
)
mockUseNotifyRunQuery.mockReturnValue({} as any)
})
afterEach(() => {
resetAllWhenMocks()
Expand Down
12 changes: 8 additions & 4 deletions app/src/organisms/DropTipWizard/TipsAttachedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,38 @@ import { StyledText } from '../../atoms/text'
import { Modal } from '../../molecules/Modal'
import { DropTipWizard } from '.'

import type { PipetteData } from '@opentrons/api-client'
import type { HostConfig, PipetteData } from '@opentrons/api-client'
import type { PipetteModelSpecs, RobotType } from '@opentrons/shared-data'
import type { ModalHeaderBaseProps } from '../../molecules/Modal/types'
import { ApiHostProvider } from '@opentrons/react-api-client'

interface TipsAttachedModalProps {
mount: PipetteData['mount']
instrumentModelSpecs: PipetteModelSpecs
robotType: RobotType
host: HostConfig | null
onCloseClick?: (arg0: any) => void
}

export const handleTipsAttachedModal = (
mount: TipsAttachedModalProps['mount'],
instrumentModelSpecs: TipsAttachedModalProps['instrumentModelSpecs'],
robotType: TipsAttachedModalProps['robotType'],
host: TipsAttachedModalProps['host'],
onCloseClick: TipsAttachedModalProps['onCloseClick']
): Promise<unknown> => {
return NiceModal.show(TipsAttachedModal, {
mount,
instrumentModelSpecs,
robotType,
host,
onCloseClick,
})
}

const TipsAttachedModal = NiceModal.create(
(props: TipsAttachedModalProps): JSX.Element => {
const { mount, onCloseClick, instrumentModelSpecs } = props
const { mount, onCloseClick, host, instrumentModelSpecs } = props
const { t } = useTranslation(['drop_tip_wizard'])
const modal = useModal()
const [showWizard, setShowWizard] = React.useState(false)
Expand All @@ -55,7 +59,7 @@ const TipsAttachedModal = NiceModal.create(
const displayMountText = is96Channel ? '96-Channel' : capitalize(mount)

return (
<>
<ApiHostProvider {...host} hostname={host?.hostname ?? null}>
<Modal header={tipsAttachedHeader}>
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing32}>
<StyledText as="p">
Expand Down Expand Up @@ -104,7 +108,7 @@ const TipsAttachedModal = NiceModal.create(
}}
/>
) : null}
</>
</ApiHostProvider>
)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { handleTipsAttachedModal } from '../TipsAttachedModal'
import { LEFT } from '@opentrons/shared-data'
import { mockPipetteInfo } from '../../../redux/pipettes/__fixtures__'
import { ROBOT_MODEL_OT3 } from '../../../redux/discovery'
import { useNotifyCurrentMaintenanceRun } from '../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun'
import { useNotifyService } from '../../../resources/useNotifyService'

import type { PipetteModelSpecs } from '@opentrons/shared-data'
import type { HostConfig } from '@opentrons/api-client'

jest.mock('../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun')
jest.mock('../../../resources/useNotifyService')

const MOCK_ACTUAL_PIPETTE = {
...mockPipetteInfo.pipetteSpecs,
Expand All @@ -24,9 +25,10 @@ const MOCK_ACTUAL_PIPETTE = {
} as PipetteModelSpecs

const mockOnClose = jest.fn()
const mockUseNotifyCurrentMaintenanceRun = useNotifyCurrentMaintenanceRun as jest.MockedFunction<
typeof useNotifyCurrentMaintenanceRun
const mockUseNotifyService = useNotifyService as jest.MockedFunction<
typeof useNotifyService
>
const MOCK_HOST: HostConfig = { hostname: 'MOCK_HOST' }

const render = (pipetteSpecs: PipetteModelSpecs) => {
return renderWithProviders(
Expand All @@ -37,6 +39,7 @@ const render = (pipetteSpecs: PipetteModelSpecs) => {
LEFT,
pipetteSpecs,
ROBOT_MODEL_OT3,
MOCK_HOST,
mockOnClose
)
}
Expand All @@ -51,7 +54,7 @@ const render = (pipetteSpecs: PipetteModelSpecs) => {

describe('TipsAttachedModal', () => {
beforeEach(() => {
mockUseNotifyCurrentMaintenanceRun.mockReturnValue({
mockUseNotifyService.mockReturnValue({
data: {
data: {
id: 'test',
Expand Down
Loading

0 comments on commit 5172fc1

Please sign in to comment.