Skip to content

Commit 00d5108

Browse files
Andrew Farriesroboquat
Andrew Farries
authored andcommitted
Move workspace classes feature flag into context
1 parent c747450 commit 00d5108

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

components/dashboard/src/contexts/FeatureFlagContext.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import { ProjectContext } from "../projects/project-context";
1111
import { getCurrentTeam, TeamsContext } from "../teams/teams-context";
1212
import { UserContext } from "../user-context";
1313

14-
const FeatureFlagContext = createContext<{ showUsageBasedPricingUI: boolean }>({
14+
const FeatureFlagContext = createContext<{ showUsageBasedPricingUI: boolean; showWorkspaceClassesUI: boolean }>({
1515
showUsageBasedPricingUI: false,
16+
showWorkspaceClassesUI: false,
1617
});
1718

1819
const FeatureFlagContextProvider: React.FC = ({ children }) => {
@@ -22,6 +23,7 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
2223
const location = useLocation();
2324
const team = getCurrentTeam(location, teams);
2425
const [showUsageBasedPricingUI, setShowUsageBasedPricingUI] = useState<boolean>(false);
26+
const [showWorkspaceClassesUI, setShowWorkspaceClassesUI] = useState<boolean>(false);
2527

2628
useEffect(() => {
2729
if (!user) {
@@ -40,10 +42,19 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
4042
},
4143
);
4244
setShowUsageBasedPricingUI(isUsageBasedBillingEnabled);
45+
46+
const showWorkspaceClasses = await getExperimentsClient().getValueAsync("workspace_classes", true, {
47+
user,
48+
});
49+
setShowWorkspaceClassesUI(showWorkspaceClasses);
4350
})();
4451
}, [user, teams, team, project]);
4552

46-
return <FeatureFlagContext.Provider value={{ showUsageBasedPricingUI }}>{children}</FeatureFlagContext.Provider>;
53+
return (
54+
<FeatureFlagContext.Provider value={{ showUsageBasedPricingUI, showWorkspaceClassesUI }}>
55+
{children}
56+
</FeatureFlagContext.Provider>
57+
);
4758
};
4859

4960
export { FeatureFlagContext, FeatureFlagContextProvider };

components/dashboard/src/settings/Preferences.tsx

+3-13
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ import { ThemeContext } from "../theme-context";
1111
import { UserContext } from "../user-context";
1212
import { trackEvent } from "../Analytics";
1313
import SelectIDE from "./SelectIDE";
14-
import { getExperimentsClient } from "../experiments/client";
1514
import SelectWorkspaceClass from "./selectClass";
1615
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu";
16+
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";
1717

1818
type Theme = "light" | "dark" | "system";
1919

2020
export default function Preferences() {
2121
const { user } = useContext(UserContext);
2222
const { setIsDark } = useContext(ThemeContext);
23+
const { showWorkspaceClassesUI } = useContext(FeatureFlagContext);
2324

2425
const [theme, setTheme] = useState<Theme>(localStorage.theme || "system");
2526
const actuallySetTheme = (theme: Theme) => {
@@ -49,24 +50,13 @@ export default function Preferences() {
4950
}
5051
};
5152

52-
const [isShowWorkspaceClasses, setIsShowWorkspaceClasses] = useState<boolean>(false);
53-
(async () => {
54-
if (!user) {
55-
return;
56-
}
57-
const showWorkspaceClasses = await getExperimentsClient().getValueAsync("workspace_classes", true, {
58-
user,
59-
});
60-
setIsShowWorkspaceClasses(showWorkspaceClasses);
61-
})();
62-
6353
return (
6454
<div>
6555
<PageWithSettingsSubMenu title="Preferences" subtitle="Configure user preferences.">
6656
<h3>Editor</h3>
6757
<p className="text-base text-gray-500 dark:text-gray-400">Choose the editor for opening workspaces.</p>
6858
<SelectIDE location="preferences" />
69-
<SelectWorkspaceClass enabled={isShowWorkspaceClasses} />
59+
<SelectWorkspaceClass enabled={showWorkspaceClassesUI} />
7060
<h3 className="mt-12">Theme</h3>
7161
<p className="text-base text-gray-500 dark:text-gray-400">Early bird or night owl? Choose your side.</p>
7262
<div className="mt-4 space-x-3 flex">

0 commit comments

Comments
 (0)