From 746638b430ae2b64fec724ad447642bccedeced9 Mon Sep 17 00:00:00 2001 From: Sven Efftinge Date: Wed, 21 Sep 2022 07:50:22 +0000 Subject: [PATCH] [usage] Enable usage view with feature flag --- components/dashboard/src/Menu.tsx | 16 +++++++++------- .../src/contexts/FeatureFlagContext.tsx | 15 +++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/components/dashboard/src/Menu.tsx b/components/dashboard/src/Menu.tsx index cc941ffc84b546..aad6bca978cd8a 100644 --- a/components/dashboard/src/Menu.tsx +++ b/components/dashboard/src/Menu.tsx @@ -27,6 +27,7 @@ import { PaymentContext } from "./payment-context"; import FeedbackFormModal from "./feedback-form/FeedbackModal"; import { inResource, isGitpodIo } from "./utils"; import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode"; +import { FeatureFlagContext } from "./contexts/FeatureFlagContext"; interface Entry { title: string; @@ -36,6 +37,7 @@ interface Entry { export default function Menu() { const { user, userBillingMode, refreshUserBillingMode } = useContext(UserContext); + const { showUsageView } = useContext(FeatureFlagContext); const { teams } = useContext(TeamsContext); const location = useLocation(); const team = getCurrentTeam(location, teams); @@ -199,7 +201,7 @@ export default function Menu() { link: `/t/${team.slug}/members`, }, ]; - if (teamBillingMode && teamBillingMode.mode === "usage-based") { + if (showUsageView || (teamBillingMode && teamBillingMode.mode === "usage-based")) { teamSettingsList.push({ title: "Usage", link: `/t/${team.slug}/usage`, @@ -221,12 +223,12 @@ export default function Menu() { title: "Projects", link: "/projects", }); - // if (userBillingMode?.mode === "usage-based") { - // userMenu.push({ - // title: "Usage", - // link: "/usage", - // }); - // } + if (showUsageView) { + userMenu.push({ + title: "Usage", + link: "/usage", + }); + } userMenu.push({ title: "Settings", link: "/settings", diff --git a/components/dashboard/src/contexts/FeatureFlagContext.tsx b/components/dashboard/src/contexts/FeatureFlagContext.tsx index fdc90fcc6e8919..20a023c43b98ae 100644 --- a/components/dashboard/src/contexts/FeatureFlagContext.tsx +++ b/components/dashboard/src/contexts/FeatureFlagContext.tsx @@ -18,9 +18,11 @@ interface FeatureFlagConfig { const FeatureFlagContext = createContext<{ showWorkspaceClassesUI: boolean; showPersistentVolumeClaimUI: boolean; + showUsageView: boolean; }>({ showWorkspaceClassesUI: false, showPersistentVolumeClaimUI: false, + showUsageView: false, }); const FeatureFlagContextProvider: React.FC = ({ children }) => { @@ -31,15 +33,16 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => { const team = getCurrentTeam(location, teams); const [showWorkspaceClassesUI, setShowWorkspaceClassesUI] = useState(false); const [showPersistentVolumeClaimUI, setShowPersistentVolumeClaimUI] = useState(false); - - const featureFlags: FeatureFlagConfig = { - workspace_classes: { defaultValue: true, setter: setShowWorkspaceClassesUI }, - persistent_volume_claim: { defaultValue: true, setter: setShowPersistentVolumeClaimUI }, - }; + const [showUsageView, setShowUsageView] = useState(false); useEffect(() => { if (!user) return; (async () => { + const featureFlags: FeatureFlagConfig = { + workspace_classes: { defaultValue: true, setter: setShowWorkspaceClassesUI }, + persistent_volume_claim: { defaultValue: true, setter: setShowPersistentVolumeClaimUI }, + usage_view: { defaultValue: true, setter: setShowUsageView }, + }; for (const [flagName, config] of Object.entries(featureFlags)) { const flagValue = await getExperimentsClient().getValueAsync(flagName, config.defaultValue, { user, @@ -54,7 +57,7 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => { }, [user, teams, team, project]); return ( - + {children} );