Skip to content

Commit

Permalink
feat(app): Add GET /deck_configuration notification support (#15007)
Browse files Browse the repository at this point in the history
Closes EXEC-263

Refactors GET /deck_configuration to use notifications.
  • Loading branch information
mjhuff authored Apr 25, 2024
1 parent d5484f8 commit e53226a
Show file tree
Hide file tree
Showing 37 changed files with 159 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
TYPOGRAPHY,
} from '@opentrons/components'
import {
useDeckConfigurationQuery,
useModulesQuery,
useUpdateDeckConfigurationMutation,
} from '@opentrons/react-api-client'
Expand Down Expand Up @@ -49,6 +48,7 @@ import { ODD_FOCUS_VISIBLE } from '../../atoms/buttons/constants'
import { TertiaryButton } from '../../atoms/buttons'
import { Modal } from '../../molecules/Modal'
import { LegacyModal } from '../../molecules/LegacyModal'
import { useNotifyDeckConfigurationQuery } from '../../resources/deck_configuration/'

import type {
CutoutConfig,
Expand Down Expand Up @@ -83,7 +83,7 @@ export function AddFixtureModal({
const { t } = useTranslation(['device_details', 'shared'])
const { updateDeckConfiguration } = useUpdateDeckConfigurationMutation()
const { data: modulesData } = useModulesQuery()
const deckConfig = useDeckConfigurationQuery()?.data ?? []
const deckConfig = useNotifyDeckConfigurationQuery()?.data ?? []
const unconfiguredMods =
modulesData?.data.filter(
attachedMod =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { fireEvent, screen } from '@testing-library/react'
import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'

import {
useDeckConfigurationQuery,
useModulesQuery,
useUpdateDeckConfigurationMutation,
} from '@opentrons/react-api-client'
Expand All @@ -15,12 +14,15 @@ import {
import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
import { AddFixtureModal } from '../AddFixtureModal'
import { useNotifyDeckConfigurationQuery } from '../../../resources/deck_configuration'

import type { UseQueryResult } from 'react-query'
import type { DeckConfiguration } from '@opentrons/shared-data'
import type { Modules } from '@opentrons/api-client'

vi.mock('@opentrons/react-api-client')
vi.mock('../../../resources/deck_configuration')

const mockSetShowAddFixtureModal = vi.fn()
const mockUpdateDeckConfiguration = vi.fn()
const mockSetCurrentDeckConfig = vi.fn()
Expand All @@ -44,7 +46,7 @@ describe('Touchscreen AddFixtureModal', () => {
vi.mocked(useUpdateDeckConfigurationMutation).mockReturnValue({
updateDeckConfiguration: mockUpdateDeckConfiguration,
} as any)
vi.mocked(useDeckConfigurationQuery).mockReturnValue(({
vi.mocked(useNotifyDeckConfigurationQuery).mockReturnValue(({
data: [],
} as unknown) as UseQueryResult<DeckConfiguration>)
vi.mocked(useModulesQuery).mockReturnValue(({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { describe, it, beforeEach, vi, afterEach } from 'vitest'

import { DeckConfigurator } from '@opentrons/components'
import {
useDeckConfigurationQuery,
useModulesQuery,
useUpdateDeckConfigurationMutation,
} from '@opentrons/react-api-client'
Expand All @@ -17,6 +16,7 @@ import { DeckFixtureSetupInstructionsModal } from '../DeckFixtureSetupInstructio
import { useIsEstopNotDisengaged } from '../../../resources/devices/hooks/useIsEstopNotDisengaged'
import { DeviceDetailsDeckConfiguration } from '../'
import { useNotifyCurrentMaintenanceRun } from '../../../resources/maintenance_runs'
import { useNotifyDeckConfigurationQuery } from '../../../resources/deck_configuration'

import type { MaintenanceRun } from '@opentrons/api-client'
import type * as OpentronsComponents from '@opentrons/components'
Expand All @@ -33,6 +33,7 @@ vi.mock('../DeckFixtureSetupInstructionsModal')
vi.mock('../../Devices/hooks')
vi.mock('../../../resources/maintenance_runs')
vi.mock('../../../resources/devices/hooks/useIsEstopNotDisengaged')
vi.mock('../../../resources/deck_configuration')

const ROBOT_NAME = 'otie'
const mockUpdateDeckConfiguration = vi.fn()
Expand Down Expand Up @@ -62,7 +63,9 @@ describe('DeviceDetailsDeckConfiguration', () => {
robotName: ROBOT_NAME,
}
vi.mocked(useModulesQuery).mockReturnValue({ data: { data: [] } } as any)
vi.mocked(useDeckConfigurationQuery).mockReturnValue({ data: [] } as any)
vi.mocked(useNotifyDeckConfigurationQuery).mockReturnValue({
data: [],
} as any)
vi.mocked(useUpdateDeckConfigurationMutation).mockReturnValue({
updateDeckConfiguration: mockUpdateDeckConfiguration,
} as any)
Expand Down Expand Up @@ -129,7 +132,7 @@ describe('DeviceDetailsDeckConfiguration', () => {
})

it('should render no deck fixtures, if deck configs are not set', () => {
vi.mocked(useDeckConfigurationQuery).mockReturnValue([] as any)
vi.mocked(useNotifyDeckConfigurationQuery).mockReturnValue([] as any)
render(props)
screen.getByText('No deck fixtures')
})
Expand Down
7 changes: 4 additions & 3 deletions app/src/organisms/DeviceDetailsDeckConfiguration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
TYPOGRAPHY,
} from '@opentrons/components'
import {
useDeckConfigurationQuery,
useModulesQuery,
useUpdateDeckConfigurationMutation,
} from '@opentrons/react-api-client'
Expand All @@ -43,6 +42,7 @@ import { DeckFixtureSetupInstructionsModal } from './DeckFixtureSetupInstruction
import { AddFixtureModal } from './AddFixtureModal'
import { useIsRobotViewable, useRunStatuses } from '../Devices/hooks'
import { useIsEstopNotDisengaged } from '../../resources/devices/hooks/useIsEstopNotDisengaged'
import { useNotifyDeckConfigurationQuery } from '../../resources/deck_configuration'

import type { CutoutFixtureId, CutoutId } from '@opentrons/shared-data'

Expand Down Expand Up @@ -74,8 +74,9 @@ export function DeviceDetailsDeckConfiguration({

const { data: modulesData } = useModulesQuery()
const deckConfig =
useDeckConfigurationQuery({ refetchInterval: DECK_CONFIG_REFETCH_INTERVAL })
.data ?? []
useNotifyDeckConfigurationQuery({
refetchInterval: DECK_CONFIG_REFETCH_INTERVAL,
}).data ?? []
const deckDef = getDeckDefFromRobotType(FLEX_ROBOT_TYPE)
const { updateDeckConfiguration } = useUpdateDeckConfigurationMutation()
const { isRunRunning } = useRunStatuses()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import * as React from 'react'
import { createPortal } from 'react-dom'
import { useTranslation } from 'react-i18next'
import { useHistory } from 'react-router-dom'
import {
useDeckConfigurationQuery,
useModulesQuery,
} from '@opentrons/react-api-client'
import { useModulesQuery } from '@opentrons/react-api-client'
import {
ALIGN_CENTER,
DIRECTION_COLUMN,
Expand All @@ -26,7 +23,7 @@ import { getTopPortalEl } from '../../../../App/portal'
import { LegacyModal } from '../../../../molecules/LegacyModal'
import { Modal } from '../../../../molecules/Modal'
import { FixtureOption } from '../../../DeviceDetailsDeckConfiguration/AddFixtureModal'

import { useNotifyDeckConfigurationQuery } from '../../../../resources/deck_configuration'
import { SmallButton } from '../../../../atoms/buttons'
import { useCloseCurrentRun } from '../../../ProtocolUpload/hooks'

Expand Down Expand Up @@ -65,7 +62,7 @@ export const ChooseModuleToConfigureModal = (
const { closeCurrentRun } = useCloseCurrentRun()
const attachedModules =
useModulesQuery({ refetchInterval: EQUIPMENT_POLL_MS })?.data?.data ?? []
const deckConfig = useDeckConfigurationQuery()?.data ?? []
const deckConfig = useNotifyDeckConfigurationQuery()?.data ?? []
const unconfiguredModuleMatches =
attachedModules.filter(
attachedMod =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import * as React from 'react'
import { createPortal } from 'react-dom'
import { Trans, useTranslation } from 'react-i18next'
import {
useDeckConfigurationQuery,
useUpdateDeckConfigurationMutation,
} from '@opentrons/react-api-client'
import { useUpdateDeckConfigurationMutation } from '@opentrons/react-api-client'
import {
ALIGN_CENTER,
BORDERS,
Expand All @@ -30,10 +27,12 @@ import {
getCutoutFixturesForModuleModel,
getFixtureIdByCutoutIdFromModuleSlotName,
} from '@opentrons/shared-data'

import { getTopPortalEl } from '../../../../App/portal'
import { LegacyModal } from '../../../../molecules/LegacyModal'
import { Modal } from '../../../../molecules/Modal'
import { SmallButton } from '../../../../atoms/buttons/SmallButton'
import { useNotifyDeckConfigurationQuery } from '../../../../resources/deck_configuration'

import type {
CutoutConfig,
Expand Down Expand Up @@ -71,7 +70,7 @@ export const LocationConflictModal = (
const { t, i18n } = useTranslation(['protocol_setup', 'shared'])

const [showModuleSelect, setShowModuleSelect] = React.useState(false)
const deckConfig = useDeckConfigurationQuery().data ?? []
const deckConfig = useNotifyDeckConfigurationQuery().data ?? []
const { updateDeckConfiguration } = useUpdateDeckConfigurationMutation()
const deckConfigurationAtLocationFixtureId = deckConfig.find(
(deckFixture: CutoutConfig) => deckFixture.cutoutId === cutoutId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import * as React from 'react'
import { createPortal } from 'react-dom'
import { useTranslation } from 'react-i18next'
import {
useDeckConfigurationQuery,
useUpdateDeckConfigurationMutation,
} from '@opentrons/react-api-client'
import { useUpdateDeckConfigurationMutation } from '@opentrons/react-api-client'
import {
ALIGN_CENTER,
BORDERS,
Expand All @@ -20,6 +17,7 @@ import { getFixtureDisplayName } from '@opentrons/shared-data'
import { TertiaryButton } from '../../../../atoms/buttons/TertiaryButton'
import { getTopPortalEl } from '../../../../App/portal'
import { LegacyModal } from '../../../../molecules/LegacyModal'
import { useNotifyDeckConfigurationQuery } from '../../../../resources/deck_configuration'

import type { CutoutFixtureId, CutoutId } from '@opentrons/shared-data'

Expand All @@ -35,7 +33,7 @@ export const NotConfiguredModal = (
const { onCloseClick, cutoutId, requiredFixtureId } = props
const { t, i18n } = useTranslation(['protocol_setup', 'shared'])
const { updateDeckConfiguration } = useUpdateDeckConfigurationMutation()
const deckConfig = useDeckConfigurationQuery()?.data ?? []
const deckConfig = useNotifyDeckConfigurationQuery()?.data ?? []

const handleUpdateDeck = (): void => {
const newDeckConfig = deckConfig.map(fixture =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ModuleInfo } from '../../ModuleInfo'
import { useAttachedModules, useStoredProtocolAnalysis } from '../../hooks'
import { getProtocolModulesInfo } from '../utils/getProtocolModulesInfo'
import { getStandardDeckViewLayerBlockList } from '../utils/getStandardDeckViewLayerBlockList'
import { useDeckConfigurationQuery } from '@opentrons/react-api-client'
import { useNotifyDeckConfigurationQuery } from '../../../../resources/deck_configuration'

const ATTACHED_MODULE_POLL_MS = 5000
const DECK_CONFIG_POLL_MS = 5000
Expand All @@ -35,7 +35,7 @@ export const SetupModulesMap = ({
const robotProtocolAnalysis = useMostRecentCompletedAnalysis(runId)
const storedProtocolAnalysis = useStoredProtocolAnalysis(runId)
const protocolAnalysis = robotProtocolAnalysis ?? storedProtocolAnalysis
const { data: actualDeckConfig = [] } = useDeckConfigurationQuery({
const { data: actualDeckConfig = [] } = useNotifyDeckConfigurationQuery({
refetchInterval: DECK_CONFIG_POLL_MS,
})
const attachedModules =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ import {
ot3StandardDeckV5,
} from '@opentrons/shared-data'
import {
useDeckConfigurationQuery,
useModulesQuery,
useUpdateDeckConfigurationMutation,
} from '@opentrons/react-api-client'

import { i18n } from '../../../../../i18n'
import { mockHeaterShaker } from '../../../../../redux/modules/__fixtures__'
import { useCloseCurrentRun } from '../../../../ProtocolUpload/hooks'
import { LocationConflictModal } from '../LocationConflictModal'
import { useNotifyDeckConfigurationQuery } from '../../../../../resources/deck_configuration'

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

vi.mock('@opentrons/react-api-client')
vi.mock('../../../../../resources/deck_configuration')
vi.mock('../../../../ProtocolUpload/hooks')

const mockFixture = {
Expand Down Expand Up @@ -57,7 +59,7 @@ describe('LocationConflictModal', () => {
closeCurrentRun: vi.fn(),
} as any)
vi.mocked(useModulesQuery).mockReturnValue({ data: { data: [] } } as any)
vi.mocked(useDeckConfigurationQuery).mockReturnValue({
vi.mocked(useNotifyDeckConfigurationQuery).mockReturnValue({
data: [mockFixture],
} as UseQueryResult<DeckConfiguration>)
vi.mocked(useUpdateDeckConfigurationMutation).mockReturnValue({
Expand Down Expand Up @@ -102,7 +104,7 @@ describe('LocationConflictModal', () => {
expect(mockUpdate).toHaveBeenCalled()
})
it('should render the modal information for a single slot fixture conflict', () => {
vi.mocked(useDeckConfigurationQuery).mockReturnValue({
vi.mocked(useNotifyDeckConfigurationQuery).mockReturnValue({
data: [
{
cutoutId: 'cutoutB1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { fireEvent } from '@testing-library/react'
import { describe, it, beforeEach, vi, expect } from 'vitest'
import { renderWithProviders } from '../../../../../__testing-utils__'
import { TRASH_BIN_ADAPTER_FIXTURE } from '@opentrons/shared-data'
import {
useDeckConfigurationQuery,
useUpdateDeckConfigurationMutation,
} from '@opentrons/react-api-client'
import { useUpdateDeckConfigurationMutation } from '@opentrons/react-api-client'

import { i18n } from '../../../../../i18n'
import { NotConfiguredModal } from '../NotConfiguredModal'
import { useNotifyDeckConfigurationQuery } from '../../../../../resources/deck_configuration'

import type { UseQueryResult } from 'react-query'
import type { DeckConfiguration } from '@opentrons/shared-data'

vi.mock('@opentrons/react-api-client')
vi.mock('../../../../../resources/deck_configuration')

const render = (props: React.ComponentProps<typeof NotConfiguredModal>) => {
return renderWithProviders(<NotConfiguredModal {...props} />, {
Expand All @@ -33,7 +33,7 @@ describe('NotConfiguredModal', () => {
vi.mocked(useUpdateDeckConfigurationMutation).mockReturnValue({
updateDeckConfiguration: mockUpdate,
} as any)
vi.mocked(useDeckConfigurationQuery).mockReturnValue(({
vi.mocked(useNotifyDeckConfigurationQuery).mockReturnValue(({
data: [],
} as unknown) as UseQueryResult<DeckConfiguration>)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
heater_shaker_commands_with_results_key,
} from '@opentrons/shared-data'
import { useMostRecentCompletedAnalysis } from '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis'
import { useDeckConfigurationQuery } from '@opentrons/react-api-client'

import { getProtocolModulesInfo } from '../../ProtocolRun/utils/getProtocolModulesInfo'

Expand All @@ -22,6 +21,7 @@ import {
useModuleRenderInfoForProtocolById,
useStoredProtocolAnalysis,
} from '..'
import { useNotifyDeckConfigurationQuery } from '../../../../resources/deck_configuration'

import type {
CutoutConfig,
Expand All @@ -33,11 +33,11 @@ import type {
import type { UseQueryResult } from 'react-query'
import type { AttachedModule } from '../../../../redux/modules/types'

vi.mock('@opentrons/react-api-client')
vi.mock('../../ProtocolRun/utils/getProtocolModulesInfo')
vi.mock('../useAttachedModules')
vi.mock('../useStoredProtocolAnalysis')
vi.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis')
vi.mock('../../../../resources/deck_configuration')

const heaterShakerCommandsWithResultsKey = (heater_shaker_commands_with_results_key as unknown) as ProtocolAnalysisOutput

Expand Down Expand Up @@ -113,7 +113,7 @@ const mockCutoutConfig: CutoutConfig = {

describe('useModuleRenderInfoForProtocolById hook', () => {
beforeEach(() => {
vi.mocked(useDeckConfigurationQuery).mockReturnValue({
vi.mocked(useNotifyDeckConfigurationQuery).mockReturnValue({
data: [mockCutoutConfig],
} as UseQueryResult<DeckConfiguration>)
vi.mocked(useAttachedModules).mockReturnValue([mockAttachedTempMod])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
getDeckDefFromRobotType,
OT2_ROBOT_TYPE,
} from '@opentrons/shared-data'
import { useDeckConfigurationQuery } from '@opentrons/react-api-client'

import { getProtocolModulesInfo } from '../ProtocolRun/utils/getProtocolModulesInfo'
import { useMostRecentCompletedAnalysis } from '../../LabwarePositionCheck/useMostRecentCompletedAnalysis'
import { useAttachedModules } from './useAttachedModules'
import { useStoredProtocolAnalysis } from './useStoredProtocolAnalysis'
import { useNotifyDeckConfigurationQuery } from '../../../resources/deck_configuration'

import type { CutoutConfig } from '@opentrons/shared-data'
import type { AttachedModule } from '../../../redux/modules/types'
Expand All @@ -33,7 +33,7 @@ export function useModuleRenderInfoForProtocolById(
pollModules?: boolean
): ModuleRenderInfoById {
const robotProtocolAnalysis = useMostRecentCompletedAnalysis(runId)
const { data: deckConfig = [] } = useDeckConfigurationQuery({
const { data: deckConfig = [] } = useNotifyDeckConfigurationQuery({
refetchInterval: REFETCH_INTERVAL_5000_MS,
})
const storedProtocolAnalysis = useStoredProtocolAnalysis(runId)
Expand Down
4 changes: 2 additions & 2 deletions app/src/organisms/DropTipWizard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import {
useCreateMaintenanceCommandMutation,
useDeleteMaintenanceRunMutation,
useDeckConfigurationQuery,
} from '@opentrons/react-api-client'

import { useNotifyCurrentMaintenanceRun } from '../../resources/maintenance_runs'
Expand Down Expand Up @@ -50,6 +49,7 @@ import {
useDropTipErrorComponents,
useWizardExitHeader,
} from './utils'
import { useNotifyDeckConfigurationQuery } from '../../resources/deck_configuration'

import type { PipetteData } from '@opentrons/api-client'
import type { CreateMaintenanceRunType } from '@opentrons/react-api-client'
Expand Down Expand Up @@ -82,7 +82,7 @@ export function DropTipWizard(props: MaintenanceRunManagerProps): JSX.Element {
} = useChainMaintenanceCommands()
const { createMaintenanceCommand } = useCreateMaintenanceCommandMutation()

const deckConfig = useDeckConfigurationQuery().data ?? []
const deckConfig = useNotifyDeckConfigurationQuery().data ?? []

const [createdMaintenanceRunId, setCreatedMaintenanceRunId] = React.useState<
string | null
Expand Down
Loading

0 comments on commit e53226a

Please sign in to comment.