Skip to content

Commit

Permalink
fix(app): ensure current run id is one created before issuing commands (
Browse files Browse the repository at this point in the history
  • Loading branch information
smb2268 authored Aug 24, 2023
1 parent f11a7b7 commit ba49933
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 22 deletions.
40 changes: 34 additions & 6 deletions app/src/organisms/GripperWizardFlows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,52 @@ export function GripperWizardFlows(
isLoading: isCommandLoading,
} = useCreateMaintenanceCommandMutation()

const [createdMaintenanceRunId, setCreatedMaintenanceRunId] = React.useState<
string | null
>(null)

// we should start checking for run deletion only after the maintenance run is created
// and the useCurrentRun poll has returned that created id
const [
monitorMaintenanceRunForDeletion,
setMonitorMaintenanceRunForDeletion,
] = React.useState<boolean>(false)

const {
createMaintenanceRun,
isLoading: isCreateLoading,
} = useCreateMaintenanceRunMutation()
} = useCreateMaintenanceRunMutation({
onSuccess: response => {
setCreatedMaintenanceRunId(response.data.id)
},
})

const { data: maintenanceRunData } = useCurrentMaintenanceRun({
refetchInterval: RUN_REFETCH_INTERVAL,
enabled: createdMaintenanceRunId != null,
})
const prevMaintenanceRunId = React.useRef<string | undefined>(
maintenanceRunData?.data.id
)

// this will close the modal in case the run was deleted by the terminate
// activity modal on the ODD
React.useEffect(() => {
if (maintenanceRunData?.data.id == null && prevMaintenanceRunId != null) {
if (
createdMaintenanceRunId !== null &&
maintenanceRunData?.data.id === createdMaintenanceRunId
) {
setMonitorMaintenanceRunForDeletion(true)
}
if (
maintenanceRunData?.data.id !== createdMaintenanceRunId &&
monitorMaintenanceRunForDeletion
) {
closeFlow()
}
}, [maintenanceRunData?.data.id, closeFlow])
}, [
maintenanceRunData?.data.id,
createdMaintenanceRunId,
monitorMaintenanceRunForDeletion,
closeFlow,
])

const [isExiting, setIsExiting] = React.useState<boolean>(false)
const [errorMessage, setErrorMessage] = React.useState<null | string>(null)
Expand Down
38 changes: 32 additions & 6 deletions app/src/organisms/ModuleWizardFlows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,19 @@ export const ModuleWizardFlows = (
currentStepIndex !== totalStepCount ? 0 : currentStepIndex
)
}
const [createdMaintenanceRunId, setCreatedMaintenanceRunId] = React.useState<
string | null
>(null)
// we should start checking for run deletion only after the maintenance run is created
// and the useCurrentRun poll has returned that created id
const [
monitorMaintenanceRunForDeletion,
setMonitorMaintenanceRunForDeletion,
] = React.useState<boolean>(false)

const { data: maintenanceRunData } = useCurrentMaintenanceRun({
refetchInterval: RUN_REFETCH_INTERVAL,
enabled: createdMaintenanceRunId != null,
})
const {
chainRunCommands,
Expand All @@ -65,18 +76,33 @@ export const ModuleWizardFlows = (
const {
createMaintenanceRun,
isLoading: isCreateLoading,
} = useCreateMaintenanceRunMutation()
} = useCreateMaintenanceRunMutation({
onSuccess: response => {
setCreatedMaintenanceRunId(response.data.id)
},
})

const prevMaintenanceRunId = React.useRef<string | undefined>(
maintenanceRunData?.data.id
)
// this will close the modal in case the run was deleted by the terminate
// activity modal on the ODD
React.useEffect(() => {
if (maintenanceRunData?.data.id == null && prevMaintenanceRunId != null) {
if (
createdMaintenanceRunId !== null &&
maintenanceRunData?.data.id === createdMaintenanceRunId
) {
setMonitorMaintenanceRunForDeletion(true)
}
if (
maintenanceRunData?.data.id !== createdMaintenanceRunId &&
monitorMaintenanceRunForDeletion
) {
closeFlow()
}
}, [maintenanceRunData, closeFlow])
}, [
maintenanceRunData?.data.id,
createdMaintenanceRunId,
monitorMaintenanceRunForDeletion,
closeFlow,
])

const [errorMessage, setErrorMessage] = React.useState<null | string>(null)
const [isExiting, setIsExiting] = React.useState<boolean>(false)
Expand Down
44 changes: 34 additions & 10 deletions app/src/organisms/PipetteWizardFlows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ export const PipetteWizardFlows = (
attachedPipettes: memoizedAttachedPipettes,
pipetteInfo: memoizedPipetteInfo,
})
const [createdMaintenanceRunId, setCreatedMaintenanceRunId] = React.useState<
string | null
>(null)
// we should start checking for run deletion only after the maintenance run is created
// and the useCurrentRun poll has returned that created id
const [
monitorMaintenanceRunForDeletion,
setMonitorMaintenanceRunForDeletion,
] = React.useState<boolean>(false)

const goBack = (): void => {
setCurrentStepIndex(
Expand All @@ -106,14 +115,9 @@ export const PipetteWizardFlows = (
}
const { data: maintenanceRunData } = useCurrentMaintenanceRun({
refetchInterval: RUN_REFETCH_INTERVAL,
enabled: createdMaintenanceRunId != null,
})
const prevMaintenanceRunId = React.useRef<string | undefined>(
maintenanceRunData?.data.id
)

React.useEffect(() => {
prevMaintenanceRunId.current = maintenanceRunData?.data.id
}, [maintenanceRunData?.data.id])
const {
chainRunCommands,
isCommandMutationLoading,
Expand All @@ -122,15 +126,36 @@ export const PipetteWizardFlows = (
const {
createMaintenanceRun,
isLoading: isCreateLoading,
} = useCreateMaintenanceRunMutation({}, host)
} = useCreateMaintenanceRunMutation(
{
onSuccess: response => {
setCreatedMaintenanceRunId(response.data.id)
},
},
host
)

// this will close the modal in case the run was deleted by the terminate
// activity modal on the ODD
React.useEffect(() => {
if (maintenanceRunData?.data.id == null && prevMaintenanceRunId != null) {
if (
createdMaintenanceRunId !== null &&
maintenanceRunData?.data.id === createdMaintenanceRunId
) {
setMonitorMaintenanceRunForDeletion(true)
}
if (
maintenanceRunData?.data.id !== createdMaintenanceRunId &&
monitorMaintenanceRunForDeletion
) {
closeFlow()
}
}, [maintenanceRunData, closeFlow])
}, [
maintenanceRunData?.data.id,
createdMaintenanceRunId,
monitorMaintenanceRunForDeletion,
closeFlow,
])

const [errorMessage, setShowErrorMessage] = React.useState<null | string>(
null
Expand Down Expand Up @@ -191,7 +216,6 @@ export const PipetteWizardFlows = (
}, [isCommandMutationLoading, isExiting])

let chainMaintenanceRunCommands

if (maintenanceRunData?.data.id != null) {
chainMaintenanceRunCommands = (
commands: CreateCommand[],
Expand Down

0 comments on commit ba49933

Please sign in to comment.