Skip to content

Commit f64024b

Browse files
committed
adding new flag and refactor flag type
1 parent 9f63300 commit f64024b

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

components/dashboard/src/contexts/FeatureFlagContext.tsx

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import React, { createContext, useContext, useState, useEffect } from "react";
7+
import React, { createContext, useContext, useState, useEffect, useMemo } from "react";
88
import { getExperimentsClient } from "../experiments/client";
99
import { ProjectContext } from "../projects/project-context";
1010
import { useCurrentTeam, useTeams } from "../teams/teams-context";
@@ -14,16 +14,11 @@ interface FeatureFlagConfig {
1414
[flagName: string]: { defaultValue: boolean; setter: React.Dispatch<React.SetStateAction<boolean>> };
1515
}
1616

17-
const FeatureFlagContext = createContext<{
18-
startWithOptions: boolean;
19-
showUsageView: boolean;
20-
isUsageBasedBillingEnabled: boolean;
21-
showUseLastSuccessfulPrebuild: boolean;
22-
usePublicApiWorkspacesService: boolean;
23-
enablePersonalAccessTokens: boolean;
24-
oidcServiceEnabled: boolean;
25-
orgGitAuthProviders: boolean;
26-
}>({
17+
type FeatureFlagsType = {
18+
[k in keyof typeof defaultFeatureFlags]: boolean;
19+
};
20+
21+
const defaultFeatureFlags = {
2722
startWithOptions: false,
2823
showUsageView: false,
2924
isUsageBasedBillingEnabled: false,
@@ -32,7 +27,10 @@ const FeatureFlagContext = createContext<{
3227
enablePersonalAccessTokens: false,
3328
oidcServiceEnabled: false,
3429
orgGitAuthProviders: false,
35-
});
30+
newSignupFlow: false,
31+
};
32+
33+
const FeatureFlagContext = createContext<FeatureFlagsType>(defaultFeatureFlags);
3634

3735
const FeatureFlagContextProvider: React.FC = ({ children }) => {
3836
const { user } = useContext(UserContext);
@@ -47,6 +45,7 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
4745
const [usePublicApiWorkspacesService, setUsePublicApiWorkspacesService] = useState<boolean>(false);
4846
const [oidcServiceEnabled, setOidcServiceEnabled] = useState<boolean>(false);
4947
const [orgGitAuthProviders, setOrgGitAuthProviders] = useState<boolean>(false);
48+
const [newSignupFlow, setNewSignupFlow] = useState<boolean>(false);
5049

5150
useEffect(() => {
5251
if (!user) return;
@@ -63,6 +62,7 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
6362
},
6463
oidcServiceEnabled: { defaultValue: false, setter: setOidcServiceEnabled },
6564
orgGitAuthProviders: { defaultValue: false, setter: setOrgGitAuthProviders },
65+
newSignupFlow: { defaultValue: false, setter: setNewSignupFlow },
6666
};
6767

6868
for (const [flagName, config] of Object.entries(featureFlags)) {
@@ -99,22 +99,31 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
9999
})();
100100
}, [user, teams, team, project]);
101101

102-
return (
103-
<FeatureFlagContext.Provider
104-
value={{
105-
startWithOptions,
106-
showUsageView,
107-
isUsageBasedBillingEnabled,
108-
showUseLastSuccessfulPrebuild,
109-
enablePersonalAccessTokens,
110-
usePublicApiWorkspacesService,
111-
oidcServiceEnabled,
112-
orgGitAuthProviders,
113-
}}
114-
>
115-
{children}
116-
</FeatureFlagContext.Provider>
117-
);
102+
const flags = useMemo(() => {
103+
return {
104+
startWithOptions,
105+
showUsageView,
106+
isUsageBasedBillingEnabled,
107+
showUseLastSuccessfulPrebuild,
108+
enablePersonalAccessTokens,
109+
usePublicApiWorkspacesService,
110+
oidcServiceEnabled,
111+
orgGitAuthProviders,
112+
newSignupFlow,
113+
};
114+
}, [
115+
enablePersonalAccessTokens,
116+
isUsageBasedBillingEnabled,
117+
newSignupFlow,
118+
oidcServiceEnabled,
119+
orgGitAuthProviders,
120+
showUsageView,
121+
showUseLastSuccessfulPrebuild,
122+
startWithOptions,
123+
usePublicApiWorkspacesService,
124+
]);
125+
126+
return <FeatureFlagContext.Provider value={flags}>{children}</FeatureFlagContext.Provider>;
118127
};
119128

120129
export { FeatureFlagContext, FeatureFlagContextProvider };

0 commit comments

Comments
 (0)