11import React from 'react' ;
2- import { createStyles , lighten , makeStyles , Theme } from '@material-ui/core/styles' ;
2+ import { createStyles , makeStyles , Theme } from '@material-ui/core/styles' ;
33import Table from '@material-ui/core/Table' ;
44import TableBody from '@material-ui/core/TableBody' ;
55import TableCell from '@material-ui/core/TableCell' ;
@@ -16,20 +16,11 @@ import Switch from '@material-ui/core/Switch';
1616import { loader } from "graphql.macro" ;
1717import { useQuery } from "@apollo/client" ;
1818import { 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" ;
3220import 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" ;
3324
3425interface SessionData {
3526 id : string ,
@@ -74,47 +65,6 @@ function createSessionData(
7465 } ;
7566}
7667
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-
11868function descendingComparator < T > ( a : T , b : T , orderBy : keyof T ) {
11969 if ( b [ orderBy ] < a [ orderBy ] ) {
12070 return - 1 ;
@@ -147,18 +97,17 @@ function stableSort<T>(array: T[], comparator: (a: T, b: T) => number) {
14797}
14898
14999interface HeadCell {
150- disablePadding : boolean ;
151100 id : keyof SessionData ;
152101 label : string ;
153102 numeric : boolean ;
154103}
155104
156105const 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' } ,
162111] ;
163112
164113const GRID_SESSIONS_QUERY = loader ( "../../graphql/sessions.gql" ) ;
@@ -183,7 +132,7 @@ function EnhancedTableHead(props: EnhancedTableProps) {
183132 < TableCell
184133 key = { headCell . id }
185134 align = { headCell . numeric ? 'right' : 'left' }
186- padding = { headCell . disablePadding ? 'none' : 'default' }
135+ padding = { 'default' }
187136 sortDirection = { orderBy === headCell . id ? order : false }
188137 >
189138 < TableSortLabel
@@ -211,31 +160,21 @@ const useToolbarStyles = makeStyles((theme: Theme) =>
211160 paddingLeft : theme . spacing ( 2 ) ,
212161 paddingRight : theme . spacing ( 1 ) ,
213162 } ,
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- } ,
224163 title : {
225164 flex : '1 1 100%' ,
226165 } ,
227166 } ) ,
228167) ;
229168
230- const EnhancedTableToolbar = ( ) => {
169+ const EnhancedTableToolbar = ( props ) => {
231170 const classes = useToolbarStyles ( ) ;
232171
233172 return (
234173 < Toolbar
235174 className = { classes . root }
236175 >
237176 < Typography className = { classes . title } variant = "h3" id = "tableTitle" component = "div" >
238- Sessions
177+ { props . title }
239178 </ Typography >
240179 </ Toolbar >
241180 ) ;
@@ -272,7 +211,17 @@ const useStyles = makeStyles((theme: Theme) =>
272211 } ,
273212 buttonMargin : {
274213 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+ } ,
276225 } ) ,
277226) ;
278227
@@ -310,6 +259,10 @@ export default function Sessions() {
310259 ) ;
311260 } ) ;
312261
262+ const queue = data . grid . sessionQueueRequests . map ( ( queuedSession ) => {
263+ return JSON . stringify ( JSON . parse ( queuedSession ) ) ;
264+ } ) ;
265+
313266 const handleRequestSort = ( event : React . MouseEvent < unknown > , property : keyof SessionData ) => {
314267 const isAsc = orderBy === property && order === 'asc' ;
315268 setOrder ( isAsc ? 'desc' : 'asc' ) ;
@@ -354,8 +307,24 @@ export default function Sessions() {
354307
355308 return (
356309 < 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+ ) }
357326 < Paper className = { classes . paper } >
358- < EnhancedTableToolbar />
327+ < EnhancedTableToolbar title = { "Sessions" } />
359328 < TableContainer >
360329 < Table
361330 className = { classes . table }
@@ -390,12 +359,12 @@ export default function Sessions() {
390359 </ TableCell >
391360 < TableCell align = "right" >
392361 < img
393- src = { osLogoPath ( row . platformName as string ) }
362+ src = { osLogo ( row . platformName as string ) }
394363 className = { classes . logo }
395364 alt = "OS Logo"
396365 />
397366 < img
398- src = { browserLogoPath ( row . browserName as string ) }
367+ src = { browserLogo ( row . browserName as string ) }
399368 className = { classes . logo }
400369 alt = "Browser Logo"
401370 />
@@ -407,12 +376,12 @@ export default function Sessions() {
407376 open = { rowOpen === row . id } >
408377 < DialogTitle id = "session-info-dialog" >
409378 < img
410- src = { osLogoPath ( row . platformName as string ) }
379+ src = { osLogo ( row . platformName as string ) }
411380 className = { classes . logo }
412381 alt = "OS Logo"
413382 />
414383 < img
415- src = { browserLogoPath ( row . browserName as string ) }
384+ src = { browserLogo ( row . browserName as string ) }
416385 className = { classes . logo }
417386 alt = "Browser Logo"
418387 />
0 commit comments