Skip to content

Commit d826790

Browse files
author
Laurie T. Malau
committed
Allow sorting in the UI
1 parent 5bdda8e commit d826790

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

components/dashboard/src/teams/TeamUsage.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ 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, SortOrder } from "@gitpod/gitpod-protocol/lib/usage";
11+
import {
12+
BillableSession,
13+
BillableSessionRequest,
14+
BillableWorkspaceType,
15+
SortOrder,
16+
} from "@gitpod/gitpod-protocol/lib/usage";
1217
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
1318
import { Item, ItemField, ItemsList } from "../components/ItemsList";
1419
import moment from "moment";
@@ -18,6 +23,7 @@ import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
1823
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";
1924
import { ReactComponent as CreditsSvg } from "../images/credits.svg";
2025
import { ReactComponent as Spinner } from "../icons/Spinner.svg";
26+
import Arrow from "../components/Arrow";
2127

2228
function TeamUsage() {
2329
const { teams } = useContext(TeamsContext);
@@ -34,19 +40,19 @@ function TeamUsage() {
3440
const [startDateOfBillMonth, setStartDateOfBillMonth] = useState(timestampStartOfCurrentMonth);
3541
const [endDateOfBillMonth, setEndDateOfBillMonth] = useState(Date.now());
3642
const [isLoading, setIsLoading] = useState<boolean>(true);
37-
const [startedTimeOrder] = useState<SortOrder>(SortOrder.Descending);
43+
const [isStartedTimeDescending, setIsStartedTimeDescending] = useState<boolean>(true);
3844

3945
useEffect(() => {
4046
if (!team) {
4147
return;
4248
}
4349
(async () => {
4450
const attributionId = AttributionId.render({ kind: "team", teamId: team.id });
45-
const request = {
51+
const request: BillableSessionRequest = {
4652
attributionId,
47-
startedTimeOrder,
48-
startDateOfBillMonth,
49-
endDateOfBillMonth,
53+
startedTimeOrder: isStartedTimeDescending ? SortOrder.Descending : SortOrder.Ascending,
54+
from: startDateOfBillMonth,
55+
to: endDateOfBillMonth,
5056
};
5157
try {
5258
const billedUsageResult = await getGitpodService().server.listBilledUsage(request);
@@ -59,7 +65,7 @@ function TeamUsage() {
5965
setIsLoading(false);
6066
}
6167
})();
62-
}, [team, startDateOfBillMonth, endDateOfBillMonth, startedTimeOrder]);
68+
}, [team, startDateOfBillMonth, endDateOfBillMonth, isStartedTimeDescending]);
6369

6470
if (!showUsageBasedPricingUI) {
6571
return <Redirect to="/" />;
@@ -195,7 +201,12 @@ function TeamUsage() {
195201
<CreditsSvg className="my-auto mr-1" />
196202
<span>Credits</span>
197203
</ItemField>
198-
<ItemField className="my-auto" />
204+
<ItemField className="my-auto cursor-pointer">
205+
<span onClick={() => setIsStartedTimeDescending(!isStartedTimeDescending)}>
206+
Started
207+
<Arrow direction={isStartedTimeDescending ? "down" : "up"} />
208+
</span>
209+
</ItemField>
199210
</Item>
200211
{currentPaginatedResults &&
201212
currentPaginatedResults.map((usage) => (

0 commit comments

Comments
 (0)