Skip to content

Commit 746638b

Browse files
svenefftingeroboquat
authored andcommitted
[usage] Enable usage view with feature flag
1 parent eb4762b commit 746638b

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

components/dashboard/src/Menu.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { PaymentContext } from "./payment-context";
2727
import FeedbackFormModal from "./feedback-form/FeedbackModal";
2828
import { inResource, isGitpodIo } from "./utils";
2929
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
30+
import { FeatureFlagContext } from "./contexts/FeatureFlagContext";
3031

3132
interface Entry {
3233
title: string;
@@ -36,6 +37,7 @@ interface Entry {
3637

3738
export default function Menu() {
3839
const { user, userBillingMode, refreshUserBillingMode } = useContext(UserContext);
40+
const { showUsageView } = useContext(FeatureFlagContext);
3941
const { teams } = useContext(TeamsContext);
4042
const location = useLocation();
4143
const team = getCurrentTeam(location, teams);
@@ -199,7 +201,7 @@ export default function Menu() {
199201
link: `/t/${team.slug}/members`,
200202
},
201203
];
202-
if (teamBillingMode && teamBillingMode.mode === "usage-based") {
204+
if (showUsageView || (teamBillingMode && teamBillingMode.mode === "usage-based")) {
203205
teamSettingsList.push({
204206
title: "Usage",
205207
link: `/t/${team.slug}/usage`,
@@ -221,12 +223,12 @@ export default function Menu() {
221223
title: "Projects",
222224
link: "/projects",
223225
});
224-
// if (userBillingMode?.mode === "usage-based") {
225-
// userMenu.push({
226-
// title: "Usage",
227-
// link: "/usage",
228-
// });
229-
// }
226+
if (showUsageView) {
227+
userMenu.push({
228+
title: "Usage",
229+
link: "/usage",
230+
});
231+
}
230232
userMenu.push({
231233
title: "Settings",
232234
link: "/settings",

components/dashboard/src/contexts/FeatureFlagContext.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ interface FeatureFlagConfig {
1818
const FeatureFlagContext = createContext<{
1919
showWorkspaceClassesUI: boolean;
2020
showPersistentVolumeClaimUI: boolean;
21+
showUsageView: boolean;
2122
}>({
2223
showWorkspaceClassesUI: false,
2324
showPersistentVolumeClaimUI: false,
25+
showUsageView: false,
2426
});
2527

2628
const FeatureFlagContextProvider: React.FC = ({ children }) => {
@@ -31,15 +33,16 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
3133
const team = getCurrentTeam(location, teams);
3234
const [showWorkspaceClassesUI, setShowWorkspaceClassesUI] = useState<boolean>(false);
3335
const [showPersistentVolumeClaimUI, setShowPersistentVolumeClaimUI] = useState<boolean>(false);
34-
35-
const featureFlags: FeatureFlagConfig = {
36-
workspace_classes: { defaultValue: true, setter: setShowWorkspaceClassesUI },
37-
persistent_volume_claim: { defaultValue: true, setter: setShowPersistentVolumeClaimUI },
38-
};
36+
const [showUsageView, setShowUsageView] = useState<boolean>(false);
3937

4038
useEffect(() => {
4139
if (!user) return;
4240
(async () => {
41+
const featureFlags: FeatureFlagConfig = {
42+
workspace_classes: { defaultValue: true, setter: setShowWorkspaceClassesUI },
43+
persistent_volume_claim: { defaultValue: true, setter: setShowPersistentVolumeClaimUI },
44+
usage_view: { defaultValue: true, setter: setShowUsageView },
45+
};
4346
for (const [flagName, config] of Object.entries(featureFlags)) {
4447
const flagValue = await getExperimentsClient().getValueAsync(flagName, config.defaultValue, {
4548
user,
@@ -54,7 +57,7 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
5457
}, [user, teams, team, project]);
5558

5659
return (
57-
<FeatureFlagContext.Provider value={{ showWorkspaceClassesUI, showPersistentVolumeClaimUI }}>
60+
<FeatureFlagContext.Provider value={{ showWorkspaceClassesUI, showPersistentVolumeClaimUI, showUsageView }}>
5861
{children}
5962
</FeatureFlagContext.Provider>
6063
);

0 commit comments

Comments
 (0)