diff --git a/components/dashboard/src/components/UsageView.tsx b/components/dashboard/src/components/UsageView.tsx index d27567f54a4813..f866d51e4d7ffc 100644 --- a/components/dashboard/src/components/UsageView.tsx +++ b/components/dashboard/src/components/UsageView.tsx @@ -82,15 +82,20 @@ function UsageView({ attributionId, billingMode }: UsageViewProps) { return "Prebuild"; }; + const isRunning = (usage: Usage) => { + if (usage.kind !== "workspaceinstance") { + return false; + } + const metaData = usage.metadata as WorkspaceInstanceUsageData; + return metaData.endTime === "" || metaData.endTime === undefined; + }; + const getMinutes = (usage: Usage) => { if (usage.kind !== "workspaceinstance") { return ""; } const metaData = usage.metadata as WorkspaceInstanceUsageData; - if (!metaData.endTime) { - return "running"; - } - const end = new Date(metaData.endTime).getTime(); + const end = metaData.endTime ? new Date(metaData.endTime).getTime() : Date.now(); const start = new Date(metaData.startTime).getTime(); const lengthOfUsage = Math.floor(end - start); const inMinutes = (lengthOfUsage / (1000 * 60)).toFixed(1); @@ -139,7 +144,12 @@ function UsageView({ attributionId, billingMode }: UsageViewProps) { return ( <> -
+
{errorMessage &&

{errorMessage}

} {!errorMessage && ( @@ -163,29 +173,31 @@ function UsageView({ attributionId, billingMode }: UsageViewProps) {
Total usage
- {totalCreditsUsed} Credits + {Intl.NumberFormat().format(totalCreditsUsed)} Credits
)} - {!isLoading && usagePage === undefined && !errorMessage && ( -
-

No sessions found.

-

- Have you started any - - {" "} - workspaces - {" "} - in{" "} - {new Date(startDateOfBillMonth).toLocaleString("default", { - month: "long", - })}{" "} - {new Date(startDateOfBillMonth).getFullYear()} or checked your other teams? -

-
- )} + {!isLoading && + (usagePage === undefined || usagePage.usageEntriesList.length === 0) && + !errorMessage && ( +
+

No sessions found.

+

+ Have you started any + + {" "} + workspaces + {" "} + in{" "} + {new Date(startDateOfBillMonth).toLocaleString("default", { + month: "long", + })}{" "} + {new Date(startDateOfBillMonth).getFullYear()} or checked your other teams? +

+
+ )} {isLoading && (
@@ -237,9 +249,20 @@ function UsageView({ attributionId, billingMode }: UsageViewProps) {
- - {(usage.metadata as WorkspaceInstanceUsageData).workspaceId} - +
+ {isRunning(usage) && ( +
+ )} + + { + (usage.metadata as WorkspaceInstanceUsageData) + .workspaceId + } + +
{(usage.metadata as WorkspaceInstanceUsageData) .contextURL && @@ -253,9 +276,11 @@ function UsageView({ attributionId, billingMode }: UsageViewProps) { {usage.credits.toFixed(1)} - - {getMinutes(usage)} - +
+ + {getMinutes(usage)} + +