@@ -15,6 +15,7 @@ import { MoreVert } from "@material-ui/icons";
1515import { useHistory } from "react-router-dom" ;
1616import { TestRun } from "../types" ;
1717import TestStatusChip from "./TestStatusChip" ;
18+ import { buildTestRunLocation } from "../_helpers/route.helpers" ;
1819
1920const TestRunList : React . FunctionComponent < {
2021 items : TestRun [ ] ;
@@ -23,84 +24,94 @@ const TestRunList: React.FunctionComponent<{
2324} > = ( { items, selectedId, handleRemove } ) => {
2425 const history = useHistory ( ) ;
2526 const [ anchorEl , setAnchorEl ] = React . useState < null | HTMLElement > ( null ) ;
26- const open = Boolean ( anchorEl ) ;
27+ const [ selectedTestRun , setSelectedTestRun ] = React . useState <
28+ TestRun | undefined
29+ > ( undefined ) ;
2730
28- const handleClick = ( event : React . MouseEvent < HTMLElement > ) => {
31+ const handleClick = (
32+ event : React . MouseEvent < HTMLElement > ,
33+ testRun : TestRun
34+ ) => {
2935 event . stopPropagation ( ) ;
3036 setAnchorEl ( event . currentTarget ) ;
37+ setSelectedTestRun ( testRun ) ;
3138 } ;
3239
3340 const handleClose = ( ) => {
34- setAnchorEl ( null ) ;
41+ setSelectedTestRun ( undefined ) ;
3542 } ;
3643
3744 return (
38- < TableContainer >
39- < Table >
40- < TableHead >
41- < TableRow >
42- < TableCell > Name</ TableCell >
43- < TableCell > OS</ TableCell >
44- < TableCell > Browser</ TableCell >
45- < TableCell > Viewport</ TableCell >
46- < TableCell > Status</ TableCell >
47- < TableCell > </ TableCell >
48- </ TableRow >
49- </ TableHead >
50- < TableBody >
51- { items . map ( ( test ) => (
52- < TableRow key = { test . id } hover selected = { test . id === selectedId } >
53- < TableCell
54- onClick = { ( ) => {
55- history . push ( {
56- search : `buildId=${ test . buildId } &testId=${ test . id } ` ,
57- } ) ;
58- } }
59- >
60- < Typography > { test . testVariation . name } </ Typography >
61- </ TableCell >
62- < TableCell >
63- < Typography > { test . testVariation . os } </ Typography >
64- </ TableCell >
65- < TableCell >
66- < Typography > { test . testVariation . browser } </ Typography >
67- </ TableCell >
68- < TableCell >
69- < Typography > { test . testVariation . viewport } </ Typography >
70- </ TableCell >
71- < TableCell >
72- < TestStatusChip status = { test . status } />
73- </ TableCell >
74- < TableCell >
75- < IconButton onClick = { handleClick } >
76- < MoreVert />
77- </ IconButton >
78- < Menu anchorEl = { anchorEl } open = { open } onClose = { handleClose } >
79- < MenuItem
80- onClick = { ( ) => {
81- history . push ( {
82- search : `buildId=${ test . buildId } &testId=${ test . id } ` ,
83- } ) ;
84- handleClose ( ) ;
85- } }
86- >
87- Details
88- </ MenuItem >
89- < MenuItem
90- onClick = { ( ) => {
91- handleRemove ( test . id ) ;
92- handleClose ( ) ;
93- } }
94- >
95- Delete
96- </ MenuItem >
97- </ Menu >
98- </ TableCell >
45+ < React . Fragment >
46+ < TableContainer >
47+ < Table >
48+ < TableHead >
49+ < TableRow >
50+ < TableCell > Name</ TableCell >
51+ < TableCell > OS</ TableCell >
52+ < TableCell > Browser</ TableCell >
53+ < TableCell > Viewport</ TableCell >
54+ < TableCell > Status</ TableCell >
55+ < TableCell > </ TableCell >
9956 </ TableRow >
100- ) ) }
101- </ TableBody >
102- </ Table >
103- </ TableContainer >
57+ </ TableHead >
58+ < TableBody >
59+ { items . map ( ( test ) => (
60+ < TableRow key = { test . id } hover selected = { test . id === selectedId } >
61+ < TableCell
62+ onClick = { ( ) => {
63+ history . push ( buildTestRunLocation ( test ) ) ;
64+ } }
65+ >
66+ < Typography > { test . testVariation . name } </ Typography >
67+ </ TableCell >
68+ < TableCell >
69+ < Typography > { test . testVariation . os } </ Typography >
70+ </ TableCell >
71+ < TableCell >
72+ < Typography > { test . testVariation . browser } </ Typography >
73+ </ TableCell >
74+ < TableCell >
75+ < Typography > { test . testVariation . viewport } </ Typography >
76+ </ TableCell >
77+ < TableCell >
78+ < TestStatusChip status = { test . status } />
79+ </ TableCell >
80+ < TableCell >
81+ < IconButton onClick = { ( event ) => handleClick ( event , test ) } >
82+ < MoreVert />
83+ </ IconButton >
84+ </ TableCell >
85+ </ TableRow >
86+ ) ) }
87+ </ TableBody >
88+ </ Table >
89+ </ TableContainer >
90+ { selectedTestRun && (
91+ < Menu
92+ anchorEl = { anchorEl }
93+ open = { ! ! selectedTestRun }
94+ onClose = { handleClose }
95+ >
96+ < MenuItem
97+ onClick = { ( ) => {
98+ history . push ( buildTestRunLocation ( selectedTestRun ) ) ;
99+ handleClose ( ) ;
100+ } }
101+ >
102+ Details
103+ </ MenuItem >
104+ < MenuItem
105+ onClick = { ( ) => {
106+ handleRemove ( selectedTestRun . id ) ;
107+ handleClose ( ) ;
108+ } }
109+ >
110+ Delete
111+ </ MenuItem >
112+ </ Menu >
113+ ) }
114+ </ React . Fragment >
104115 ) ;
105116} ;
106117
0 commit comments