From 12078232ab3962bac8f31cac35a07f447ec6a19c Mon Sep 17 00:00:00 2001 From: "Laurie T. Malau" Date: Fri, 22 Jul 2022 07:24:55 +0000 Subject: [PATCH] View without data or access --- components/dashboard/src/teams/TeamUsage.tsx | 265 ++++++++++-------- .../src/util/gitpod-host-url.ts | 4 + 2 files changed, 150 insertions(+), 119 deletions(-) diff --git a/components/dashboard/src/teams/TeamUsage.tsx b/components/dashboard/src/teams/TeamUsage.tsx index e8eb5d8c994899..f57516f556b0d3 100644 --- a/components/dashboard/src/teams/TeamUsage.tsx +++ b/components/dashboard/src/teams/TeamUsage.tsx @@ -8,13 +8,14 @@ import { useContext, useEffect, useState } from "react"; import { Redirect, useLocation } from "react-router"; import { getCurrentTeam, TeamsContext } from "./teams-context"; import { PaymentContext } from "../payment-context"; -import { getGitpodService } from "../service/service"; +import { getGitpodService, gitpodHostUrl } from "../service/service"; import { BillableSession, BillableWorkspaceType } from "@gitpod/gitpod-protocol/lib/usage"; import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution"; import { Item, ItemField, ItemsList } from "../components/ItemsList"; import moment from "moment"; import Pagination from "../components/Pagination"; import Header from "../components/Header"; +import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; function TeamUsage() { const { teams } = useContext(TeamsContext); @@ -24,6 +25,7 @@ function TeamUsage() { const [billedUsage, setBilledUsage] = useState([]); const [currentPage, setCurrentPage] = useState(1); const [resultsPerPage] = useState(10); + const [errorMessage, setErrorMessage] = useState(""); useEffect(() => { if (!team) { @@ -31,8 +33,14 @@ function TeamUsage() { } (async () => { const attributionId = AttributionId.render({ kind: "team", teamId: team.id }); - const billedUsageResult = await getGitpodService().server.listBilledUsage(attributionId); - setBilledUsage(billedUsageResult); + try { + const billedUsageResult = await getGitpodService().server.listBilledUsage(attributionId); + setBilledUsage(billedUsageResult); + } catch (error) { + if (error.code === ErrorCodes.PERMISSION_DENIED) { + setErrorMessage("Access to usage details is restricted to team owners."); + } + } })(); }, [team]); @@ -75,128 +83,147 @@ function TeamUsage() { <>
-
-
-
-
-
Period
-
June 2022
-
-
-
Total usage
-
- - - - - - - - - - {calculateTotalUsage()} Total Credits + {errorMessage &&

{errorMessage}

} + {!errorMessage && ( +
+
+
+
+
Period
+
June 2022
+
+
+
Total usage
+
+ + + + + + + + + + {calculateTotalUsage()} Total Credits +
-
-
-

All Usage

- View usage details of all team members. - - - - Type - - - Class - - - Usage - - - - - - +

No sessions found.

+

+ Have you started any + + {" "} + workspaces + {" "} + or checked your other teams? +

+
+ )} + {billedUsage.length > 0 && ( +
+

All Usage

+ View usage details of all team members. + + + + Type + + + Class + + + Usage + + + - - - - - - Credits - - - - {currentPaginatedResults.map((usage) => ( -
-
- {getType(usage.workspaceType)} -
-
- {usage.workspaceClass} -
-
- {getMinutes(usage)} -
-
- {usage.credits.toFixed(1)} -
-
- - {moment(new Date(usage.startTime).toDateString()).fromNow()} - -
-
- ))} -
- {billedUsage.length > resultsPerPage && ( - + + + + + + + + + Credits + + + + {currentPaginatedResults && + currentPaginatedResults.map((usage) => ( +
+
+ {getType(usage.workspaceType)} +
+
+ {usage.workspaceClass} +
+
+ {getMinutes(usage)} +
+
+ {usage.credits.toFixed(1)} +
+
+ + {moment(new Date(usage.startTime).toDateString()).fromNow()} + +
+
+ ))} + + {billedUsage.length > resultsPerPage && ( + + )} +
)}
-
+ )}
); diff --git a/components/gitpod-protocol/src/util/gitpod-host-url.ts b/components/gitpod-protocol/src/util/gitpod-host-url.ts index 281ed4acdbf6a0..b700990939d3e5 100644 --- a/components/gitpod-protocol/src/util/gitpod-host-url.ts +++ b/components/gitpod-protocol/src/util/gitpod-host-url.ts @@ -85,6 +85,10 @@ export class GitpodHostUrl { return this.with((url) => ({ protocol: url.protocol === "https:" ? "wss:" : "ws:" })); } + asWorkspacePage(): GitpodHostUrl { + return this.with((url) => ({ pathname: "/workspaces" })); + } + asDashboard(): GitpodHostUrl { return this.with((url) => ({ pathname: "/" })); }