From cc44b33f9db62389cccdf2cde06e3716cf9ca7ff Mon Sep 17 00:00:00 2001 From: jhugman Date: Tue, 20 Jul 2021 15:45:37 +0000 Subject: [PATCH] [fenix] Allow branch enrollment and unenrollment in Nimbus secret menu (https://github.com/mozilla-mobile/fenix/pull/20050) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../debug/res/raw/initial_experiments.json | 25 +++++++++++++------ .../fenix/nimbus/NimbusBranchesStore.kt | 8 ++++++ .../controller/NimbusBranchesController.kt | 11 ++++++-- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/src/debug/res/raw/initial_experiments.json b/app/src/debug/res/raw/initial_experiments.json index fdff360285..a255084cee 100644 --- a/app/src/debug/res/raw/initial_experiments.json +++ b/app/src/debug/res/raw/initial_experiments.json @@ -14,24 +14,33 @@ } }, { - "slug": "a1", + "slug": "fancy-settings", "ratio": 0, "feature": { "value": { - "settings-title": "settings_title", - "settings-title-punctuation": "…" + "settings-title": "Fancy Settings" }, "enabled": true, "featureId": "nimbus-validation" } }, { - "slug": "a2", + "slug": "smiley", "ratio": 0, "feature": { "value": { - "settings-title": "preferences_category_general", - "settings-title-punctuation": "!" + "settings-title-punctuation": "\uD83D\uDE03" + }, + "enabled": true, + "featureId": "nimbus-validation" + } + }, + { + "slug": "bundled-text", + "ratio": 0, + "feature": { + "value": { + "settings-title": "preferences_category_general" }, "enabled": true, "featureId": "nimbus-validation" @@ -78,11 +87,11 @@ } }, { - "slug": "treatment", + "slug": "edit-menu-icon", "ratio": 0, "feature": { "value": { - "settings-title": "Fancy Settings", + "settings-title": "preferences_category_general", "settings-icon": "ic_edit" }, "enabled": true, diff --git a/app/src/main/java/org/mozilla/fenix/nimbus/NimbusBranchesStore.kt b/app/src/main/java/org/mozilla/fenix/nimbus/NimbusBranchesStore.kt index c378686ff5..d508559d54 100644 --- a/app/src/main/java/org/mozilla/fenix/nimbus/NimbusBranchesStore.kt +++ b/app/src/main/java/org/mozilla/fenix/nimbus/NimbusBranchesStore.kt @@ -50,6 +50,11 @@ sealed class NimbusBranchesAction : Action { * @param selectedBranch The selected [Branch] slug for a Nimbus experiment. */ data class UpdateSelectedBranch(val selectedBranch: String) : NimbusBranchesAction() + + /** + * Opts out of the branches. + */ + object UpdateUnselectBranch : NimbusBranchesAction() } /** @@ -75,5 +80,8 @@ private fun nimbusBranchesFragmentStateReducer( is NimbusBranchesAction.UpdateSelectedBranch -> { state.copy(selectedBranch = action.selectedBranch) } + is NimbusBranchesAction.UpdateUnselectBranch -> { + state.copy(selectedBranch = "") + } } } diff --git a/app/src/main/java/org/mozilla/fenix/nimbus/controller/NimbusBranchesController.kt b/app/src/main/java/org/mozilla/fenix/nimbus/controller/NimbusBranchesController.kt index 0916e26df1..46ae9479f7 100644 --- a/app/src/main/java/org/mozilla/fenix/nimbus/controller/NimbusBranchesController.kt +++ b/app/src/main/java/org/mozilla/fenix/nimbus/controller/NimbusBranchesController.kt @@ -26,7 +26,14 @@ class NimbusBranchesController( ) : NimbusBranchesAdapterDelegate { override fun onBranchItemClicked(branch: Branch) { - experiments.optInWithBranch(experimentId, branch.slug) - nimbusBranchesStore.dispatch(NimbusBranchesAction.UpdateSelectedBranch(branch.slug)) + nimbusBranchesStore.dispatch( + if (experiments.getExperimentBranch(experimentId) != branch.slug) { + experiments.optInWithBranch(experimentId, branch.slug) + NimbusBranchesAction.UpdateSelectedBranch(branch.slug) + } else { + experiments.optOut(experimentId) + NimbusBranchesAction.UpdateUnselectBranch + } + ) } }