Skip to content

Commit d14c146

Browse files
authored
fix(app): sync the start module setup toast and module setup between app/odd. (#19193)
Cherry pick [#19158](#19158)
1 parent 11b03e0 commit d14c146

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
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: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,35 +177,50 @@ export function useGetModulesNeedingSetupThatCanCurrentlyBeSetUp(): AttachedModu
177177
}
178178

179179
export function useModuleAttachedToast(
180-
launchModuleSetupCallback: () => void
180+
launchModuleSetupCallback: (open: boolean) => void
181181
): void {
182182
const currentlySetuppableModules = useGetModulesNeedingSetupThatCanCurrentlyBeSetUp()
183183

184184
const currentRunId = useCurrentRunId({ refetchInterval: CURRENT_RUN_POLL })
185185
const { t, i18n } = useTranslation(['module_wizard_flows', 'shared'])
186-
const { makeToast } = useToaster()
186+
const { makeToast, eatToast } = useToaster()
187187
const moduleSerials = currentlySetuppableModules.map(m => m.serialNumber)
188188
const moduleSerialsRef = useRef(moduleSerials)
189189
const runInProgress = currentRunId != null
190+
const [toastID, setToastID] = useState<string>('')
190191

191192
const [firstRun, setFirstRun] = useState<boolean>(true)
192193

193194
useEffect(() => {
194195
const newModuleSerials = difference(moduleSerials, moduleSerialsRef.current)
195196
if (!runInProgress && newModuleSerials.length > 0) {
196-
makeToast(t('module_added') as string, 'info', {
197-
buttonText: i18n.format(t('shared:close'), 'capitalize'),
198-
linkText: t('module_added_link'),
199-
onLinkClick: launchModuleSetupCallback,
200-
disableTimeout: true,
201-
displayType: 'odd',
202-
})
197+
setToastID(
198+
makeToast(t('module_added') as string, 'info', {
199+
buttonText: i18n.format(t('shared:close'), 'capitalize'),
200+
linkText: t('module_added_link'),
201+
onLinkClick: () => {
202+
launchModuleSetupCallback(true)
203+
},
204+
disableTimeout: true,
205+
displayType: 'odd',
206+
})
207+
)
203208
}
209+
204210
moduleSerialsRef.current = moduleSerials
205211
setFirstRun(false)
206212
// dont want this hook to rerun when other deps change
207213
// eslint-disable-next-line react-hooks/exhaustive-deps
208214
}, [moduleSerials, runInProgress, firstRun])
215+
216+
useEffect(() => {
217+
// Close toast if there are no new modules to setup
218+
if (toastID && currentlySetuppableModules.length === 0) {
219+
launchModuleSetupCallback(false)
220+
eatToast(toastID)
221+
setToastID('')
222+
}
223+
}, [toastID, currentlySetuppableModules])
209224
}
210225

211226
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 { useGetModulesNeedingSetupThatCanCurrentlyBeSetUp } 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 = useGetModulesNeedingSetupThatCanCurrentlyBeSetUp()
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 (showLaunchSetup || wizardFlowBaseProps.attachedModule == null) {

0 commit comments

Comments
 (0)