Updating get feature flags functions
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/passport": "^10.0.3",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@noahspan/noahspan-modules": "^0.2.4",
|
||||
"@noahspan/noahspan-modules": "^0.2.7",
|
||||
"@schematics/angular": "^17.3.7",
|
||||
"dotenv": "^16.4.5",
|
||||
"reflect-metadata": "0.1.13",
|
||||
|
||||
@@ -16,15 +16,19 @@ export class AppController {
|
||||
|
||||
@Public()
|
||||
@Get('featureFlags')
|
||||
async getFeatureFlags(@Query() query: any): Promise<FeatureFlagValue[]> {
|
||||
console.log(process.env.CLIENT_ID);
|
||||
async getFeatureFlags(
|
||||
@Query() query: any
|
||||
): Promise<{ key: string; enabled: boolean }[]> {
|
||||
try {
|
||||
const token: string = await this.appConfigService.getToken();
|
||||
const featureFlags: FeatureFlagValue[] =
|
||||
const featureFlagKeys: string[] =
|
||||
query.keys && query.keys.toString().includes(';')
|
||||
? query.keys.split(';')
|
||||
: [query.keys];
|
||||
const featureFlagLabel: string = query.label;
|
||||
const featureFlags: { key: string; enabled: boolean }[] =
|
||||
await this.appConfigService.getFeatureFlags(
|
||||
token,
|
||||
`${query.key}`,
|
||||
query.label
|
||||
featureFlagKeys,
|
||||
featureFlagLabel
|
||||
);
|
||||
|
||||
return featureFlags;
|
||||
|
||||
@@ -4,7 +4,6 @@ import Pilots from './components/pilots/Pilots';
|
||||
import { useAppContext } from './hooks/appContext/UseAppContext';
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import { useFeatureFlag } from './hooks/featureFlag/UseFeatureFlag';
|
||||
import { IFeatureFlagValue } from './hooks/featureFlag/IFeatureFlagValue';
|
||||
|
||||
const App: React.FC<unknown> = () => {
|
||||
const appContext = useAppContext();
|
||||
@@ -12,10 +11,12 @@ const App: React.FC<unknown> = () => {
|
||||
useEffect(() => {
|
||||
const getFeatureFlags = async () => {
|
||||
try {
|
||||
const featureFlagKeys: string = 'flying-pilots';
|
||||
const response: AxiosResponse = await axios.get(
|
||||
`http://localhost:7071/api/featureFlags?key=flying*&label=${process.env.NODE_ENV}`
|
||||
`http://localhost:7071/api/featureFlags?keys=${featureFlagKeys}&label=${process.env.NODE_ENV}`
|
||||
);
|
||||
const featureFlags: IFeatureFlagValue[] = response.data;
|
||||
const featureFlags: { key: string; enabled: boolean }[] = response.data;
|
||||
console.log(featureFlags);
|
||||
|
||||
if (featureFlags.length > 0) {
|
||||
appContext.dispatch({
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { IFeatureFlagValue } from '../../hooks/featureFlag/IFeatureFlagValue';
|
||||
|
||||
export interface IAppContextState {
|
||||
featureFlags: IFeatureFlagValue[];
|
||||
featureFlags: { key: string; enabled: boolean }[];
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { IFeatureFlagValue } from '../../hooks/featureFlag/IFeatureFlagValue';
|
||||
import { IAppContextState } from './IAppContextState';
|
||||
|
||||
export type Action = {
|
||||
type: 'SET_FEATURE_FLAGS';
|
||||
payload: IFeatureFlagValue[];
|
||||
payload: { key: string; enabled: boolean }[];
|
||||
};
|
||||
|
||||
export const reducer = (
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useAppContext } from '../appContext/UseAppContext';
|
||||
|
||||
export const useFeatureFlag = (featureFlagId: string) => {
|
||||
export const useFeatureFlag = (featureFlagKey: string) => {
|
||||
const appContext = useAppContext();
|
||||
const featureFlag = appContext.state.featureFlags.find(
|
||||
(featureFlag) => featureFlag.id === featureFlagId
|
||||
(featureFlag) => featureFlag.key === featureFlagKey
|
||||
);
|
||||
|
||||
return featureFlag;
|
||||
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -36,7 +36,7 @@
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/passport": "^10.0.3",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@noahspan/noahspan-modules": "^0.2.4",
|
||||
"@noahspan/noahspan-modules": "^0.2.7",
|
||||
"@schematics/angular": "^17.3.7",
|
||||
"dotenv": "^16.4.5",
|
||||
"reflect-metadata": "0.1.13",
|
||||
@@ -4622,9 +4622,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@noahspan/noahspan-modules": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@noahspan/noahspan-modules/-/noahspan-modules-0.2.4.tgz",
|
||||
"integrity": "sha512-Zrf7+OqHAR8ipzOVxHl5VilJs1ZgYWd8ic2Gjf/e6xXz/KoleQj7S1hgBvCcPGk2pxDMPkrQf38qOuVL1rJixQ==",
|
||||
"version": "0.2.7",
|
||||
"resolved": "https://registry.npmjs.org/@noahspan/noahspan-modules/-/noahspan-modules-0.2.7.tgz",
|
||||
"integrity": "sha512-iDCwqfT3yK+Y48N0+jy/AiA50WQvdyaHHyUUgPblw5IzdWuMzks/dFUVegCmXyLqREUGPZk+dDXv6FIObrZTpA==",
|
||||
"dependencies": {
|
||||
"@azure/app-configuration": "^1.6.0",
|
||||
"@azure/identity": "^4.2.0",
|
||||
|
||||
Reference in New Issue
Block a user