Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
f12ce1f0
Commit
f12ce1f0
authored
Dec 09, 2024
by
Yoelis Acourt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add wrapper component and warning
parent
6f699f82
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
UseFeatureFlag.js
src/Gargantext/Hooks/UseFeatureFlag.js
+2
-0
UseFeatureFlag.purs
src/Gargantext/Hooks/UseFeatureFlag.purs
+31
-3
No files found.
src/Gargantext/Hooks/UseFeatureFlag.js
View file @
f12ce1f0
...
...
@@ -9,8 +9,10 @@ export const _useFeatureFlag = function useFeatureFlag(cookieKeys) {
const
[
isFeatureEnabled
,
setIsFeatureEnabled
]
=
useState
(
checkFeatureFlag
);
useEffect
(()
=>
{
const
hasEnabledFlag
=
checkFeatureFlag
();
isFeatureEnabled
&&
console
.
error
(
"Warning: feature flags are in use"
);
if
(
isFeatureEnabled
!==
hasEnabledFlag
)
{
setIsFeatureEnabled
(
hasEnabledFlag
);
...
...
src/Gargantext/Hooks/UseFeatureFlag.purs
View file @
f12ce1f0
module Gargantext.Hooks.UseFeatureFlag where
import Prelude
import Effect (Effect)
import Effect.Uncurried (runEffectFn1, EffectFn1)
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
foreign import _useFeatureFlag :: EffectFn1 (Array String) Boolean
here :: R2.Here
here = R2.here "Gargantext.Hooks.UseFeatureFlag"
{-
useFeatureFlag is a custom React hook that determines whether a feature flag is enabled based on the presence and value of specific cookies.
It checks the cookies provided as keys and returns true if any of them are set to 'true'. Otherwise, it returns false.
This hook is useful for conditional rendering of features based on user-specific settings or feature toggles managed via cookies.
This hook is useful for conditional rendering of features based on user-specific feature toggles managed via cookies.
Usage :
parentCpt :: R.Component ()
parentCpt = here.component "container" cpt
where
...
...
@@ -24,3 +30,25 @@ parentCpt = here.component "container" cpt
useFeatureFlag :: Array String -> R.Hooks Boolean
useFeatureFlag keys =
R.unsafeHooksEffect $ runEffectFn1 _useFeatureFlag keys
type FeatureProps =
( render :: Boolean -> R.Element
, keys :: Array String
)
{-
Use feature component two wrap your component behind a feature flag.
It might be cleaner to use it instead of directly using the useFeatureFlag hook
Usage:
feature { keys: [ "keyOne" ], render: \shouldRender -> if shouldRender then H.text "hello" else H.text "you cant see me" }
-}
feature :: R2.Leaf (FeatureProps)
feature =
( \{ keys, render } _ -> do
shouldRender <- useFeatureFlag keys
pure $
render shouldRender
)
# R.hooksComponent "flagged"
# R2.leaf
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment