@@ -24,12 +24,16 @@ import { ReactComponent as Spinner } from "../icons/Spinner.svg";
24
24
import { ReactComponent as SortArrow } from "../images/sort-arrow.svg" ;
25
25
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode" ;
26
26
27
+ interface ExtendedBillableSession extends BillableSession {
28
+ contextURL : string ;
29
+ }
30
+
27
31
function TeamUsage ( ) {
28
32
const { teams } = useContext ( TeamsContext ) ;
29
33
const location = useLocation ( ) ;
30
34
const team = getCurrentTeam ( location , teams ) ;
31
35
const [ teamBillingMode , setTeamBillingMode ] = useState < BillingMode | undefined > ( undefined ) ;
32
- const [ billedUsage , setBilledUsage ] = useState < BillableSession [ ] > ( [ ] ) ;
36
+ const [ billedUsage , setBilledUsage ] = useState < ExtendedBillableSession [ ] > ( [ ] ) ;
33
37
const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
34
38
const [ resultsPerPage ] = useState ( 15 ) ;
35
39
const [ errorMessage , setErrorMessage ] = useState ( "" ) ;
@@ -55,6 +59,9 @@ function TeamUsage() {
55
59
if ( ! team ) {
56
60
return ;
57
61
}
62
+ if ( billedUsage . length === 0 ) {
63
+ setIsLoading ( true ) ;
64
+ }
58
65
( async ( ) => {
59
66
const attributionId = AttributionId . render ( { kind : "team" , teamId : team . id } ) ;
60
67
const request : BillableSessionRequest = {
@@ -65,7 +72,14 @@ function TeamUsage() {
65
72
} ;
66
73
try {
67
74
const billedUsageResult = await getGitpodService ( ) . server . listBilledUsage ( request ) ;
68
- setBilledUsage ( billedUsageResult ) ;
75
+ const extendedResult = await Promise . all (
76
+ billedUsageResult . map ( async ( res ) => {
77
+ const ws = await getGitpodService ( ) . server . getWorkspace ( res . workspaceId ) ;
78
+ return Object . assign ( res , { contextURL : ws . workspace . contextURL } ) ;
79
+ } ) ,
80
+ ) ;
81
+ console . log ( extendedResult ) ;
82
+ setBilledUsage ( extendedResult ) ;
69
83
} catch ( error ) {
70
84
if ( error . code === ErrorCodes . PERMISSION_DENIED ) {
71
85
setErrorMessage ( "Access to usage details is restricted to team owners." ) ;
@@ -141,7 +155,7 @@ function TeamUsage() {
141
155
const displayTime = ( time : string ) => {
142
156
const options : Intl . DateTimeFormatOptions = {
143
157
day : "numeric" ,
144
- month : "long " ,
158
+ month : "short " ,
145
159
year : "numeric" ,
146
160
hour : "numeric" ,
147
161
minute : "numeric" ,
@@ -184,7 +198,7 @@ function TeamUsage() {
184
198
</ div >
185
199
</ div >
186
200
</ div >
187
- { billedUsage . length === 0 && ! errorMessage && ! isLoading && (
201
+ { ! isLoading && billedUsage . length === 0 && ! errorMessage && (
188
202
< div className = "flex flex-col w-full mb-8" >
189
203
< h3 className = "text-center text-gray-500 mt-8" > No sessions found.</ h3 >
190
204
< p className = "text-center text-gray-500 mt-1" >
@@ -212,26 +226,22 @@ function TeamUsage() {
212
226
{ billedUsage . length > 0 && ! isLoading && (
213
227
< div className = "flex flex-col w-full mb-8" >
214
228
< ItemsList className = "mt-2 text-gray-500" >
215
- < Item header = { false } className = "grid grid-cols-5 bg-gray-100 mb-5" >
229
+ < Item header = { false } className = "grid grid-cols-5 gap-x-8 bg-gray-100 mb-5" >
216
230
< ItemField className = "my-auto" >
217
231
< span > Type</ span >
218
232
</ ItemField >
219
- < ItemField className = "my-auto" >
220
- < span > Class </ span >
233
+ < ItemField className = "col-span-2 my-auto" >
234
+ < span > ID </ span >
221
235
</ ItemField >
222
236
< ItemField className = "my-auto" >
223
- < span > Usage</ span >
224
- </ ItemField >
225
- < ItemField className = "flex my-auto" >
226
- < CreditsSvg className = "my-auto mr-1" />
227
237
< span > Credits</ span >
228
238
</ ItemField >
229
239
< ItemField className = "my-auto cursor-pointer" >
230
240
< span
231
241
className = "flex my-auto"
232
242
onClick = { ( ) => setIsStartedTimeDescending ( ! isStartedTimeDescending ) }
233
243
>
234
- Started
244
+ Timestamp
235
245
< SortArrow
236
246
className = { `h-4 w-4 my-auto ${
237
247
isStartedTimeDescending ? "" : " transform rotate-180"
@@ -241,30 +251,41 @@ function TeamUsage() {
241
251
</ ItemField >
242
252
</ Item >
243
253
{ currentPaginatedResults &&
244
- currentPaginatedResults . map ( ( usage ) => (
245
- < div
246
- key = { usage . instanceId }
247
- className = "flex p-3 grid grid-cols-5 justify-between transition ease-in-out rounded-xl focus:bg-gitpod-kumquat-light"
248
- >
249
- < div className = "my-auto" >
250
- < span > { getType ( usage . workspaceType ) } </ span >
251
- </ div >
252
- < div className = "my-auto" >
253
- < span className = "text-gray-400" > { usage . workspaceClass } </ span >
254
- </ div >
255
- < div className = "my-auto" >
256
- < span className = "text-gray-700" > { getMinutes ( usage ) } </ span >
257
- </ div >
258
- < div className = "my-auto" >
259
- < span className = "text-gray-700" > { usage . credits . toFixed ( 1 ) } </ span >
260
- </ div >
261
- < div className = "my-auto" >
262
- < span className = "text-gray-400" >
263
- { displayTime ( usage . startTime ) }
264
- </ span >
254
+ currentPaginatedResults . map ( ( usage ) => {
255
+ return (
256
+ < div
257
+ key = { usage . instanceId }
258
+ className = "flex p-3 grid grid-cols-5 gap-x-8 justify-between transition ease-in-out rounded-xl focus:bg-gitpod-kumquat-light"
259
+ >
260
+ < div className = "flex flex-col my-auto" >
261
+ < span > { getType ( usage . workspaceType ) } </ span >
262
+ < span className = "text-sm text-gray-400" >
263
+ { usage . workspaceClass }
264
+ </ span >
265
+ </ div >
266
+ < div className = "flex flex-col col-span-2 my-auto" >
267
+ < span className = "text-gray-700" > { usage . workspaceId } </ span >
268
+ < span className = "text-sm text-gray-400" >
269
+ { usage . contextURL }
270
+ </ span >
271
+ </ div >
272
+ < div className = "flex flex-col my-auto" >
273
+ < span className = "text-gray-700" >
274
+ { usage . credits . toFixed ( 1 ) }
275
+ </ span >
276
+ < span className = "text-sm text-gray-400" >
277
+ { getMinutes ( usage ) }
278
+ </ span >
279
+ </ div >
280
+ < div className = "flex flex-col my-auto" >
281
+ < span className = "text-gray-400" >
282
+ { displayTime ( usage . startTime ) }
283
+ </ span >
284
+ < span className = "text-sm text-gray-400" > user</ span >
285
+ </ div >
265
286
</ div >
266
- </ div >
267
- ) ) }
287
+ ) ;
288
+ } ) }
268
289
</ ItemsList >
269
290
{ billedUsage . length > resultsPerPage && (
270
291
< Pagination
0 commit comments