11import React , { Component } from 'react' ;
22import { connect } from 'dva' ;
33import { routerRedux } from 'dva/router' ;
4- import { Card , Form } from 'antd' ;
4+ import { Card , Form , Icon , Tabs } from 'antd' ;
55
66import SearchBar from '@/components/SearchBar' ;
77import RowSelection from '@/components/RowSelection' ;
88import Table from '@/components/Table' ;
99import PageHeaderLayout from '../../layouts/PageHeaderLayout' ;
1010
11- @connect ( ( { datastore, global, dashboard, loading } ) => ( {
11+ const { TabPane } = Tabs ;
12+
13+ @connect ( ( { datastore, global, dashboard, loading, user } ) => ( {
1214 selectedIndices : global . selectedIndices ,
1315 results : dashboard . results [ global . selectedControllers [ 0 ] ]
1416 ? dashboard . results [ global . selectedControllers [ 0 ] ]
1517 : [ ] ,
1618 selectedControllers : global . selectedControllers ,
1719 datastoreConfig : datastore . datastoreConfig ,
20+ favoriteResults : user . favoriteResults ,
1821 loading : loading . effects [ 'dashboard/fetchResults' ] ,
1922} ) )
2023class Results extends Component {
@@ -121,9 +124,20 @@ class Results extends Component {
121124 ) ;
122125 } ;
123126
127+ favoriteRecord = ( event , value , result ) => {
128+ // Stop propagation from going to the next page
129+ event . stopPropagation ( ) ;
130+ const { dispatch } = this . props ;
131+ // dispatch an action to favorite result
132+ dispatch ( {
133+ type : 'user/favoriteResult' ,
134+ payload : result ,
135+ } ) ;
136+ } ;
137+
124138 render ( ) {
125139 const { results, selectedRows } = this . state ;
126- const { selectedControllers, loading } = this . props ;
140+ const { selectedControllers, loading, favoriteResults } = this . props ;
127141 const rowSelection = {
128142 // eslint-disable-next-line no-shadow
129143 onSelect : ( record , selected , selectedRows ) => this . onSelectChange ( selectedRows ) ,
@@ -152,6 +166,29 @@ class Results extends Component {
152166 dataIndex : 'run.end' ,
153167 key : 'run.end' ,
154168 } ,
169+ {
170+ title : 'Actions' ,
171+ dataIndex : 'actions' ,
172+ key : 'actions' ,
173+ render : ( value , row ) => {
174+ // if already favorited return a filled star,
175+ // else allow user to favorite a record
176+ let isFavorite = false ;
177+ favoriteResults . forEach ( item => {
178+ if ( item . key === row . key ) {
179+ isFavorite = true ;
180+ }
181+ } ) ;
182+ if ( isFavorite ) {
183+ return < Icon type = "star" theme = "filled" /> ;
184+ }
185+ return (
186+ < a onClick = { e => this . favoriteRecord ( e , null , row ) } >
187+ < Icon type = "star" />
188+ </ a >
189+ ) ;
190+ } ,
191+ } ,
155192 ] ;
156193
157194 return (
@@ -169,19 +206,36 @@ class Results extends Component {
169206 onCompare = { this . compareResults }
170207 />
171208 </ Form >
172- < Table
173- style = { { marginTop : 16 } }
174- rowSelection = { rowSelection }
175- columns = { columns }
176- dataSource = { results }
177- onRow = { record => ( {
178- onClick : ( ) => {
179- this . retrieveResults ( [ record ] ) ;
180- } ,
181- } ) }
182- loading = { loading }
183- bordered
184- />
209+ < Tabs type = "card" style = { { marginTop : 16 } } >
210+ < TabPane tab = "Results" key = "results" >
211+ < Table
212+ rowSelection = { rowSelection }
213+ columns = { columns }
214+ dataSource = { results }
215+ onRow = { record => ( {
216+ onClick : ( ) => {
217+ this . retrieveResults ( [ record ] ) ;
218+ } ,
219+ } ) }
220+ loading = { loading }
221+ bordered
222+ />
223+ </ TabPane >
224+ < TabPane tab = "Favorites" key = "favorites" >
225+ < Table
226+ rowSelection = { rowSelection }
227+ columns = { columns }
228+ dataSource = { favoriteResults }
229+ onRow = { record => ( {
230+ onClick : ( ) => {
231+ this . retrieveResults ( [ record ] ) ;
232+ } ,
233+ } ) }
234+ loading = { loading }
235+ bordered
236+ />
237+ </ TabPane >
238+ </ Tabs >
185239 </ Card >
186240 </ PageHeaderLayout >
187241 ) ;
0 commit comments