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

fix(app): poll modules from protocol run module controls #14581

Merged
merged 3 commits into from
Mar 4, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export const ProtocolRunModuleControls = ({
} = usePipetteIsReady()

const moduleRenderInfoForProtocolById = useModuleRenderInfoForProtocolById(
runId
runId,
true
)
const attachedModules = Object.values(moduleRenderInfoForProtocolById).filter(
module => module.attachedModuleMatch != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('ProtocolRunModuleControls', () => {

it('renders a magnetic module card', () => {
when(mockUseModuleRenderInfoForProtocolById)
.calledWith(RUN_ID)
.calledWith(RUN_ID, true)
.mockReturnValue({
[mockMagMod.moduleId]: {
moduleId: 'magModModuleId',
Expand All @@ -102,7 +102,7 @@ describe('ProtocolRunModuleControls', () => {

it('renders a temperature module card', () => {
when(mockUseModuleRenderInfoForProtocolById)
.calledWith(RUN_ID)
.calledWith(RUN_ID, true)
.mockReturnValue({
[mockTempMod.moduleId]: {
moduleId: 'temperatureModuleId',
Expand All @@ -129,7 +129,7 @@ describe('ProtocolRunModuleControls', () => {

it('renders a thermocycler module card', () => {
when(mockUseModuleRenderInfoForProtocolById)
.calledWith(RUN_ID)
.calledWith(RUN_ID, true)
.mockReturnValue({
[mockTCModule.moduleId]: {
moduleId: mockTCModule.moduleId,
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('ProtocolRunModuleControls', () => {

it('renders a heater-shaker module card', () => {
when(mockUseModuleRenderInfoForProtocolById)
.calledWith(RUN_ID)
.calledWith(RUN_ID, true)
.mockReturnValue({
[mockHeaterShakerDef.moduleId]: {
moduleId: 'heaterShakerModuleId',
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('ProtocolRunModuleControls', () => {

it('renders correct text when module is not attached but required for protocol', () => {
when(mockUseModuleRenderInfoForProtocolById)
.calledWith(RUN_ID)
.calledWith(RUN_ID, true)
.mockReturnValue({
[mockHeaterShakerDef.moduleId]: {
moduleId: 'heaterShakerModuleId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,11 @@ describe('useModuleRenderInfoForProtocolById hook', () => {
when(mockUseDeckConfigurationQuery).mockReturnValue({
data: [mockCutoutConfig],
} as UseQueryResult<DeckConfiguration>)
when(mockUseAttachedModules)
.calledWith()
.mockReturnValue([
mockMagneticModuleGen2,
mockTemperatureModuleGen2,
mockThermocycler,
])
mockUseAttachedModules.mockReturnValue([
mockMagneticModuleGen2,
mockTemperatureModuleGen2,
mockThermocycler,
])
when(mockUseStoredProtocolAnalysis)
.calledWith('1')
.mockReturnValue((PROTOCOL_DETAILS as unknown) as ProtocolAnalysisOutput)
Expand All @@ -162,11 +160,15 @@ describe('useModuleRenderInfoForProtocolById hook', () => {
.calledWith('1')
.mockReturnValue(null)
when(mockUseStoredProtocolAnalysis).calledWith('1').mockReturnValue(null)
const { result } = renderHook(() => useModuleRenderInfoForProtocolById('1'))
const { result } = renderHook(() =>
useModuleRenderInfoForProtocolById('1', true)
)
expect(result.current).toStrictEqual({})
})
it('should return module render info', () => {
const { result } = renderHook(() => useModuleRenderInfoForProtocolById('1'))
const { result } = renderHook(() =>
useModuleRenderInfoForProtocolById('1', true)
)
expect(result.current).toStrictEqual({
magneticModuleId: {
conflictedFixture: mockCutoutConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ export interface ModuleRenderInfoById {
[moduleId: string]: ModuleRenderInfoForProtocol
}

const DECK_CONFIG_REFETCH_INTERVAL = 5000
const REFETCH_INTERVAL_5000_MS = 5000

export function useModuleRenderInfoForProtocolById(
runId: string
runId: string,
pollModules?: boolean
): ModuleRenderInfoById {
const robotProtocolAnalysis = useMostRecentCompletedAnalysis(runId)
const { data: deckConfig } = useDeckConfigurationQuery({
refetchInterval: DECK_CONFIG_REFETCH_INTERVAL,
refetchInterval: REFETCH_INTERVAL_5000_MS,
})
const storedProtocolAnalysis = useStoredProtocolAnalysis(runId)
const protocolAnalysis = robotProtocolAnalysis ?? storedProtocolAnalysis
const attachedModules = useAttachedModules()
const attachedModules = useAttachedModules({
refetchInterval: pollModules ? REFETCH_INTERVAL_5000_MS : false,
})
if (protocolAnalysis == null) return {}

const deckDef = getDeckDefFromRobotType(
Expand Down
Loading