mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 07:29:08 -05:00
Merge pull request #2623 from penpot/niwinz-parse-frontend-features-from-flags
✨ Parse frontend features from flags
This commit is contained in:
commit
efb4b2cb7d
2 changed files with 48 additions and 32 deletions
|
@ -65,11 +65,6 @@
|
||||||
flags (sequence (map keyword) (str/words flags))]
|
flags (sequence (map keyword) (str/words flags))]
|
||||||
(flags/parse flags/default default-flags flags)))
|
(flags/parse flags/default default-flags flags)))
|
||||||
|
|
||||||
(defn- parse-features
|
|
||||||
[global]
|
|
||||||
(when-let [features-str (obj/get global "penpotFeatures")]
|
|
||||||
(map keyword (str/words features-str))))
|
|
||||||
|
|
||||||
(defn- parse-version
|
(defn- parse-version
|
||||||
[global]
|
[global]
|
||||||
(-> (obj/get global "penpotVersion")
|
(-> (obj/get global "penpotVersion")
|
||||||
|
@ -94,7 +89,6 @@
|
||||||
|
|
||||||
(def build-date (parse-build-date global))
|
(def build-date (parse-build-date global))
|
||||||
(def flags (atom (parse-flags global)))
|
(def flags (atom (parse-flags global)))
|
||||||
(def features (atom (parse-features global)))
|
|
||||||
(def version (atom (parse-version global)))
|
(def version (atom (parse-version global)))
|
||||||
(def target (atom (parse-target global)))
|
(def target (atom (parse-target global)))
|
||||||
(def browser (atom (parse-browser)))
|
(def browser (atom (parse-browser)))
|
||||||
|
|
|
@ -8,38 +8,54 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.logging :as log]
|
[app.common.logging :as log]
|
||||||
[app.config :as cfg]
|
[app.config :as cf]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
[app.util.timers :as tm]
|
||||||
|
[cuerdas.core :as str]
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
(log/set-level! :debug)
|
(log/set-level! :trace)
|
||||||
|
|
||||||
(def available-features #{:auto-layout :components-v2})
|
(def available-features
|
||||||
|
#{:auto-layout :components-v2})
|
||||||
|
|
||||||
(defn- toggle-feature
|
(defn- toggle-feature
|
||||||
[feature]
|
[feature]
|
||||||
(ptk/reify ::toggle-feature
|
(ptk/reify ::toggle-feature
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(log/debug :msg "toggle-feature"
|
(let [features (or (:features state) #{})]
|
||||||
:feature (d/name feature)
|
(if (contains? features feature)
|
||||||
:result (if (not (contains? (:features state) feature))
|
(do
|
||||||
"enabled"
|
(log/debug :hint "feature disabled" :feature (d/name feature))
|
||||||
"disabled"))
|
(assoc state :features (disj features feature)))
|
||||||
(-> state
|
(do
|
||||||
(update :features
|
(log/debug :hint "feature enabled" :feature (d/name feature))
|
||||||
(fn [features]
|
(assoc state :features (conj features feature))))))))
|
||||||
(let [features (or features #{})]
|
|
||||||
(if (contains? features feature)
|
(defn- enable-feature
|
||||||
(disj features feature)
|
[feature]
|
||||||
(conj features feature)))))))))
|
(ptk/reify ::enable-feature
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(let [features (or (:features state) #{})]
|
||||||
|
(if (contains? features feature)
|
||||||
|
state
|
||||||
|
(do
|
||||||
|
(log/debug :hint "feature enabled" :feature (d/name feature))
|
||||||
|
(assoc state :features (conj features feature))))))))
|
||||||
|
|
||||||
(defn toggle-feature!
|
(defn toggle-feature!
|
||||||
[feature]
|
[feature]
|
||||||
(assert (contains? available-features feature) "Not supported feature")
|
(assert (contains? available-features feature) "Not supported feature")
|
||||||
(st/emit! (toggle-feature feature)))
|
(tm/schedule-on-idle #(st/emit! (toggle-feature feature))))
|
||||||
|
|
||||||
|
(defn enable-feature!
|
||||||
|
[feature]
|
||||||
|
(assert (contains? available-features feature) "Not supported feature")
|
||||||
|
(tm/schedule-on-idle #(st/emit! (enable-feature feature))))
|
||||||
|
|
||||||
(defn active-feature?
|
(defn active-feature?
|
||||||
([feature]
|
([feature]
|
||||||
|
@ -62,14 +78,20 @@
|
||||||
active-feature? (mf/deref active-feature-ref)]
|
active-feature? (mf/deref active-feature-ref)]
|
||||||
active-feature?))
|
active-feature?))
|
||||||
|
|
||||||
;; Read initial enabled features from config, if set
|
;; Enable all features set on the configuration
|
||||||
(if-let [enabled-features @cfg/features]
|
(->> @cf/flags
|
||||||
(doseq [f enabled-features]
|
(map str)
|
||||||
(toggle-feature! f))
|
(keep (fn [flag]
|
||||||
|
(when (str/starts-with? flag "frontend-feature-")
|
||||||
|
(subs flag 17))))
|
||||||
|
(map keyword)
|
||||||
|
(run! enable-feature!))
|
||||||
|
|
||||||
(when *assert*
|
;; Enable the rest of available configuration if we are on development
|
||||||
;; By default, all features disabled, except in development
|
;; environemnt (aka devenv).
|
||||||
;; environment, that are enabled except components-v2
|
(when *assert*
|
||||||
(doseq [f available-features]
|
;; By default, all features disabled, except in development
|
||||||
(when (not= f :components-v2)
|
;; environment, that are enabled except components-v2
|
||||||
(toggle-feature! f)))))
|
(->> available-features
|
||||||
|
(remove #(= % :components-v2))
|
||||||
|
(run! enable-feature!)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue