Skip to content

Commit 20324c1

Browse files
author
Laurie T. Malau
committed
add sorting
1 parent ea3921d commit 20324c1

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

components/dashboard/src/teams/TeamUsage.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useContext, useEffect, useState } from "react";
88
import { Redirect, useLocation } from "react-router";
99
import { getCurrentTeam, TeamsContext } from "./teams-context";
1010
import { getGitpodService, gitpodHostUrl } from "../service/service";
11-
import { BillableSession, BillableWorkspaceType } from "@gitpod/gitpod-protocol/lib/usage";
11+
import { BillableSession, BillableWorkspaceType, SortOrder } from "@gitpod/gitpod-protocol/lib/usage";
1212
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
1313
import { Item, ItemField, ItemsList } from "../components/ItemsList";
1414
import moment from "moment";
@@ -34,6 +34,7 @@ function TeamUsage() {
3434
const [startDateOfBillMonth, setStartDateOfBillMonth] = useState(timestampStartOfCurrentMonth);
3535
const [endDateOfBillMonth, setEndDateOfBillMonth] = useState(Date.now());
3636
const [isLoading, setIsLoading] = useState<boolean>(true);
37+
const [startedTimeOrder] = useState<SortOrder>(SortOrder.Descending);
3738

3839
useEffect(() => {
3940
if (!team) {
@@ -44,6 +45,7 @@ function TeamUsage() {
4445
try {
4546
const billedUsageResult = await getGitpodService().server.listBilledUsage(
4647
attributionId,
48+
startedTimeOrder,
4749
startDateOfBillMonth,
4850
endDateOfBillMonth,
4951
);
@@ -56,7 +58,7 @@ function TeamUsage() {
5658
setIsLoading(false);
5759
}
5860
})();
59-
}, [team, startDateOfBillMonth, endDateOfBillMonth]);
61+
}, [team, startDateOfBillMonth, endDateOfBillMonth, startedTimeOrder]);
6062

6163
if (!showUsageBasedPricingUI) {
6264
return <Redirect to="/" />;

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import { RemotePageMessage, RemoteTrackMessage, RemoteIdentifyMessage } from "./
6161
import { IDEServer } from "./ide-protocol";
6262
import { InstallationAdminSettings, TelemetryData } from "./installation-admin-protocol";
6363
import { Currency } from "./plans";
64-
import { BillableSession } from "./usage";
64+
import { BillableSession, SortOrder } from "./usage";
6565
import { SupportedWorkspaceClass } from "./workspace-class";
6666

6767
export interface GitpodClient {
@@ -294,7 +294,12 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
294294
getSpendingLimitForTeam(teamId: string): Promise<number | undefined>;
295295
setSpendingLimitForTeam(teamId: string, spendingLimit: number): Promise<void>;
296296

297-
listBilledUsage(attributionId: string, from?: number, to?: number): Promise<BillableSession[]>;
297+
listBilledUsage(
298+
attributionId: string,
299+
startedTimeOrder: SortOrder,
300+
from?: number,
301+
to?: number,
302+
): Promise<BillableSession[]>;
298303
setUsageAttribution(usageAttribution: string): Promise<void>;
299304

300305
/**
@@ -308,7 +313,7 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
308313
* Frontend notifications
309314
*/
310315
getNotifications(): Promise<string[]>;
311-
316+
312317
getSupportedWorkspaceClasses(): Promise<SupportedWorkspaceClass[]>;
313318
}
314319

components/gitpod-protocol/src/usage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ export interface BillableSession {
3636
}
3737

3838
export type BillableWorkspaceType = WorkspaceType;
39+
40+
export enum SortOrder {
41+
Descending = 0,
42+
Ascending = 1,
43+
}

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import { BlockedRepository } from "@gitpod/gitpod-protocol/lib/blocked-repositor
7272
import { EligibilityService } from "../user/eligibility-service";
7373
import { AccountStatementProvider } from "../user/account-statement-provider";
7474
import { GithubUpgradeURL, PlanCoupon } from "@gitpod/gitpod-protocol/lib/payment-protocol";
75-
import { BillableSession } from "@gitpod/gitpod-protocol/lib/usage";
75+
import { BillableSession, SortOrder } from "@gitpod/gitpod-protocol/lib/usage";
7676
import {
7777
AssigneeIdentityIdentifier,
7878
TeamSubscription,
@@ -2080,7 +2080,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
20802080
const result = await super.getNotifications(ctx);
20812081
const user = this.checkAndBlockUser("getNotifications");
20822082
if (user.usageAttributionId) {
2083-
const allSessions = await this.listBilledUsage(ctx, user.usageAttributionId);
2083+
const allSessions = await this.listBilledUsage(ctx, user.usageAttributionId, 0);
20842084
const totalUsage = allSessions.map((s) => s.credits).reduce((a, b) => a + b, 0);
20852085
const costCenter = await this.costCenterDB.findById(user.usageAttributionId);
20862086
if (costCenter) {
@@ -2099,6 +2099,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
20992099
async listBilledUsage(
21002100
ctx: TraceContext,
21012101
attributionId: string,
2102+
startedTimeOrder: SortOrder,
21022103
from?: number,
21032104
to?: number,
21042105
): Promise<BillableSession[]> {
@@ -2116,7 +2117,13 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
21162117
timestampTo = Timestamp.fromDate(new Date(to));
21172118
}
21182119
const usageClient = this.usageServiceClientProvider.getDefault();
2119-
const response = await usageClient.listBilledUsage(ctx, attributionId, timestampFrom, timestampTo);
2120+
const response = await usageClient.listBilledUsage(
2121+
ctx,
2122+
attributionId,
2123+
startedTimeOrder as number,
2124+
timestampFrom,
2125+
timestampTo,
2126+
);
21202127
const sessions = response.getSessionsList().map((s) => this.mapBilledSession(s));
21212128

21222129
return sessions;

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ import { LicenseEvaluator } from "@gitpod/licensor/lib";
169169
import { Feature } from "@gitpod/licensor/lib/api";
170170
import { Currency } from "@gitpod/gitpod-protocol/lib/plans";
171171
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
172-
import { BillableSession } from "@gitpod/gitpod-protocol/lib/usage";
172+
import { BillableSession, SortOrder } from "@gitpod/gitpod-protocol/lib/usage";
173173
import { WorkspaceClusterImagebuilderClientProvider } from "./workspace-cluster-imagebuilder-client-provider";
174174

175175
// shortcut
@@ -3210,6 +3210,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
32103210
async listBilledUsage(
32113211
ctx: TraceContext,
32123212
attributionId: string,
3213+
startedTimeOrder: SortOrder,
32133214
from?: number,
32143215
to?: number,
32153216
): Promise<BillableSession[]> {

components/usage-api/typescript/src/usage/v1/sugar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ export class PromisifiedUsageServiceClient {
9191
);
9292
}
9393

94-
public async listBilledUsage(_ctx: TraceContext, attributionId: string, from?: Timestamp, to?: Timestamp): Promise<ListBilledUsageResponse> {
94+
public async listBilledUsage(_ctx: TraceContext, attributionId: string, order: ListBilledUsageRequest.Ordering, from?: Timestamp, to?: Timestamp): Promise<ListBilledUsageResponse> {
9595
const ctx = TraceContext.childContext(`/usage-service/listBilledUsage`, _ctx);
9696

9797
try {
9898
const req = new ListBilledUsageRequest();
9999
req.setAttributionId(attributionId);
100100
req.setFrom(from);
101101
req.setTo(to);
102+
req.setOrder(order);
102103

103104
const response = await new Promise<ListBilledUsageResponse>((resolve, reject) => {
104105
this.client.listBilledUsage(

0 commit comments

Comments
 (0)