-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ added feature toggle support (#99)
* feat: ✨ added feature toggle support * fix: 🐛 fixed issue with client component use * fix: 🐛 added missing env to workflow * fix: 🐛 fixed failing test workflow
- Loading branch information
Showing
17 changed files
with
403 additions
and
263 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 @@ | ||
NEXT_PUBLIC_FLAGSMITH_ENVIRONMENT_ID= |
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,25 @@ | ||
{ | ||
"name": "@ultra-reporter/feature-toggle", | ||
"description": "Ultra Reporter feature toggles", | ||
"version": "0.5.0", | ||
"private": true, | ||
"scripts": { | ||
"lint": "eslint . --max-warnings 0" | ||
}, | ||
"exports": { | ||
"./client": "./src/client.ts", | ||
"./provider": "./src/provider.tsx" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.3.12", | ||
"@types/react-dom": "^18", | ||
"@ultra-reporter/typescript-config": "workspace:*" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.0", | ||
"react-dom": "^18.0" | ||
}, | ||
"dependencies": { | ||
"flagsmith": "^7.0.2" | ||
} | ||
} |
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,14 @@ | ||
import { createFlagsmithInstance } from 'flagsmith/isomorphic'; | ||
import { IState } from 'flagsmith/types'; | ||
|
||
export const getFeatureState = async (): Promise<IState<string>> => { | ||
const flagsmith = createFlagsmithInstance(); | ||
await flagsmith.init({ | ||
evaluationContext: { | ||
environment: { | ||
apiKey: process.env.NEXT_PUBLIC_FLAGSMITH_ENVIRONMENT_ID, | ||
}, | ||
}, | ||
}); | ||
return flagsmith.getState(); | ||
}; |
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 @@ | ||
export const Flags = ['sign_in_support', 'faq']; |
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,32 @@ | ||
/* eslint-disable react/react-in-jsx-scope */ | ||
'use client'; | ||
|
||
import { createFlagsmithInstance } from 'flagsmith/isomorphic'; | ||
import { FlagsmithProvider, useFlags } from 'flagsmith/react'; | ||
import { IFlagsmithFeature, IFlagsmithTrait, IState } from 'flagsmith/types'; | ||
import { useRef } from 'react'; | ||
import { Flags } from './flag-list'; | ||
|
||
interface FeatureProviderProps { | ||
serverState: IState<string>; | ||
children: JSX.Element; | ||
} | ||
|
||
export const FeatureProvider = ({ | ||
serverState, | ||
children, | ||
}: FeatureProviderProps): JSX.Element => { | ||
const flagsmith = useRef(createFlagsmithInstance()); | ||
return ( | ||
<FlagsmithProvider flagsmith={flagsmith.current} serverState={serverState}> | ||
{children} | ||
</FlagsmithProvider> | ||
); | ||
}; | ||
|
||
export function getFlag( | ||
flagId: string | ||
): (IFlagsmithFeature & IFlagsmithTrait) | undefined { | ||
const flags = useFlags(Flags); | ||
return flags[flagId]; | ||
} |
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,11 @@ | ||
{ | ||
"extends": "@ultra-reporter/typescript-config/react-library.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules"] | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"extends": "@ultra-reporter/typescript-config/react-library.json", | ||
"extends": "@ultra-reporter/typescript-config/base.json", | ||
"include": ["."], | ||
"exclude": ["dist", "build", "node_modules"] | ||
"exclude": ["node_modules"] | ||
} |
Oops, something went wrong.