From e783fee2ec9ce5c8d99c57e6e9a4d0fbb9300ece Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Thu, 28 Sep 2023 14:03:58 +0900 Subject: [PATCH] bug fix: when experimentId is alised id, repository will fetch wrong data --- .../Nativebrik_Example/ContentView.swift | 14 +------------- ios/Nativebrik/Classes/embedding.swift | 17 +++++++++++++---- ios/Nativebrik/Classes/remote-config.swift | 8 ++++++-- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/ios/Example/Nativebrik_Example/Nativebrik_Example/ContentView.swift b/ios/Example/Nativebrik_Example/Nativebrik_Example/ContentView.swift index e369c4f..2ab3872 100644 --- a/ios/Example/Nativebrik_Example/Nativebrik_Example/ContentView.swift +++ b/ios/Example/Nativebrik_Example/Nativebrik_Example/ContentView.swift @@ -131,20 +131,8 @@ Morondava is a charming coastal town located on the western coast of Madagascar. ScrollView(.vertical) { nativebrik .experiment - .embedding("cjjei1223akg00bptlh0") + .embedding("TOP_COMPONENT") .frame(width: nil, height: 270) - nativebrik - .experiment - .remoteConfigAsView("cjm5piq23akg008u0km0") { phase in - switch phase { - case .failure: - Text("error") - case .loading: - Text("loading") - case .completed(let variant): - Text(variant.getAsString("text") ?? "Not Found") - } - } ForEach(self.items, id: \.title) { item in item.padding() } diff --git a/ios/Nativebrik/Classes/embedding.swift b/ios/Nativebrik/Classes/embedding.swift index c8057e1..718bf5f 100644 --- a/ios/Nativebrik/Classes/embedding.swift +++ b/ios/Nativebrik/Classes/embedding.swift @@ -63,15 +63,19 @@ class EmbeddingUIView: ComponentUIView { self?.renderFallback(phase: .failure) return } + guard let experimentConfigId = config.id else { + self?.renderFallback(phase: .failure) + return + } repositories.track.trackExperimentEvent( TrackExperimentEvent( - experimentId: experimentId, + experimentId: experimentConfigId, variantId: variantId ) ) - self?.loadAndTransition(experimentId: experimentId, componentId: componentId) + self?.loadAndTransition(experimentId: experimentConfigId, componentId: componentId) } } } @@ -98,6 +102,7 @@ class EmbeddingSwiftViewModel: ComponentSwiftViewModel { self?.phase = .failure return } + print("hello", experimentId, configs) guard let experimentConfig = extractExperimentConfigMatchedToProperties(configs: configs, properties: { seed in return self?.user.toEventProperties(seed: seed) ?? [] }) else { @@ -121,16 +126,20 @@ class EmbeddingSwiftViewModel: ComponentSwiftViewModel { self?.phase = .failure return } + guard let experimentConfigId = experimentConfig.id else { + self?.phase = .failure + return + } repositories.track.trackExperimentEvent( TrackExperimentEvent( - experimentId: experimentId, + experimentId: experimentConfigId, variantId: variantId ) ) self?.fetchComponentAndUpdatePhase( - experimentId: experimentId, + experimentId: experimentConfigId, componentId: componentId, config: config, repositories: repositories, diff --git a/ios/Nativebrik/Classes/remote-config.swift b/ios/Nativebrik/Classes/remote-config.swift index f943fd9..ddd4fb2 100644 --- a/ios/Nativebrik/Classes/remote-config.swift +++ b/ios/Nativebrik/Classes/remote-config.swift @@ -189,16 +189,20 @@ public class RemoteConfig { phase(.failure) return } + guard let experimentConfigId = config.id else { + phase(.failure) + return + } self.repositories.track.trackExperimentEvent( TrackExperimentEvent( - experimentId: self.experimentId, + experimentId: experimentConfigId, variantId: variantId ) ) phase(.completed(RemoteConfigVariant( - experimentId: experimentId, + experimentId: experimentConfigId, variantId: variantId, configs: variantConfigs, config: self.config,