Skip to content

Commit

Permalink
fix(app): ensure firmware takeover modal won't open uneccessarily (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
smb2268 authored Feb 2, 2024
1 parent 8ec9c41 commit 74e8c82
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions app/src/organisms/FirmwareUpdateModal/FirmwareUpdateTakeover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ export function FirmwareUpdateTakeover(): JSX.Element {
)

React.useEffect(() => {
// in case instruments are updated elsewhere in the app, clear update needed list
// when all instruments are ok but array has elements
if (
instrumentsData?.find(instrument => !instrument.ok) == null &&
!showUpdateNeededModal &&
instrumentsToUpdate.length > 0
) {
setInstrumentsToUpdate([])
setIndexToUpdate(0)
} else if (
instrumentsToUpdate.length > indexToUpdate &&
instrumentsToUpdate[indexToUpdate]?.subsystem != null &&
maintenanceRunData == null &&
Expand All @@ -72,12 +81,23 @@ export function FirmwareUpdateTakeover(): JSX.Element {
) {
setShowUpdateNeededModal(true)
}
// close modal if update is no longer needed
else if (
instrumentsData?.find(instrument => !instrument.ok) == null &&
initiatedSubsystemUpdate == null &&
showUpdateNeededModal
) {
setShowUpdateNeededModal(false)
}
}, [
instrumentsToUpdate,
externalSubsystemUpdate,
indexToUpdate,
maintenanceRunData,
instrumentsToUpdate,
initiatedSubsystemUpdate,
instrumentsData,
isUnboxingFlowOngoing,
externalSubsystemUpdate,
maintenanceRunData,
showUpdateNeededModal,
])

return (
Expand All @@ -88,10 +108,12 @@ export function FirmwareUpdateTakeover(): JSX.Element {
<UpdateNeededModal
subsystem={instrumentsToUpdate[indexToUpdate]?.subsystem}
onClose={() => {
// if no more instruments need updating, close the modal
// if no more instruments need updating, close the modal and clear data
// otherwise start over with next instrument
if (instrumentsToUpdate.length <= indexToUpdate + 1) {
setShowUpdateNeededModal(false)
setInstrumentsToUpdate([])
setIndexToUpdate(0)
} else {
setIndexToUpdate(prevIndexToUpdate => prevIndexToUpdate + 1)
}
Expand Down

0 comments on commit 74e8c82

Please sign in to comment.