Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: switch to translations coming from config and fix UI inconsistencies #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion KetchSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'KetchSDK'
s.version = '2.0.2'
s.version = '2.0.3'
s.summary = 'Integrated solution for user data usage consents management'
s.homepage = 'https://ketch.com'
s.license = { :type => 'Apache', :file => 'LICENSE' }
Expand Down
336 changes: 336 additions & 0 deletions Sources/KetchSDK/Core/Entities/Configuration.swift

Large diffs are not rendered by default.

339 changes: 0 additions & 339 deletions Sources/KetchSDK/Core/Entities/Strings.swift

This file was deleted.

44 changes: 10 additions & 34 deletions Sources/KetchSDK/Core/Ketch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public final class Ketch: ObservableObject {

/// Configuration updates stream
@Published public var configuration: KetchSDK.Configuration?

/// Localize Strings updates stream
@Published public var localizedStrings: KetchSDK.LocalizedStrings?

/// Consent updates stream
@Published public var consent: KetchSDK.ConsentStatus?
Expand All @@ -45,7 +42,6 @@ public final class Ketch: ObservableObject {
private var plugins = Set<PolicyPlugin>()

private var configurationSubject = CurrentValueSubject<KetchSDK.Configuration?, KetchSDK.KetchError>(nil)
private var localizedStringsSubject = CurrentValueSubject<KetchSDK.LocalizedStrings?, KetchSDK.KetchError>(nil)
private var consentSubject = CurrentValueSubject<KetchSDK.ConsentStatus?, KetchSDK.KetchError>(nil)
private var subscriptions = Set<AnyCancellable>()

Expand Down Expand Up @@ -85,16 +81,6 @@ public final class Ketch: ObservableObject {
}
}
.store(in: &subscriptions)

localizedStringsSubject
.replaceError(with: nil)
.compactMap { $0 }
.sink { localizedStrings in
DispatchQueue.main.async {
self.localizedStrings = localizedStrings
}
}
.store(in: &subscriptions)

consentSubject
.replaceError(with: nil)
Expand Down Expand Up @@ -122,16 +108,16 @@ public final class Ketch: ObservableObject {
self.configurationSubject.send(configuration)
}
.store(in: &subscriptions)
KetchApiRequest()
.fetchLocalizedStrings()
.sink { result in
if case .failure(let error) = result {
self.localizedStringsSubject.send(completion: .failure(error))
}
} receiveValue: { localizedStrings in
self.localizedStringsSubject.send(localizedStrings)
}
.store(in: &subscriptions)
//KetchApiRequest()
// .fetchLocalizedStrings()
// .sink { result in
// if case .failure(let error) = result {
// self.localizedStringsSubject.send(completion: .failure(error))
// }
// } receiveValue: { localizedStrings in
// self.localizedStringsSubject.send(localizedStrings)
// }
// .store(in: &subscriptions)
}

public func loadConfiguration(
Expand All @@ -154,16 +140,6 @@ public final class Ketch: ObservableObject {
self.configurationSubject.send(configuration)
}
.store(in: &subscriptions)
KetchApiRequest()
.fetchLocalizedStrings(languageCode:String(Locale.preferredLanguages[0].prefix(2)))
.sink { result in
if case .failure(let error) = result {
self.localizedStringsSubject.send(completion: .failure(error))
}
} receiveValue: { localizedStrings in
self.localizedStringsSubject.send(localizedStrings)
}
.store(in: &subscriptions)
}

public func invokeRights(
Expand Down
12 changes: 0 additions & 12 deletions Sources/KetchSDK/Core/KetchApiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,12 @@ class KetchApiRequest {
typealias ConsentUpdate = KetchSDK.ConsentUpdate
typealias InvokeRightConfig = KetchSDK.InvokeRightConfig
typealias Vendors = KetchSDK.Vendors
typealias LocalizedStrings = KetchSDK.LocalizedStrings

private let apiClient: ApiClient

init(apiClient: ApiClient = DefaultApiClient()) {
self.apiClient = apiClient
}

func fetchLocalizedStrings(languageCode:String = String(Locale.preferredLanguages[0].prefix(2))) -> AnyPublisher<LocalizedStrings, KetchError> {
apiClient.execute(
request: ApiRequest(
endPoint: .localizedStrings(languageCode: languageCode)
)
)
.decode(type: LocalizedStrings.self, decoder: JSONDecoder())
.mapError(KetchError.init)
.eraseToAnyPublisher()
}

func fetchConfig(organization: String, property: String) -> AnyPublisher<Configuration, KetchError> {
apiClient.execute(
Expand Down
17 changes: 4 additions & 13 deletions Sources/KetchSDK/UI/KetchUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class KetchUI: ObservableObject {

/// Localized Strings updates stream
/// Reflected from Ketch dependency
@Published public var localizedStrings: KetchSDK.LocalizedStrings?
@Published public var localizedStrings: KetchSDK.Configuration.Translations?

/// Consent updates stream
/// Reflected from Ketch dependency
Expand All @@ -41,12 +41,7 @@ public final class KetchUI: ObservableObject {
ketch.$configuration
.sink { configuration in
self.configuration = configuration
}
.store(in: &subscriptions)

ketch.$localizedStrings
.sink { localizedStrings in
self.localizedStrings = localizedStrings
self.localizedStrings = configuration?.translations
}
.store(in: &subscriptions)

Expand Down Expand Up @@ -86,7 +81,6 @@ extension KetchUI {
guard
let configuration,
let consentStatus,
let localizedStrings,
let banner = configuration.experiences?.consent?.banner
else { return nil }

Expand All @@ -105,7 +99,6 @@ extension KetchUI {
guard
let configuration,
let consentStatus,
let localizedStrings,
let modal = configuration.experiences?.consent?.modal
else { return nil }

Expand All @@ -124,7 +117,6 @@ extension KetchUI {
guard
let configuration,
let consentStatus,
let localizedStrings,
let jit = configuration.experiences?.consent?.jit
else { return nil }

Expand All @@ -144,7 +136,6 @@ extension KetchUI {
guard
let configuration,
let consentStatus,
let localizedStrings,
let preference = configuration.experiences?.preference
else { return nil }

Expand Down Expand Up @@ -298,11 +289,11 @@ extension KetchUI {
switch defaultExperience {
case .banner:
if shouldShowBanner { showBanner() }
else if shouldShowPreference { showPreference() }
//else if shouldShowPreference { showPreference() }

case .modal:
if shouldShowModal { showModal() }
else if shouldShowPreference { showPreference() }
//else if shouldShowPreference { showPreference() }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ extension KetchUI.PresentationItem {
vendors: config.vendors,
purposesConsent: consent.purposes,
vendorsConsent: consent.vendors,
theme: theme.purposesListTheme
theme: theme.purposesListTheme,
purposeButtonsLookIdentical: theme.purposeButtonsLookIdentical ?? false
)

let buttonProps = Props.Button(
Expand Down Expand Up @@ -121,16 +122,20 @@ extension KetchUI.PresentationItem {

private func preference(item: ItemType.PreferenceItem) -> some View {
let theme = Props.Preference.Theme(with: config.theme)

let hideConsentTitle = item.config.consents.hideConsentTitle ?? false

let purposesProps = Props.PurposesList(
bodyTitle: item.config.consents.bodyTitle ?? String(),
bodyDescription: item.config.consents.bodyDescription ?? String(),
consentTitle: "Purposes",
consentTitle: hideConsentTitle ? nil : (item.localizedStrings?.purposes ?? "Purposes"),
hideLegalBases: item.config.consents.hideLegalBases ?? false,
purposes: config.purposes,
vendors: config.vendors,
purposesConsent: consent.purposes,
vendorsConsent: consent.vendors,
theme: theme.purposesListTheme
theme: theme.purposesListTheme,
purposeButtonsLookIdentical: theme.purposeButtonsLookIdentical ?? false
)


Expand Down
18 changes: 9 additions & 9 deletions Sources/KetchSDK/UI/PresentationItem/PresentationItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension KetchUI {
let itemType: ItemType
let config: KetchSDK.Configuration
let consent: KetchSDK.ConsentStatus
let localizedStrings: KetchSDK.LocalizedStrings
let localizedStrings: KetchSDK.Configuration.Translations?

public var id: String { String(describing: itemType) }
}
Expand All @@ -31,7 +31,7 @@ extension KetchUI.PresentationItem.ItemType {
/// Internal implementation of Banner PresentationItem that contains possible actions handler
struct BannerItem {
let config: KetchSDK.Configuration.Experience.ConsentExperience.Banner
let localizedStrings: KetchSDK.LocalizedStrings
let localizedStrings: KetchSDK.Configuration.Translations?
let actionHandler: (Action) -> KetchUI.PresentationItem?

enum Action {
Expand All @@ -45,7 +45,7 @@ extension KetchUI.PresentationItem.ItemType {
/// Internal implementation of Modal PresentationItem that contains possible actions handler
struct ModalItem {
let config: KetchSDK.Configuration.Experience.ConsentExperience.Modal
let localizedStrings: KetchSDK.LocalizedStrings
let localizedStrings: KetchSDK.Configuration.Translations?
let actionHandler: (Action) -> KetchUI.PresentationItem?

enum Action {
Expand All @@ -58,7 +58,7 @@ extension KetchUI.PresentationItem.ItemType {
/// Internal implementation of Just In Time PresentationItem that contains possible actions handler
struct JitItem {
let config: KetchSDK.Configuration.Experience.ConsentExperience.JIT
let localizedStrings: KetchSDK.LocalizedStrings
let localizedStrings: KetchSDK.Configuration.Translations?
let purpose: KetchSDK.Configuration.Purpose
let actionHandler: (Action) -> KetchUI.PresentationItem?

Expand All @@ -73,7 +73,7 @@ extension KetchUI.PresentationItem.ItemType {
/// Internal implementation of Preference PresentationItem that contains possible actions handler
struct PreferenceItem {
let config: KetchSDK.Configuration.PreferenceExperience
let localizedStrings: KetchSDK.LocalizedStrings
let localizedStrings: KetchSDK.Configuration.Translations?
let actionHandler: (Action) -> KetchUI.PresentationItem?

enum Action {
Expand All @@ -97,7 +97,7 @@ extension KetchUI.PresentationItem {
static func banner(
bannerConfig: KetchSDK.Configuration.Experience.ConsentExperience.Banner,
config: KetchSDK.Configuration,
localizedStrings: KetchSDK.LocalizedStrings,
localizedStrings: KetchSDK.Configuration.Translations?,
consent: KetchSDK.ConsentStatus,
actionHandler: @escaping (ItemType.BannerItem.Action) -> KetchUI.PresentationItem?
) -> Self {
Expand Down Expand Up @@ -125,7 +125,7 @@ extension KetchUI.PresentationItem {
static func modal(
modalConfig: KetchSDK.Configuration.Experience.ConsentExperience.Modal,
config: KetchSDK.Configuration,
localizedStrings: KetchSDK.LocalizedStrings,
localizedStrings: KetchSDK.Configuration.Translations?,
consent: KetchSDK.ConsentStatus,
actionHandler: @escaping (ItemType.ModalItem.Action) -> KetchUI.PresentationItem?
) -> Self {
Expand Down Expand Up @@ -153,7 +153,7 @@ extension KetchUI.PresentationItem {
static func preference(
preferenceConfig: KetchSDK.Configuration.PreferenceExperience,
config: KetchSDK.Configuration,
localizedStrings: KetchSDK.LocalizedStrings,
localizedStrings: KetchSDK.Configuration.Translations?,
consent: KetchSDK.ConsentStatus,
actionHandler: @escaping (ItemType.PreferenceItem.Action) -> KetchUI.PresentationItem?
) -> Self {
Expand Down Expand Up @@ -182,7 +182,7 @@ extension KetchUI.PresentationItem {
static func jit(
jitConfig: KetchSDK.Configuration.Experience.ConsentExperience.JIT,
config: KetchSDK.Configuration,
localizedStrings: KetchSDK.LocalizedStrings,
localizedStrings: KetchSDK.Configuration.Translations?,
purpose: KetchSDK.Configuration.Purpose,
consent: KetchSDK.ConsentStatus,
actionHandler: @escaping (ItemType.JitItem.Action) -> KetchUI.PresentationItem?
Expand Down
19 changes: 10 additions & 9 deletions Sources/KetchSDK/UI/Views/Banner/BannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct BannerView: View {
}
.foregroundColor(props.theme.contentColor)
}

TitleDescriptionSection(
props: props.titleDescriptionSectionProps
) { action in
Expand All @@ -43,24 +43,25 @@ struct BannerView: View {
}
}
.padding(.bottom, 12)


if let primaryButton = props.primaryButton {
CustomButton(props: primaryButton) {
self.handle(action: .primary)
}
}

if let secondaryButton = props.secondaryButton {
CustomButton(props: secondaryButton) {
self.handle(action: .secondary)
}
}

HStack {
LogoSection(textContent: props.localizedStrings.poweredBy)
.foregroundColor(props.theme.contentColor)
Spacer()
if (props.theme.showWatermark) {
HStack {
LogoSection(textContent: props.localizedStrings?.poweredBy ?? "Powered By")
.foregroundColor(props.theme.contentColor)
Spacer()
}
}
}
.padding(24)
Expand Down
4 changes: 3 additions & 1 deletion Sources/KetchSDK/UI/Views/Banner/Props+Banner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Props {
let primaryButton: Button?
let secondaryButton: Button?
let theme: Theme
let localizedStrings: KetchSDK.LocalizedStrings
let localizedStrings: KetchSDK.Configuration.Translations?

struct Theme {
let titleFontSize: CGFloat = 20
Expand All @@ -26,6 +26,8 @@ extension Props {
let buttonColor: Color
let secondaryButtonColor: Color
let secondaryButtonVariant: String

let showWatermark: Bool
}
}
}
2 changes: 1 addition & 1 deletion Sources/KetchSDK/UI/Views/JIT/JitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct JitView: View {
}

HStack {
LogoSection(textContent: props.localizedStrings.poweredBy)
LogoSection(textContent: props.localizedStrings?.poweredBy ?? "Powered by")
.foregroundColor(props.theme.headerTextColor)
Spacer()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/KetchSDK/UI/Views/JIT/Props+Jit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension Props {
let moreInfoText: String?
let moreInfoDestinationEnabled: Bool
let theme: Theme
let localizedStrings: KetchSDK.LocalizedStrings
let localizedStrings: KetchSDK.Configuration.Translations?

struct Theme {
let titleFontSize: CGFloat = 20
Expand Down
11 changes: 6 additions & 5 deletions Sources/KetchSDK/UI/Views/Modal/ModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ struct ModalView: View {
presentationMode.wrappedValue.dismiss()
}
}

HStack {
LogoSection(textContent: props.localizedStrings.poweredBy)
.foregroundColor(props.theme.headerTextColor)
Spacer()
if (props.theme.showWatermark) {
HStack {
LogoSection(textContent: props.localizedStrings?.poweredBy ?? "Powered by")
.foregroundColor(props.theme.headerTextColor)
Spacer()
}
}
}
.padding(24)
Expand Down
Loading