Commit 514d1318 authored by Yoelis Acourt's avatar Yoelis Acourt

add hoc component + some utils

tosquash
parent f12ce1f0
Pipeline #7130 passed with stages
in 17 minutes and 28 seconds
......@@ -3,8 +3,11 @@ module Gargantext.Hooks.UseFeatureFlag where
import Prelude
import Effect.Uncurried (runEffectFn1, EffectFn1)
import Gargantext.Components.CodeEditor (previewPostProcess)
import Gargantext.Utils.Reactix as R2
import Reactix (hooksComponent)
import Reactix as R
import Reactix.DOM.HTML as H
foreign import _useFeatureFlag :: EffectFn1 (Array String) Boolean
......@@ -42,13 +45,18 @@ type FeatureProps =
Usage:
feature { keys: [ "keyOne" ], render: \shouldRender -> if shouldRender then H.text "hello" else H.text "you cant see me" }
-}
feature :: R2.Leaf (FeatureProps)
feature =
feature :: R2.Leaf FeatureProps
feature = R2.renderLeaf "" $
( \{ keys, render } _ -> do
shouldRender <- useFeatureFlag keys
pure $
render shouldRender
)
# R.hooksComponent "flagged"
# R2.leaf
hideBehind :: forall a. Array String -> R2.Component a -> R2.Component a
hideBehind keys cpt = R2.renderComponent "" \props children -> do
shouldRender <- useFeatureFlag keys
pure $
if shouldRender then cpt props children
else H.text ""
......@@ -72,6 +72,14 @@ component
-> R.Element
component cpt props children = R.createElement cpt props children
renderComponent :: forall a. String -> R.HooksComponent a -> (Record a -> Array R.Element -> R.Element)
renderComponent name cpt props children =
R.createElement (R.hooksComponent name cpt) props children
renderLeaf :: forall a. String -> R.HooksComponent a -> Leaf a
renderLeaf name cpt props =
renderComponent name cpt props []
leaf
:: forall cpt p
. R.IsComponent cpt p (Array R.Element)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment