Skip to content

Commit

Permalink
[usage] Enable usage view with feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
svenefftinge authored and roboquat committed Sep 21, 2022
1 parent eb4762b commit 746638b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
16 changes: 9 additions & 7 deletions components/dashboard/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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`,
Expand All @@ -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",
Expand Down
15 changes: 9 additions & 6 deletions components/dashboard/src/contexts/FeatureFlagContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -31,15 +33,16 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
const team = getCurrentTeam(location, teams);
const [showWorkspaceClassesUI, setShowWorkspaceClassesUI] = useState<boolean>(false);
const [showPersistentVolumeClaimUI, setShowPersistentVolumeClaimUI] = useState<boolean>(false);

const featureFlags: FeatureFlagConfig = {
workspace_classes: { defaultValue: true, setter: setShowWorkspaceClassesUI },
persistent_volume_claim: { defaultValue: true, setter: setShowPersistentVolumeClaimUI },
};
const [showUsageView, setShowUsageView] = useState<boolean>(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,
Expand All @@ -54,7 +57,7 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
}, [user, teams, team, project]);

return (
<FeatureFlagContext.Provider value={{ showWorkspaceClassesUI, showPersistentVolumeClaimUI }}>
<FeatureFlagContext.Provider value={{ showWorkspaceClassesUI, showPersistentVolumeClaimUI, showUsageView }}>
{children}
</FeatureFlagContext.Provider>
);
Expand Down

0 comments on commit 746638b

Please sign in to comment.