Skip to content

Commit 323dfe7

Browse files
authored
fix(app): sync the start module setup toast and module setup between app/odd. (#19158)
1 parent 95b9d6e commit 323dfe7

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

app/src/App/OnDeviceDisplayApp.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ export const OnDeviceDisplayApp = (): JSX.Element => {
218218
<ProtocolReceiptToasts />
219219
{!showModuleSetupModal ? (
220220
<ModuleAttachedToasts
221-
openFlow={() => {
222-
setShowModuleSetupModal(true)
221+
openFlow={(open: boolean) => {
222+
setShowModuleSetupModal(open)
223223
}}
224224
/>
225225
) : null}
@@ -312,7 +312,11 @@ function ProtocolReceiptToasts(): null {
312312
return null
313313
}
314314

315-
function ModuleAttachedToasts({ openFlow }: { openFlow: () => void }): null {
315+
function ModuleAttachedToasts({
316+
openFlow,
317+
}: {
318+
openFlow: (open: boolean) => void
319+
}): null {
316320
useModuleAttachedToast(openFlow)
317321
return null
318322
}

app/src/App/hooks.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useContext, useEffect, useRef } from 'react'
1+
import { useCallback, useContext, useEffect, useRef, useState } from 'react'
22
import { useTranslation } from 'react-i18next'
33
import { useQueryClient } from 'react-query'
44
import { useDispatch } from 'react-redux'
@@ -152,34 +152,49 @@ export function useGetNewModules(): AttachedModule[] {
152152
}
153153

154154
export function useModuleAttachedToast(
155-
launchModuleSetupCallback: () => void
155+
launchModuleSetupCallback: (open: boolean) => void
156156
): void {
157157
const newModules = useGetNewModules()
158158
const currentRunId = useCurrentRunId({ refetchInterval: CURRENT_RUN_POLL })
159159
const attachedPipettes = useAttachedPipettes(newModules.length > 0)
160160
const { t, i18n } = useTranslation(['module_wizard_flows', 'shared'])
161-
const { makeToast } = useToaster()
161+
const { makeToast, eatToast } = useToaster()
162162
const moduleSerials = newModules.map(m => m.serialNumber)
163163
const moduleSerialsRef = useRef(moduleSerials)
164164
const runInProgress = currentRunId != null
165+
const [toastID, setToastID] = useState<string>('')
165166

166167
useEffect(() => {
167168
const newModuleSerials = difference(moduleSerials, moduleSerialsRef.current)
168169
const hasPipette =
169170
attachedPipettes.left != null || attachedPipettes.right != null
170171
if (!runInProgress && hasPipette && newModuleSerials.length > 0) {
171-
makeToast(t('module_added') as string, 'info', {
172-
buttonText: i18n.format(t('shared:close'), 'capitalize'),
173-
linkText: t('module_added_link'),
174-
onLinkClick: launchModuleSetupCallback,
175-
disableTimeout: true,
176-
displayType: 'odd',
177-
})
172+
setToastID(
173+
makeToast(t('module_added') as string, 'info', {
174+
buttonText: i18n.format(t('shared:close'), 'capitalize'),
175+
linkText: t('module_added_link'),
176+
onLinkClick: () => {
177+
launchModuleSetupCallback(true)
178+
},
179+
disableTimeout: true,
180+
displayType: 'odd',
181+
})
182+
)
178183
}
184+
179185
moduleSerialsRef.current = moduleSerials
180186
// dont want this hook to rerun when other deps change
181187
// eslint-disable-next-line react-hooks/exhaustive-deps
182188
}, [moduleSerials, runInProgress])
189+
190+
useEffect(() => {
191+
// Close toast if there are no new modules to setup
192+
if (toastID && newModules.length === 0) {
193+
launchModuleSetupCallback(false)
194+
eatToast(toastID)
195+
setToastID('')
196+
}
197+
}, [toastID, newModules])
183198
}
184199

185200
export function useScrollRef(): {

app/src/organisms/ModuleWizardFlows/index.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { COLORS, LegacyStyledText } from '@opentrons/components'
55
import { useModulesQuery } from '@opentrons/react-api-client'
66
import { getModuleDisplayName } from '@opentrons/shared-data'
77

8+
import { useGetNewModules } from '/app/App/hooks'
89
import {
910
SimpleWizardBody,
1011
SimpleWizardInProgressBody,
@@ -65,13 +66,6 @@ export function ModuleWizardFlows(
6566
deckConfig,
6667
} = useModuleSetupWizard({ closeFlow, attachedModuleOnLaunch, onComplete })
6768

68-
// build out flow if there is a module passed in at launch
69-
useEffect(() => {
70-
if (attachedModuleOnLaunch != null) {
71-
buildFlowForSelectedModule(attachedModuleOnLaunch)
72-
}
73-
}, [])
74-
7569
const sendIdentifyStacker = useSendIdentifyStacker()
7670
const [selectedModule, setSelectedModule] = useState<AttachedModule | null>(
7771
null
@@ -87,6 +81,21 @@ export function ModuleWizardFlows(
8781
enabled: wizardFlowBaseProps.attachedModule != null,
8882
})?.data?.data ?? []
8983

84+
// build out flow if there is a module passed in at launch
85+
useEffect(() => {
86+
if (attachedModuleOnLaunch != null) {
87+
buildFlowForSelectedModule(attachedModuleOnLaunch)
88+
}
89+
}, [])
90+
91+
// Close the modal if no new modules are attached
92+
const newModules = useGetNewModules()
93+
useEffect(() => {
94+
if (newModules.length === 0 && wizardFlowBaseProps.attachedModule == null) {
95+
handleCleanUpAndClose()
96+
}
97+
}, [newModules, wizardFlowBaseProps])
98+
9099
const doorStatus = useIsDoorOpen(robotName).isDoorOpen
91100

92101
if (wizardFlowBaseProps.attachedPipette == null) return null

0 commit comments

Comments
 (0)