-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
294 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* 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 { Redirect, useLocation } from "react-router"; | ||
import { PageWithSubMenu } from "../components/PageWithSubMenu"; | ||
import { getCurrentTeam, TeamsContext } from "./teams-context"; | ||
import { getTeamSettingsMenu } from "./TeamSettings"; | ||
import { PaymentContext } from "../payment-context"; | ||
import { getGitpodService } from "../service/service"; | ||
import { BillableSession } from "@gitpod/gitpod-protocol/lib/usage"; | ||
import { Item, ItemField, ItemsList } from "../components/ItemsList"; | ||
import moment from "moment"; | ||
import Property from "../admin/Property"; | ||
import Arrow from "../components/Arrow"; | ||
|
||
function TeamUsage() { | ||
const { teams } = useContext(TeamsContext); | ||
const { showPaymentUI, showUsageBasedUI } = useContext(PaymentContext); | ||
const location = useLocation(); | ||
const team = getCurrentTeam(location, teams); | ||
const [billedUsage, setBilledUsage] = useState<BillableSession[]>([]); | ||
|
||
useEffect(() => { | ||
if (!team) { | ||
return; | ||
} | ||
(async () => { | ||
const billedUsageResult = await getGitpodService().server.getBilledUsage("some-attribution-id"); | ||
setBilledUsage(billedUsageResult); | ||
})(); | ||
}, [team]); | ||
|
||
if (!showUsageBasedUI) { | ||
return <Redirect to="/" />; | ||
} | ||
|
||
const getType = (type: string) => { | ||
if (type === "regular") { | ||
return "Workspace"; | ||
} | ||
return "Prebuild"; | ||
}; | ||
|
||
const getHours = (endTime: number, startTime: number) => { | ||
return (endTime - startTime) / (1000 * 60 * 60) + "hrs"; | ||
}; | ||
|
||
return ( | ||
<PageWithSubMenu | ||
subMenu={getTeamSettingsMenu({ team, showPaymentUI, showUsageBasedUI })} | ||
title="Usage" | ||
subtitle="Manage team usage." | ||
> | ||
<div className="flex flex-col w-full"> | ||
<div className="flex w-full mt-6 mb-6"> | ||
<Property name="Last 30 days">Jun 1 - June 30</Property> | ||
<Property name="Workspaces">4,200 Min</Property> | ||
<Property name="Prebuilds">12,334 Min</Property> | ||
</div> | ||
</div> | ||
<ItemsList className="mt-2 text-gray-500"> | ||
<Item header={false} className="grid grid-cols-6 bg-gray-100"> | ||
<ItemField className="my-auto"> | ||
<span>Type</span> | ||
</ItemField> | ||
<ItemField className="my-auto"> | ||
<span>Class</span> | ||
</ItemField> | ||
<ItemField className="my-auto"> | ||
<span>Amount</span> | ||
</ItemField> | ||
<ItemField className="my-auto"> | ||
<span>Credits</span> | ||
</ItemField> | ||
<ItemField className="my-auto" /> | ||
</Item> | ||
{billedUsage.map((usage) => ( | ||
<div | ||
key={usage.instanceId} | ||
className="flex p-3 grid grid-cols-6 justify-between transition ease-in-out rounded-xl focus:bg-gitpod-kumquat-light" | ||
> | ||
<div className="my-auto"> | ||
<span className={usage.workspaceType === "prebuild" ? "text-orange-400" : "text-green-500"}> | ||
{getType(usage.workspaceType)} | ||
</span> | ||
</div> | ||
<div className="my-auto"> | ||
<span className="text-gray-400">{usage.workspaceClass}</span> | ||
</div> | ||
<div className="my-auto"> | ||
<span className="text-gray-700">{getHours(usage.endTime, usage.startTime)}</span> | ||
</div> | ||
<div className="my-auto"> | ||
<span className="text-gray-700">{usage.credits}</span> | ||
</div> | ||
<div className="my-auto"> | ||
<span className="text-gray-400"> | ||
{moment(new Date(usage.startTime).toDateString()).fromNow()} | ||
</span> | ||
</div> | ||
<div className="pr-2"> | ||
<Arrow up={false} /> | ||
</div> | ||
</div> | ||
))} | ||
</ItemsList> | ||
</PageWithSubMenu> | ||
); | ||
} | ||
|
||
export default TeamUsage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/** | ||
* 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 { WorkspaceType } from "./protocol"; | ||
|
||
export interface BillableSession { | ||
// The id of the one paying the bill | ||
attributionId: string; | ||
|
||
// Relevant for workspace type. When prebuild, shows "prebuild" | ||
userId?: string; | ||
teamId?: string; | ||
|
||
instanceId: string; | ||
|
||
workspaceId: string; | ||
|
||
workspaceType: WorkspaceType; | ||
|
||
// "standard" or "XL" | ||
workspaceClass: string; | ||
|
||
// When the workspace started | ||
startTime: number; | ||
|
||
// When the workspace ended | ||
endTime: number; | ||
|
||
// The credits used for this session | ||
credits: number; | ||
|
||
// TODO - maybe | ||
projectId?: string; | ||
} | ||
|
||
export const billableSessionDummyData: BillableSession[] = [ | ||
{ | ||
attributionId: "some-attribution-id", | ||
userId: "prebuild", | ||
teamId: "prebuild", | ||
instanceId: "some-instance-id", | ||
workspaceId: "some-workspace-id", | ||
workspaceType: "prebuild", | ||
workspaceClass: "XL", | ||
startTime: Date.now() + -3 * 24 * 3600 * 1000, // 3 days ago | ||
endTime: Date.now(), | ||
credits: 320, | ||
projectId: "project-123", | ||
}, | ||
{ | ||
attributionId: "some-attribution-id2", | ||
userId: "some-user", | ||
teamId: "some-team", | ||
instanceId: "some-instance-id2", | ||
workspaceId: "some-workspace-id2", | ||
workspaceType: "regular", | ||
workspaceClass: "standard", | ||
startTime: Date.now() + -5 * 24 * 3600 * 1000, | ||
endTime: Date.now(), | ||
credits: 130, | ||
projectId: "project-123", | ||
}, | ||
{ | ||
attributionId: "some-attribution-id3", | ||
userId: "some-other-user", | ||
teamId: "some-other-team", | ||
instanceId: "some-instance-id3", | ||
workspaceId: "some-workspace-id3", | ||
workspaceType: "regular", | ||
workspaceClass: "XL", | ||
startTime: Date.now() + -5 * 24 * 3600 * 1000, | ||
endTime: Date.now() + -4 * 24 * 3600 * 1000, | ||
credits: 150, | ||
projectId: "project-134", | ||
}, | ||
{ | ||
attributionId: "some-attribution-id4", | ||
userId: "some-other-user2", | ||
teamId: "some-other-team2", | ||
instanceId: "some-instance-id4", | ||
workspaceId: "some-workspace-id4", | ||
workspaceType: "regular", | ||
workspaceClass: "standard", | ||
startTime: Date.now() + -10 * 24 * 3600 * 1000, | ||
endTime: Date.now() + -9 * 24 * 3600 * 1000, | ||
credits: 330, | ||
projectId: "project-137", | ||
}, | ||
{ | ||
attributionId: "some-attribution-id5", | ||
userId: "some-other-user3", | ||
teamId: "some-other-team3", | ||
instanceId: "some-instance-id5", | ||
workspaceId: "some-workspace-id5", | ||
workspaceType: "regular", | ||
workspaceClass: "XL", | ||
startTime: Date.now() + -2 * 24 * 3600 * 1000, | ||
endTime: Date.now(), | ||
credits: 222, | ||
projectId: "project-138", | ||
}, | ||
{ | ||
attributionId: "some-attribution-id6", | ||
userId: "some-other-user4", | ||
teamId: "some-other-team4", | ||
instanceId: "some-instance-id6", | ||
workspaceId: "some-workspace-id3", | ||
workspaceType: "regular", | ||
workspaceClass: "XL", | ||
startTime: Date.now() + -7 * 24 * 3600 * 1000, | ||
endTime: Date.now() + -6 * 24 * 3600 * 1000, | ||
credits: 300, | ||
projectId: "project-134", | ||
}, | ||
{ | ||
attributionId: "some-attribution-id8", | ||
userId: "some-other-user5", | ||
teamId: "some-other-team5", | ||
instanceId: "some-instance-id8", | ||
workspaceId: "some-workspace-id3", | ||
workspaceType: "regular", | ||
workspaceClass: "standard", | ||
startTime: Date.now() + -1 * 24 * 3600 * 1000, | ||
endTime: Date.now(), | ||
credits: 100, | ||
projectId: "project-567", | ||
}, | ||
{ | ||
attributionId: "some-attribution-id7", | ||
userId: "prebuild", | ||
teamId: "some-other-team7", | ||
instanceId: "some-instance-id7", | ||
workspaceId: "some-workspace-id7", | ||
workspaceType: "prebuild", | ||
workspaceClass: "XL", | ||
startTime: Date.now() + -1 * 24 * 3600 * 1000, | ||
endTime: Date.now(), | ||
credits: 200, | ||
projectId: "project-345", | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.