Skip to content

[usage] Enable usage view with feature flag #13065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
};
Comment on lines +41 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for making these very explicit (rather than reflecting over the set of flags)? I feel this has the potential to confuse others who are trying to use feature flags - having to define them here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah never mind, I missed that you just moved the definition (and the problem already exists)

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