Repository navigation
feat(MSDK-4229): add tab-targeted showSecondLayer to the React Native bridge #262
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
Open
islameldesoky95
wants to merge
1
commit into
master
Choose a base branch
from
feat/MSDK-4229-tab-targeted-show-second-layer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import com.facebook.react.bridge.Promise | |
| import com.usercentrics.reactnative.extensions.toWritableMap | ||
| import com.usercentrics.sdk.* | ||
| import com.usercentrics.sdk.errors.UsercentricsError | ||
| import com.usercentrics.sdk.models.settings.SecondLayerTab | ||
|
|
||
| interface UsercentricsProxy { | ||
|
|
||
|
|
@@ -21,7 +22,7 @@ interface UsercentricsProxy { | |
| onSubscribeClicked: (String?) -> Unit, | ||
| promise: Promise, | ||
| ) | ||
| fun showSecondLayer(activity: Activity, bannerSettings: BannerSettings?, promise: Promise) | ||
| fun showSecondLayer(activity: Activity, bannerSettings: BannerSettings?, tab: SecondLayerTab?, promise: Promise) | ||
| } | ||
|
|
||
| internal class UsercentricsProxyImpl : UsercentricsProxy { | ||
|
|
@@ -59,9 +60,10 @@ internal class UsercentricsProxyImpl : UsercentricsProxy { | |
| override fun showSecondLayer( | ||
| activity: Activity, | ||
| bannerSettings: BannerSettings?, | ||
| tab: SecondLayerTab?, | ||
| promise: Promise, | ||
| ) { | ||
| UsercentricsBanner(activity, bannerSettings).showSecondLayer { | ||
| UsercentricsBanner(activity, bannerSettings).showSecondLayer(tab) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The pinned Assessment: 🔴 Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** android/src/main/java/com/usercentrics/reactnative/api/UsercentricsProxy.kt
**Line:** 66:66
**Comment:**
*Api Mismatch: The pinned `usercentrics-ui` 2.34.0 artifact lacks this tab overload, so Android builds fail when compiling this call.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| promise.resolve(it?.toWritableMap()) | ||
| } | ||
| } | ||
|
|
||
15 changes: 15 additions & 0 deletions
15
android/src/main/java/com/usercentrics/reactnative/extensions/SecondLayerTabExtensions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.usercentrics.reactnative.extensions | ||
|
|
||
| import com.facebook.react.bridge.ReadableMap | ||
| import com.facebook.react.bridge.ReadableType | ||
| import com.usercentrics.sdk.models.settings.SecondLayerTab | ||
|
|
||
| // The tab travels inside the options map. A missing, null, non-string or unknown value falls back | ||
| // to the default tab, like a tab the layout does not have. | ||
| internal fun ReadableMap?.secondLayerTab(): SecondLayerTab? { | ||
| if (this == null || !hasKey("tab") || getType("tab") != ReadableType.String) { | ||
| return null | ||
| } | ||
| val value = getString("tab") ?: return null | ||
| return runCatching { SecondLayerTab.valueOf(value) }.getOrNull() | ||
| } |
51 changes: 51 additions & 0 deletions
51
...oid/src/test/java/com/usercentrics/reactnative/extensions/SecondLayerTabExtensionsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.usercentrics.reactnative.extensions | ||
|
|
||
| import com.facebook.react.bridge.JavaOnlyMap | ||
| import com.usercentrics.sdk.models.settings.SecondLayerTab | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Test | ||
|
|
||
| class SecondLayerTabExtensionsTest { | ||
|
|
||
| @Test | ||
| fun `secondLayerTab maps SERVICES and PARTNERS`() { | ||
| assertEquals(SecondLayerTab.SERVICES, JavaOnlyMap().apply { putString("tab", "SERVICES") }.secondLayerTab()) | ||
| assertEquals(SecondLayerTab.PARTNERS, JavaOnlyMap().apply { putString("tab", "PARTNERS") }.secondLayerTab()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `secondLayerTab keeps the banner settings keys independent of the tab`() { | ||
| val map = JavaOnlyMap().apply { | ||
| putString("variant", "A") | ||
| putString("tab", "PARTNERS") | ||
| } | ||
|
|
||
| assertEquals(SecondLayerTab.PARTNERS, map.secondLayerTab()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `secondLayerTab falls back to the default tab for a null map`() { | ||
| val map: JavaOnlyMap? = null | ||
|
|
||
| assertNull(map.secondLayerTab()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `secondLayerTab falls back to the default tab for a missing key`() { | ||
| assertNull(JavaOnlyMap().secondLayerTab()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `secondLayerTab falls back to the default tab for a null value`() { | ||
| assertNull(JavaOnlyMap().apply { putNull("tab") }.secondLayerTab()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `secondLayerTab falls back to the default tab for an unknown or non-string value`() { | ||
| assertNull(JavaOnlyMap().apply { putString("tab", "UNKNOWN") }.secondLayerTab()) | ||
| assertNull(JavaOnlyMap().apply { putString("tab", "services") }.secondLayerTab()) | ||
| assertNull(JavaOnlyMap().apply { putInt("tab", 1) }.secondLayerTab()) | ||
| assertNull(JavaOnlyMap().apply { putBoolean("tab", true) }.secondLayerTab()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import Foundation | ||
| import Usercentrics | ||
|
|
||
| extension SecondLayerTab { | ||
| // An unknown or missing value falls back to the default tab, like a tab the layout does not have. | ||
| static func from(enumString: String?) -> SecondLayerTab? { | ||
| switch enumString { | ||
| case "SERVICES": | ||
| return SecondLayerTab.services | ||
| case "PARTNERS": | ||
| return SecondLayerTab.partners | ||
| default: | ||
| return nil | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** | ||
| * A tab of the second layer that can be opened directly. | ||
| * | ||
| * - `services`: the Services tab of GDPR and CCPA layouts. | ||
| * - `partners`: the Vendors tab of TCF layouts. | ||
| * | ||
| * A tab the current layout does not have, or no tab at all, opens the default tab. | ||
| */ | ||
| export enum SecondLayerTab { | ||
|
|
||
| services = "SERVICES", | ||
| partners = "PARTNERS" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: Usercentrics/react-native-sdk
Length of output: 4270
Update the fake's
showSecondLayeroverride to match the new interface signature.This PR adds the
tab: SecondLayerTab?parameter toUsercentricsProxy.showSecondLayer. The fake's override still has the old three-parameter signature, so it no longer implements the interface member. Add the parameter and its import.Two other errors in the fake predate this PR and also block compilation. The import on line 8 names a package that does not exist. The
showFirstLayeroverride also has the wrong parameter list. Both need separate fixes before the androidTest sources compile.Suggested fix
import com.usercentrics.reactnativeusercentrics.api.UsercentricsProxy +import com.usercentrics.sdk.models.settings.SecondLayerTab