1
1
import {
2
- Bullseye ,
3
2
Button ,
4
3
ButtonVariant ,
5
4
EmptyState ,
@@ -9,22 +8,20 @@ import {
9
8
EmptyStateIcon ,
10
9
Label ,
11
10
Popover ,
12
- Spinner ,
13
11
} from '@patternfly/react-core' ;
14
12
import { DownloadIcon } from '@patternfly/react-icons/dist/esm/icons/download-icon' ;
15
13
import { ExclamationCircleIcon } from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon' ;
16
14
import { OutlinedClockIcon } from '@patternfly/react-icons/dist/esm/icons/outlined-clock-icon' ;
17
15
import { PlusCircleIcon } from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon' ;
18
16
import { SyncIcon } from '@patternfly/react-icons/dist/esm/icons/sync-icon' ;
19
- import { sortable , SortByDirection , TableVariant } from '@patternfly/react-table' ;
20
- import { Table , TableBody , TableHeader } from '@patternfly/react-table/deprecated' ;
21
17
import type { Query } from 'api/queries/query' ;
22
18
import { getQuery } from 'api/queries/query' ;
23
19
import type { Report } from 'api/reports/report' ;
24
20
import messages from 'locales/messages' ;
25
21
import React from 'react' ;
26
22
import type { WrappedComponentProps } from 'react-intl' ;
27
23
import { injectIntl } from 'react-intl' ;
24
+ import { DataTable } from 'routes/components/dataTable' ;
28
25
import type { DropdownWrapperItem } from 'routes/components/dropdownWrapper' ;
29
26
import { DropdownWrapper } from 'routes/components/dropdownWrapper' ;
30
27
import { EmptyFilterState } from 'routes/components/state/emptyFilterState' ;
@@ -34,38 +31,24 @@ import { styles } from './exportsTable.styles';
34
31
interface ExportsTableOwnProps {
35
32
isLoading ?: boolean ;
36
33
onClose ( ) ;
37
- onSort ( value : string , isSortAscending : boolean ) ;
34
+ onSort ( sortType : string , isSortAscending : boolean ) ;
38
35
query : Query ;
39
36
report : Report ;
40
37
}
41
38
42
39
interface ExportsTableState {
43
40
columns ?: any [ ] ;
44
- loadingRows ?: any [ ] ;
45
41
rows ?: any [ ] ;
46
42
}
47
43
48
44
type ExportsTableProps = ExportsTableOwnProps & WrappedComponentProps ;
49
45
50
- export const ExportsTableColumnIds = {
51
- actions : 'actions' ,
52
- created : 'created' ,
53
- expires : 'expires' ,
54
- names : 'names' ,
55
- status : 'status' ,
56
- } ;
57
-
58
46
class ExportsTableBase extends React . Component < ExportsTableProps , ExportsTableState > {
59
47
public state : ExportsTableState = {
60
48
columns : [ ] ,
61
49
rows : [ ] ,
62
50
} ;
63
51
64
- constructor ( props : ExportsTableProps ) {
65
- super ( props ) ;
66
- this . handleOnSort = this . handleOnSort . bind ( this ) ;
67
- }
68
-
69
52
public componentDidMount ( ) {
70
53
this . initDatum ( ) ;
71
54
}
@@ -91,69 +74,44 @@ class ExportsTableBase extends React.Component<ExportsTableProps, ExportsTableSt
91
74
92
75
const columns = [
93
76
{
94
- id : ExportsTableColumnIds . names ,
77
+ name : intl . formatMessage ( messages . names , { count : 1 } ) ,
95
78
orderBy : 'name' ,
96
- title : intl . formatMessage ( messages . names , { count : 1 } ) ,
97
- ...( isSortable && { transforms : [ sortable ] } ) ,
79
+ isSortable,
98
80
} ,
99
81
{
100
- id : ExportsTableColumnIds . created ,
82
+ name : intl . formatMessage ( messages . timeOfExport ) ,
101
83
orderBy : 'created' ,
102
- title : intl . formatMessage ( messages . timeOfExport ) ,
103
- ...( isSortable && { transforms : [ sortable ] } ) ,
84
+ isSortable,
104
85
} ,
105
86
{
106
- id : ExportsTableColumnIds . expires ,
87
+ name : intl . formatMessage ( messages . expiresOn ) ,
107
88
orderBy : 'expires' ,
108
- title : intl . formatMessage ( messages . expiresOn ) ,
109
- ...( isSortable && { transforms : [ sortable ] } ) ,
89
+ isSortable,
110
90
} ,
111
91
{
112
- id : ExportsTableColumnIds . status ,
113
- title : intl . formatMessage ( messages . statusActions ) ,
92
+ name : intl . formatMessage ( messages . statusActions ) ,
114
93
} ,
115
94
{
116
- id : ExportsTableColumnIds . actions ,
117
- title : '' ,
95
+ name : '' ,
118
96
} ,
119
97
] ;
120
98
121
99
if ( report . data . length ) {
122
100
report . data . map ( ( item : any ) => {
123
101
rows . push ( {
124
102
cells : [
125
- { title : < div > { item . name } </ div > , id : ExportsTableColumnIds . names } ,
126
- { title : < div > { item . created } </ div > , id : ExportsTableColumnIds . created } ,
127
- { title : < div > { item . expires } </ div > , id : ExportsTableColumnIds . expires } ,
128
- { title : this . getStatus ( item . status ) , id : ExportsTableColumnIds . status } ,
129
- { title : this . getActions ( ) , id : ExportsTableColumnIds . actions } ,
103
+ { value : item . name } ,
104
+ { value : item . created } ,
105
+ { value : item . expires } ,
106
+ { value : this . getStatus ( item . status ) } ,
107
+ { value : this . getActions ( ) } ,
130
108
] ,
131
109
item,
132
110
} ) ;
133
111
} ) ;
134
112
}
135
-
136
- const loadingRows = [
137
- {
138
- heightAuto : true ,
139
- cells : [
140
- {
141
- props : { colSpan : 7 } ,
142
- title : (
143
- < Bullseye >
144
- < div style = { { textAlign : 'center' } } >
145
- < Spinner size = "xl" />
146
- </ div >
147
- </ Bullseye >
148
- ) ,
149
- } ,
150
- ] ,
151
- } ,
152
- ] ;
153
-
154
113
this . setState ( {
155
114
columns,
156
- loadingRows,
157
115
rows,
158
116
} ) ;
159
117
} ;
@@ -198,27 +156,6 @@ class ExportsTableBase extends React.Component<ExportsTableProps, ExportsTableSt
198
156
) ;
199
157
} ;
200
158
201
- private getSortBy = ( ) => {
202
- const { query } = this . props ;
203
- const { columns } = this . state ;
204
-
205
- let index = - 1 ;
206
- let direction : any = SortByDirection . asc ;
207
-
208
- for ( const key of Object . keys ( query . order_by ) ) {
209
- let c = 0 ;
210
- for ( const column of columns ) {
211
- if ( column . orderBy === key ) {
212
- direction = query . order_by [ key ] === 'asc' ? SortByDirection . asc : SortByDirection . desc ;
213
- index = c ;
214
- break ;
215
- }
216
- c ++ ;
217
- }
218
- }
219
- return index > - 1 ? { index, direction } : { } ;
220
- } ;
221
-
222
159
private getStatus = ( status : string ) => {
223
160
const { intl } = this . props ;
224
161
@@ -288,36 +225,20 @@ class ExportsTableBase extends React.Component<ExportsTableProps, ExportsTableSt
288
225
console . log ( 'handleOnDownload clicked' ) ;
289
226
} ;
290
227
291
- private handleOnSort = ( event , index , direction ) => {
292
- const { onSort } = this . props ;
293
- const { columns } = this . state ;
294
-
295
- if ( onSort ) {
296
- const orderBy = columns [ index - 1 ] . orderBy ;
297
- const isSortAscending = direction === SortByDirection . asc ;
298
- onSort ( orderBy , isSortAscending ) ;
299
- }
300
- } ;
301
-
302
228
public render ( ) {
303
- const { intl, isLoading } = this . props ;
304
- const { columns, loadingRows , rows } = this . state ;
229
+ const { intl, isLoading, onSort , query } = this . props ;
230
+ const { columns, rows } = this . state ;
305
231
306
232
return (
307
- < >
308
- < Table
309
- aria-label = { intl . formatMessage ( messages . exportsTableAriaLabel ) }
310
- cells = { columns }
311
- rows = { isLoading ? loadingRows : rows }
312
- sortBy = { this . getSortBy ( ) }
313
- onSort = { this . handleOnSort }
314
- variant = { TableVariant . compact }
315
- >
316
- < TableHeader />
317
- < TableBody />
318
- </ Table >
319
- { rows . length === 0 && < div style = { styles . emptyState } > { this . getEmptyState ( ) } </ div > }
320
- </ >
233
+ < DataTable
234
+ ariaLabel = { intl . formatMessage ( messages . exportsTableAriaLabel ) }
235
+ columns = { columns }
236
+ emptyState = { this . getEmptyState ( ) }
237
+ isLoading = { isLoading }
238
+ onSort = { onSort }
239
+ rows = { rows }
240
+ orderBy = { query . order_by }
241
+ />
321
242
) ;
322
243
}
323
244
}
0 commit comments