From be797aaee246d51f1da0a8be9f64f91f7cb98d82 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Mon, 17 Jun 2024 19:21:19 -0400 Subject: [PATCH 1/2] Digital PCT265 defect DE307-687: Re-log all analytics on page state return. --- .../ReplaceableMoleculeBehaviorModel.swift | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift index 9cbf85ed..8b624a7b 100644 --- a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift +++ b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift @@ -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 hasPreviouslyBeenShown = false + var previouslyReplacedIds = Set() 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,28 @@ 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) MVMCoreUILoggingHandler.shared()?.defaultLogPageUpdate(forController: viewController, from: module) } + public func onPageShown(_ delegateObject: MVMCoreUIDelegateObject?) { + guard hasPreviouslyBeenShown else { + // Skip first replacement build handled in onPageNew. (Pulled and reported from cache.) + hasPreviouslyBeenShown = true + return + } + debugLog("Page reshown. Resend replaced molecule analytics for: \(previouslyReplacedIds)") + previouslyReplacedIds.forEach { id in + logUpdated(moleculeId: id) + } + } + deinit { debugLog("deinit") } From 10c63a52b972da383980778dd30cc16a37ca0c97 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Mon, 17 Jun 2024 19:43:47 -0400 Subject: [PATCH 2/2] Digital PCT265 defect DE307-687: Slightly better logging clarity, making sure the base page is logged before the module counterparts. --- .../ReplaceableMoleculeBehaviorModel.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift index 8b624a7b..c35a5d19 100644 --- a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift +++ b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift @@ -30,7 +30,7 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, Pa String(describing: Self.self) } - var hasPreviouslyBeenShown = false + var isPageShowing = false var previouslyReplacedIds = Set() var moleculeIds: [String] public var modulesToListenFor: [String] @@ -120,21 +120,22 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, Pa 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?) { - guard hasPreviouslyBeenShown else { - // Skip first replacement build handled in onPageNew. (Pulled and reported from cache.) - hasPreviouslyBeenShown = true - return - } - debugLog("Page reshown. Resend replaced molecule analytics for: \(previouslyReplacedIds)") + 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") }