-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
126 additions
and
2 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,56 @@ | ||
import RandomColor from "../RandomColor"; | ||
import { TicTacToe } from "../TicTacToe"; | ||
import Accordion from "../accordion/accordion"; | ||
import LightDarkMode from "../light-dark-mode/Light-dark-mode"; | ||
import TreeView from "../tree-view/TreeView"; | ||
import { FeatureFlagsContext } from "./context/FeatureFlagsContext"; | ||
import menus from "../tree-view/data"; | ||
import TabTest from "../tree-view/custom-tabs/Tab-test"; | ||
import { useContext } from "react"; | ||
|
||
export const FeatureFlags = () => { | ||
const { loading, enabledFlags } = useContext(FeatureFlagsContext); | ||
|
||
const componentsToRender = [ | ||
{ | ||
key: "showLightAndDarkMode", | ||
component: <LightDarkMode />, | ||
}, | ||
|
||
{ | ||
key: "showTicTacToeBoard", | ||
component: <TicTacToe />, | ||
}, | ||
{ | ||
key: "showRandomColorGenerator", | ||
component: <RandomColor />, | ||
}, | ||
{ | ||
key: "showAccordion", | ||
component: <Accordion />, | ||
}, | ||
{ | ||
key: "showTreeView", | ||
component: <TreeView menus={menus} />, | ||
}, | ||
{ | ||
key : 'showTabs', | ||
component : <TabTest /> | ||
} | ||
]; | ||
|
||
function checkEnabledFlags(getCurrentKey) { | ||
return enabledFlags[getCurrentKey]; | ||
} | ||
|
||
if (loading) return <h1 className="text-lg text-center">Loading</h1>; | ||
|
||
return ( | ||
<div> | ||
<h1 className="text-2xl text-center bg-gr py-4">Feature Flags</h1> | ||
{componentsToRender.map((componentItem) => | ||
checkEnabledFlags(componentItem.key) ? componentItem.component : null, | ||
)} | ||
</div> | ||
); | ||
} |
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,34 @@ | ||
import { createContext, useState, useEffect } from "react"; | ||
import featureFlagsDataServiceCall from "../data"; | ||
|
||
export const FeatureFlagsContext = createContext(null); | ||
|
||
export default function FeatureFlagGlobalState({ children }) { | ||
const [loading, setLoading] = useState(false); | ||
const [enabledFlags, setEnabledFlags] = useState({}); | ||
|
||
async function fetchFeatureFlags() { | ||
try { | ||
setLoading(true); | ||
// original service call | ||
const response = await featureFlagsDataServiceCall(); | ||
console.log(response); | ||
setEnabledFlags(response); | ||
setLoading(false); | ||
} catch (error) { | ||
setLoading(false); | ||
console.log(error); | ||
throw new Error(error); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
fetchFeatureFlags(); | ||
}, []); | ||
|
||
return ( | ||
<FeatureFlagsContext.Provider value={{ loading, enabledFlags }}> | ||
{children} | ||
</FeatureFlagsContext.Provider> | ||
); | ||
} |
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,18 @@ | ||
const dummyApiResponse = { | ||
showLightAndDarkMode: false, | ||
showTicTacToeBoard: true, | ||
showRandomColorGenerator: true, | ||
showAccordion: true, | ||
showTreeView: false, | ||
showTabs: true, | ||
}; | ||
|
||
function featureFlagsDataServiceCall() { | ||
|
||
return new Promise((resolve, reject) => { | ||
if (dummyApiResponse) setTimeout(resolve(dummyApiResponse), 500); | ||
else reject("Some error eccured! Please Try again"); | ||
}); | ||
} | ||
|
||
export default featureFlagsDataServiceCall; |
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