Skip to content

Show personal Usage page #12771

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 3 commits into from
Sep 12, 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
3 changes: 3 additions & 0 deletions components/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
settingsPathTeamsNew,
settingsPathVariables,
settingsPathSSHKeys,
usagePathMain,
} from "./settings/settings.routes";
import {
projectsPathInstallGitHubApp,
Expand Down Expand Up @@ -90,6 +91,7 @@ const ProjectsSearch = React.lazy(() => import(/* webpackPrefetch: true */ "./ad
const TeamsSearch = React.lazy(() => import(/* webpackPrefetch: true */ "./admin/TeamsSearch"));
const OAuthClientApproval = React.lazy(() => import(/* webpackPrefetch: true */ "./OauthClientApproval"));
const License = React.lazy(() => import(/* webpackPrefetch: true */ "./admin/License"));
const Usage = React.lazy(() => import(/* webpackPrefetch: true */ "./Usage"));

function Loading() {
return <></>;
Expand Down Expand Up @@ -377,6 +379,7 @@ function App() {
<Route path="/setup" exact component={Setup} />
<Route path={workspacesPathMain} exact component={Workspaces} />
<Route path={settingsPathAccount} exact component={Account} />
<Route path={usagePathMain} exact component={Usage} />
<Route path={settingsPathIntegrations} exact component={Integrations} />
<Route path={settingsPathNotifications} exact component={Notifications} />
<Route path={settingsPathBilling} exact component={Billing} />
Expand Down
28 changes: 17 additions & 11 deletions components/dashboard/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,23 @@ export default function Menu() {
return teamSettingsList;
}
// User menu
return [
{
title: "Projects",
link: "/projects",
},
{
title: "Settings",
link: "/settings",
alternatives: getSettingsMenu({ userBillingMode }).flatMap((e) => e.link),
},
];
const userMenu = [];
userMenu.push({
title: "Projects",
link: "/projects",
});
// if (userBillingMode?.mode === "usage-based") {
// userMenu.push({
// title: "Usage",
// link: "/usage",
// });
// }
userMenu.push({
title: "Settings",
link: "/settings",
alternatives: getSettingsMenu({ userBillingMode }).flatMap((e) => e.link),
});
return userMenu;
})();
const rightMenu: Entry[] = [
...(user?.rolesOrPermissions?.includes("admin")
Expand Down
47 changes: 47 additions & 0 deletions components/dashboard/src/Usage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is almost identical to src/teams/TeamUsage.tsx. Can we use one in both places?

Copy link
Member Author

Choose a reason for hiding this comment

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

@andrew-farries, I think there are two options, having the entry points separate (like now) and computing the props depending without consideration of location, or we merge, and need to sort out, what's meaningful inside of a single component depending on the location.
I'd prefer to go with the current state, just to avoid the complexity of properly creating the props for <UsageView />.

* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import { useContext, useEffect, useState } from "react";

import { getGitpodService, gitpodHostUrl } from "./service/service";
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
import UsageView from "./components/UsageView";
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
import { UserContext } from "./user-context";

function TeamUsage() {
const { user } = useContext(UserContext);
const [billingMode, setBillingMode] = useState<BillingMode | undefined>(undefined);
const [attributionId, setAttributionId] = useState<AttributionId | undefined>();

useEffect(() => {
if (!user) {
return;
}
setAttributionId({ kind: "user", userId: user.id });
(async () => {
const billingMode = await getGitpodService().server.getBillingModeForUser();
setBillingMode(billingMode);
})();
}, [user]);

useEffect(() => {
if (!billingMode) {
return;
}
if (!BillingMode.showUsageBasedBilling(billingMode)) {
window.location.href = gitpodHostUrl.asDashboard().toString();
}
}, [billingMode]);

if (!billingMode || !attributionId) {
return <></>;
}

return <UsageView billingMode={billingMode} attributionId={attributionId} />;
}

export default TeamUsage;
Loading