1
1
import React from 'react' ;
2
- import { createStyles , lighten , makeStyles , Theme } from '@material-ui/core/styles' ;
2
+ import { createStyles , makeStyles , Theme } from '@material-ui/core/styles' ;
3
3
import Table from '@material-ui/core/Table' ;
4
4
import TableBody from '@material-ui/core/TableBody' ;
5
5
import TableCell from '@material-ui/core/TableCell' ;
@@ -16,20 +16,11 @@ import Switch from '@material-ui/core/Switch';
16
16
import { loader } from "graphql.macro" ;
17
17
import { useQuery } from "@apollo/client" ;
18
18
import { GridConfig } from "../../config" ;
19
- import chromeLogo from "../../assets/browsers/chrome.svg" ;
20
- import edgeLogo from "../../assets/browsers/edge.svg" ;
21
- import operaLogo from "../../assets/browsers/opera.svg" ;
22
- import firefoxLogo from "../../assets/browsers/firefox.svg" ;
23
- import internetExplorerLogo from "../../assets/browsers/internet-explorer.svg" ;
24
- import safariLogo from "../../assets/browsers/safari.svg" ;
25
- import safariTechnologyPreviewLogo from "../../assets/browsers/safari-technology-preview.png" ;
26
- import unknownBrowserLogo from "../../assets/browsers/unknown.svg" ;
27
- import macLogo from "../../assets/operating-systems/mac.svg" ;
28
- import windowsLogo from "../../assets/operating-systems/windows.svg" ;
29
- import linuxLogo from "../../assets/operating-systems/linux.svg" ;
30
- import unknownOsLogo from "../../assets/operating-systems/unknown.svg" ;
31
- import { Button , Dialog , DialogActions , DialogContent , DialogTitle , IconButton } from "@material-ui/core" ;
19
+ import { Button , Dialog , DialogActions , DialogContent , DialogTitle , IconButton , List , ListItem } from "@material-ui/core" ;
32
20
import InfoIcon from "@material-ui/icons/Info" ;
21
+ import browserLogo from "../../util/browser-logo" ;
22
+ import osLogo from "../../util/os-logo" ;
23
+ import browserVersion from "../../util/browser-version" ;
33
24
34
25
interface SessionData {
35
26
id : string ,
@@ -74,47 +65,6 @@ function createSessionData(
74
65
} ;
75
66
}
76
67
77
- const browserLogoPath = ( browser : string ) : string => {
78
- switch ( browser . toLowerCase ( ) ) {
79
- case "chrome" :
80
- return chromeLogo ;
81
- case "microsoftedge" :
82
- return edgeLogo ;
83
- case "operablink" :
84
- return operaLogo ;
85
- case "opera" :
86
- return operaLogo ;
87
- case "firefox" :
88
- return firefoxLogo ;
89
- case "internet explorer" :
90
- return internetExplorerLogo ;
91
- case "safari" :
92
- return safariLogo ;
93
- case "safari technology preview" :
94
- return safariTechnologyPreviewLogo ;
95
- default :
96
- return unknownBrowserLogo ;
97
- }
98
- } ;
99
-
100
- const browserVersion = ( version : string ) : string => {
101
- return version . length > 0 ? " - v." + version : version ;
102
- }
103
-
104
- const osLogoPath = ( os : string ) : string => {
105
- const osLowerCase : string = os . toLowerCase ( ) ;
106
- if ( osLowerCase . includes ( "win" ) ) {
107
- return windowsLogo ;
108
- }
109
- if ( osLowerCase . includes ( "mac" ) ) {
110
- return macLogo ;
111
- }
112
- if ( osLowerCase . includes ( "nix" ) || osLowerCase . includes ( "nux" ) || osLowerCase . includes ( "aix" ) ) {
113
- return linuxLogo ;
114
- }
115
- return unknownOsLogo ;
116
- } ;
117
-
118
68
function descendingComparator < T > ( a : T , b : T , orderBy : keyof T ) {
119
69
if ( b [ orderBy ] < a [ orderBy ] ) {
120
70
return - 1 ;
@@ -147,18 +97,17 @@ function stableSort<T>(array: T[], comparator: (a: T, b: T) => number) {
147
97
}
148
98
149
99
interface HeadCell {
150
- disablePadding : boolean ;
151
100
id : keyof SessionData ;
152
101
label : string ;
153
102
numeric : boolean ;
154
103
}
155
104
156
105
const headCells : HeadCell [ ] = [
157
- { id : 'id' , numeric : false , disablePadding : false , label : 'ID' } ,
158
- { id : 'rawCapabilities' , numeric : false , disablePadding : false , label : 'Capabilities' } ,
159
- { id : 'startTime' , numeric : false , disablePadding : false , label : 'Start time' } ,
160
- { id : 'sessionDurationMillis' , numeric : true , disablePadding : false , label : 'Duration' } ,
161
- { id : 'nodeUri' , numeric : false , disablePadding : false , label : 'Node URI' } ,
106
+ { id : 'id' , numeric : false , label : 'ID' } ,
107
+ { id : 'rawCapabilities' , numeric : false , label : 'Capabilities' } ,
108
+ { id : 'startTime' , numeric : false , label : 'Start time' } ,
109
+ { id : 'sessionDurationMillis' , numeric : true , label : 'Duration' } ,
110
+ { id : 'nodeUri' , numeric : false , label : 'Node URI' } ,
162
111
] ;
163
112
164
113
const GRID_SESSIONS_QUERY = loader ( "../../graphql/sessions.gql" ) ;
@@ -183,7 +132,7 @@ function EnhancedTableHead(props: EnhancedTableProps) {
183
132
< TableCell
184
133
key = { headCell . id }
185
134
align = { headCell . numeric ? 'right' : 'left' }
186
- padding = { headCell . disablePadding ? 'none' : 'default' }
135
+ padding = { 'default' }
187
136
sortDirection = { orderBy === headCell . id ? order : false }
188
137
>
189
138
< TableSortLabel
@@ -211,31 +160,21 @@ const useToolbarStyles = makeStyles((theme: Theme) =>
211
160
paddingLeft : theme . spacing ( 2 ) ,
212
161
paddingRight : theme . spacing ( 1 ) ,
213
162
} ,
214
- highlight :
215
- theme . palette . type === 'light'
216
- ? {
217
- color : theme . palette . secondary . main ,
218
- backgroundColor : lighten ( theme . palette . secondary . light , 0.85 ) ,
219
- }
220
- : {
221
- color : theme . palette . text . primary ,
222
- backgroundColor : theme . palette . secondary . dark ,
223
- } ,
224
163
title : {
225
164
flex : '1 1 100%' ,
226
165
} ,
227
166
} ) ,
228
167
) ;
229
168
230
- const EnhancedTableToolbar = ( ) => {
169
+ const EnhancedTableToolbar = ( props ) => {
231
170
const classes = useToolbarStyles ( ) ;
232
171
233
172
return (
234
173
< Toolbar
235
174
className = { classes . root }
236
175
>
237
176
< Typography className = { classes . title } variant = "h3" id = "tableTitle" component = "div" >
238
- Sessions
177
+ { props . title }
239
178
</ Typography >
240
179
</ Toolbar >
241
180
) ;
@@ -272,7 +211,17 @@ const useStyles = makeStyles((theme: Theme) =>
272
211
} ,
273
212
buttonMargin : {
274
213
padding : 1 ,
275
- }
214
+ } ,
215
+ queueList : {
216
+ minWidth : 750 ,
217
+ backgroundColor : theme . palette . background . paper ,
218
+ marginBottom : 20 ,
219
+ } ,
220
+ queueListItem : {
221
+ borderBottomWidth : 1 ,
222
+ borderBottomStyle : 'solid' ,
223
+ borderBottomColor : '#e0e0e0' ,
224
+ } ,
276
225
} ) ,
277
226
) ;
278
227
@@ -310,6 +259,10 @@ export default function Sessions() {
310
259
) ;
311
260
} ) ;
312
261
262
+ const queue = data . grid . sessionQueueRequests . map ( ( queuedSession ) => {
263
+ return JSON . stringify ( JSON . parse ( queuedSession ) ) ;
264
+ } ) ;
265
+
313
266
const handleRequestSort = ( event : React . MouseEvent < unknown > , property : keyof SessionData ) => {
314
267
const isAsc = orderBy === property && order === 'asc' ;
315
268
setOrder ( isAsc ? 'desc' : 'asc' ) ;
@@ -354,8 +307,24 @@ export default function Sessions() {
354
307
355
308
return (
356
309
< div className = { classes . root } >
310
+ { queue . length > 0 && (
311
+ < div className = { classes . queueList } >
312
+ < EnhancedTableToolbar title = { `Queue (${ queue . length } )` } />
313
+ < List component = "nav" aria-label = "main mailbox folders" >
314
+ { queue . map ( ( queueItem , index ) => {
315
+ return (
316
+ < ListItem className = { classes . queueListItem } key = { index } >
317
+ < pre >
318
+ { queueItem }
319
+ </ pre >
320
+ </ ListItem >
321
+ )
322
+ } ) }
323
+ </ List >
324
+ </ div >
325
+ ) }
357
326
< Paper className = { classes . paper } >
358
- < EnhancedTableToolbar />
327
+ < EnhancedTableToolbar title = { "Sessions" } />
359
328
< TableContainer >
360
329
< Table
361
330
className = { classes . table }
@@ -390,12 +359,12 @@ export default function Sessions() {
390
359
</ TableCell >
391
360
< TableCell align = "right" >
392
361
< img
393
- src = { osLogoPath ( row . platformName as string ) }
362
+ src = { osLogo ( row . platformName as string ) }
394
363
className = { classes . logo }
395
364
alt = "OS Logo"
396
365
/>
397
366
< img
398
- src = { browserLogoPath ( row . browserName as string ) }
367
+ src = { browserLogo ( row . browserName as string ) }
399
368
className = { classes . logo }
400
369
alt = "Browser Logo"
401
370
/>
@@ -407,12 +376,12 @@ export default function Sessions() {
407
376
open = { rowOpen === row . id } >
408
377
< DialogTitle id = "session-info-dialog" >
409
378
< img
410
- src = { osLogoPath ( row . platformName as string ) }
379
+ src = { osLogo ( row . platformName as string ) }
411
380
className = { classes . logo }
412
381
alt = "OS Logo"
413
382
/>
414
383
< img
415
- src = { browserLogoPath ( row . browserName as string ) }
384
+ src = { browserLogo ( row . browserName as string ) }
416
385
className = { classes . logo }
417
386
alt = "Browser Logo"
418
387
/>
0 commit comments