Merge branch 'bugfix/DE307-687' into 'release/20_0_0'

Digital PCT265 defect DE307-687: Replacement module reporting on page visibility restore.

### Summary
Fire the trackState page section updates again when the page becomes visible.

### JIRA Ticket
https://onejira.verizon.com/browse/DE307-687

See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/-/merge_requests/1132
This commit is contained in:
Hedden, Kyle Matthew 2024-06-18 16:35:15 +00:00
commit 1d2098c44c

View File

@ -20,7 +20,7 @@ public class ReplaceableMoleculeBehaviorModel: PageBehaviorModelProtocol {
}
}
public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, CoreLogging {
public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, PageVisibilityBehavior, CoreLogging {
public var loggingPrefix: String {
"\(self) \(ObjectIdentifier(self).hashValue) \(moleculeIds.prefix(3)) \(moleculeIds.count > 3 ? "+ \(moleculeIds.count - 3) more" : ""):\n"
@ -30,6 +30,8 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, Co
String(describing: Self.self)
}
var isPageShowing = false
var previouslyReplacedIds = Set<String>()
var moleculeIds: [String]
public var modulesToListenFor: [String]
private var observingForResponses: NSObjectProtocol?
@ -75,7 +77,7 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, Co
return rootMolecule
}
debugLog("top replacing \(rootMolecule) with \(updatedMolecule)")
logUpdated(molecule: updatedMolecule)
logUpdated(moleculeId: updatedMolecule.id)
changeList.append(updatedMolecule)
return updatedMolecule
}
@ -92,7 +94,7 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, Co
return
}
debugLog("deep replacing \(replacedMolecule) with \(newMolecule)")
logUpdated(molecule: newMolecule)
logUpdated(moleculeId: newMolecule.id)
changeList.append(newMolecule)
}
} catch {
@ -111,15 +113,29 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, Co
return hasReplacement ? updatedRootMolecules : nil
}
private func logUpdated(molecule: MoleculeModelProtocol) {
guard let module: [AnyHashable: Any] = delegateObject?.moleculeDelegate?.getModuleWithName(molecule.id),
private func logUpdated(moleculeId: String) {
guard let module: [AnyHashable: Any] = delegateObject?.moleculeDelegate?.getModuleWithName(moleculeId),
let viewController = delegateObject?.moleculeDelegate as? MVMCoreViewControllerProtocol else {
debugLog("Missing the originating module \(molecule.id) creating this molecule!")
debugLog("Missing the originating module \(moleculeId) creating this molecule!")
return
}
previouslyReplacedIds.insert(moleculeId)
guard isPageShowing else { return } // Page has not been made visible yet. (Pulled and replaced from cache on load or background update.) Hold reporting until onPageShown.
MVMCoreUILoggingHandler.shared()?.defaultLogPageUpdate(forController: viewController, from: module)
}
public func onPageShown(_ delegateObject: MVMCoreUIDelegateObject?) {
isPageShowing = true
debugLog("Page shown. Send molecule analytics for: \(previouslyReplacedIds)")
previouslyReplacedIds.forEach { id in
logUpdated(moleculeId: id)
}
}
public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) {
isPageShowing = false
}
deinit {
debugLog("deinit")
}