11import React from "react" ;
2- import { Chip } from "@material-ui/core" ;
2+ import { Chip , Typography } from "@material-ui/core" ;
33import TestStatusChip from "../TestStatusChip" ;
44import {
55 useTestRunState ,
66 useTestRunDispatch ,
7- getTestRunList ,
87 useBuildState ,
9- selectTestRun ,
108} from "../../contexts" ;
119import { useSnackbar } from "notistack" ;
1210import {
@@ -26,6 +24,9 @@ import { DataGridCustomToolbar } from "./DataGridCustomToolbar";
2624import { StatusFilterOperators } from "./StatusFilterOperators" ;
2725import { TagFilterOperators } from "./TagFilterOperators" ;
2826import { TestStatus } from "../../types" ;
27+ import { testRunService } from "../../services" ;
28+ import { useHistory } from "react-router" ;
29+ import { buildTestRunLocation } from "../../_helpers/route.helpers" ;
2930
3031const columnsDef : GridColDef [ ] = [
3132 { field : "id" , hide : true , filterable : false } ,
@@ -97,8 +98,9 @@ const columnsDef: GridColDef[] = [
9798
9899const TestRunList : React . FunctionComponent = ( ) => {
99100 const { enqueueSnackbar } = useSnackbar ( ) ;
100- const { testRun, testRuns, loading } = useTestRunState ( ) ;
101- const { selectedBuildId } = useBuildState ( ) ;
101+ const history = useHistory ( ) ;
102+ const { selectedTestRun, testRuns, loading } = useTestRunState ( ) ;
103+ const { selectedBuild } = useBuildState ( ) ;
102104 const testRunDispatch = useTestRunDispatch ( ) ;
103105
104106 const [ sortModel , setSortModel ] = React . useState < GridSortModel > ( [
@@ -108,24 +110,29 @@ const TestRunList: React.FunctionComponent = () => {
108110 } ,
109111 ] ) ;
110112
111- const getTestRunListCallback = React . useCallback (
112- ( ) =>
113- selectedBuildId &&
114- getTestRunList ( testRunDispatch , selectedBuildId ) . catch ( ( err : string ) =>
115- enqueueSnackbar ( err , {
116- variant : "error" ,
117- } )
118- ) ,
119- [ testRunDispatch , enqueueSnackbar , selectedBuildId ]
120- ) ;
113+ const getTestRunListCallback = React . useCallback ( ( ) => {
114+ testRunDispatch ( { type : "request" } ) ;
115+ if ( selectedBuild ?. id ) {
116+ testRunService
117+ . getList ( selectedBuild . id )
118+ . then ( ( payload ) => testRunDispatch ( { type : "get" , payload } ) )
119+ . catch ( ( err : string ) =>
120+ enqueueSnackbar ( err , {
121+ variant : "error" ,
122+ } )
123+ ) ;
124+ } else {
125+ testRunDispatch ( { type : "get" , payload : [ ] } ) ;
126+ }
127+ } , [ testRunDispatch , enqueueSnackbar , selectedBuild ?. id ] ) ;
121128
122129 React . useEffect ( ( ) => {
123130 getTestRunListCallback ( ) ;
124131 } , [ getTestRunListCallback ] ) ;
125132
126133 return (
127134 < React . Fragment >
128- { selectedBuildId && (
135+ { selectedBuild ? (
129136 < DataGrid
130137 rows = { testRuns }
131138 columns = { columnsDef }
@@ -142,13 +149,15 @@ const TestRunList: React.FunctionComponent = () => {
142149 sortModel = { sortModel }
143150 onSortModelChange = { ( model ) => setSortModel ( model ) }
144151 onRowClick = { ( param : GridRowParams ) => {
145- selectTestRun (
146- testRunDispatch ,
147- param . getValue ( param . id , "id" ) ?. toString ( )
152+ history . push (
153+ buildTestRunLocation (
154+ selectedBuild . id ,
155+ param . getValue ( param . id , "id" ) ?. toString ( )
156+ )
148157 ) ;
149158 } }
150159 onStateChange = { ( props : GridStateChangeParams ) => {
151- if ( ! testRun ) {
160+ if ( ! selectedTestRun ) {
152161 // only if testRun modal is not shown
153162 testRunDispatch ( {
154163 type : "filter" ,
@@ -161,6 +170,8 @@ const TestRunList: React.FunctionComponent = () => {
161170 }
162171 } }
163172 />
173+ ) : (
174+ < Typography variant = "h5" > Select build from list</ Typography >
164175 ) }
165176 </ React . Fragment >
166177 ) ;
0 commit comments