-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a UI for toggling developer feature flags (#18602)
- Loading branch information
Showing
11 changed files
with
129 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 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 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,5 @@ | ||
(ns status-im.contexts.preview.feature-flags.style) | ||
|
||
(def container | ||
{:flex 1 | ||
:margin-left 20}) |
This file contains 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,39 @@ | ||
(ns status-im.contexts.preview.feature-flags.view | ||
(:require | ||
[clojure.string :as string] | ||
[quo.core :as quo] | ||
[re-frame.core :as rf] | ||
[react-native.core :as rn] | ||
[status-im.contexts.preview.feature-flags.style :as style] | ||
[status-im.feature-flags :as ff])) | ||
|
||
(defn view | ||
[] | ||
[rn/view {:style {:flex 1}} | ||
[quo/page-nav | ||
{:type :title | ||
:text-align :left | ||
:title "Features Flags" | ||
:icon-name :i/arrow-left | ||
:on-press #(rf/dispatch [:navigate-back])}] | ||
(doall | ||
(for [context-name ff/feature-flags-categories | ||
:let [context-flags (filter (fn [[k]] | ||
(string/includes? (str k) context-name)) | ||
(ff/feature-flags))]] | ||
^{:key (str context-name)} | ||
[rn/view {:style style/container} | ||
[quo/text | ||
context-name] | ||
(doall | ||
(for [i (range (count context-flags)) | ||
:let [[flag] (nth context-flags i)]] | ||
^{:key (str context-name flag i)} | ||
[rn/view {:style {:flex-direction :row}} | ||
[quo/selectors | ||
{:type :toggle | ||
:checked? (ff/enabled? flag) | ||
:container-style {:margin-right 8} | ||
:on-change #(ff/toggle flag)}] | ||
[quo/text (second (string/split (name flag) "."))]]))]))]) | ||
|
This file contains 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 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 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 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 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 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,37 @@ | ||
(ns status-im.feature-flags | ||
(:require | ||
[clojure.string :as string] | ||
[react-native.config :as config] | ||
[reagent.core :as reagent])) | ||
|
||
(defn- enabled-in-env? | ||
[k] | ||
(= "1" (config/get-config k))) | ||
|
||
(defonce ^:private feature-flags-config | ||
(reagent/atom | ||
{::wallet.edit-default-keypair (enabled-in-env? :FLAG_EDIT_DEFAULT_KEYPAIR_ENABLED) | ||
::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED) | ||
::wallet.remove-account (enabled-in-env? :FLAG_REMOVE_ACCOUNT_ENABLED)})) | ||
|
||
(defn feature-flags [] @feature-flags-config) | ||
|
||
(def feature-flags-categories | ||
(set (map | ||
(fn [k] | ||
(first (string/split (str (name k)) "."))) | ||
(keys @feature-flags-config)))) | ||
|
||
(defn enabled? | ||
[flag] | ||
(get (feature-flags) flag)) | ||
|
||
(defn toggle | ||
[flag] | ||
(swap! feature-flags-config update flag not)) | ||
|
||
(defn alert | ||
[flag action] | ||
(if (enabled? flag) | ||
(action) | ||
(js/alert (str flag " is currently feature flagged off")))) |
This file contains 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