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

Add isReturningUser and isPrivacyProEligible targets and modularize target management #5277

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

aitorvs
Copy link
Collaborator

@aitorvs aitorvs commented Nov 15, 2024

Task/Issue URL: https://app.asana.com/0/1198194956794324/1208710375047087/f

Description

This PR adds couple new targets for FF, ie. isReturningUser and isPrivacyProEligible, both of type Boolean

The PR also modularizes the way we hande targets, turning them into plugins so that it's easier in the future to add targets without (almost) touching the toggles API

Steps to test this PR

Feature 1

  • [ ]
  • [ ]

Copy link
Collaborator Author

aitorvs commented Nov 15, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

}

// In the remote config, targets is a list, but it should not be. So we pick the first one (?)
if (!containsAndMatchCohortTargets(targets.firstOrNull())) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was certainly wrong before, but we never added more than one target so far so 🤷

@nalcalag nalcalag self-assigned this Nov 15, 2024
Comment on lines +89 to +106
@ContributesMultibinding(AppScope::class)
class LocaleToggleTargetMatcher @Inject constructor(
private val appBuildConfig: AppBuildConfig,
) : TargetMatcherPlugin {
override fun matchesTargetProperty(target: Target): Boolean {
val country = appBuildConfig.deviceLocale.country.lowercase()
val language = appBuildConfig.deviceLocale.language.lowercase()

val isCountryMatching = target.localeCountry?.let {
country == it.lowercase()
} ?: true
val isLanguageMatching = target.localeLanguage?.let {
language == it.lowercase()
} ?: true

return isCountryMatching && isLanguageMatching
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this logic, I realised we only support one language and one country as a target. If we wanted to test multiple languages, it wouldn’t work, right? Shouldn't it be an array instead of a String?
cc/ @marcosholgado

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it supports multiple languages, targets is an array already, i.e.

"targets": [
{
"variantKey": "mh"
},
{
"variantKey": "mp"
}
]

) : TargetMatcherPlugin {
override fun matchesTargetProperty(target: Target): Boolean {
return target.isPrivacyProEligible?.let { isPrivacyProEligible ->
// runBlocking sucks I know :shrug:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

Copy link
Contributor

@nalcalag nalcalag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works as expected 💯 I added a question but it is not related to this PR so feel free to merge it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants