@@ -10,8 +10,13 @@ import {
10
10
Drawer ,
11
11
DrawerContent ,
12
12
DrawerContentBody ,
13
- Button
13
+ Button ,
14
+ EmptyState ,
15
+ EmptyStateIcon ,
16
+ EmptyStatePrimary ,
17
+ EmptyStateBody ,
14
18
} from '@patternfly/react-core' ;
19
+ import { SearchIcon } from '@patternfly/react-icons' ;
15
20
import { Table , Thead , Tr , Th , ThProps , Tbody , Td } from '@patternfly/react-table' ;
16
21
import { fetch } from 'cross-fetch'
17
22
import { DetailsDrawer } from './DetailsDrawer' ;
@@ -38,7 +43,6 @@ export const ImageTable: React.FunctionComponent = () => {
38
43
const [ perPage , setPerPage ] = React . useState ( 20 ) ;
39
44
const [ isDrawerExpanded , setIsExpanded ] = React . useState ( false ) ;
40
45
const [ selectedImage , setSelectedImage ] = React . useState ( { } ) ;
41
-
42
46
const [ providerSelections , setProviderSelections ] = React . useState < string [ ] > ( [ ] ) ;
43
47
const [ regionSelections , setRegionSelections ] = React . useState < string [ ] > ( [ ] ) ;
44
48
const [ architectureSelections , setArchitectureSelections ] = React . useState < string [ ] > ( [ ] ) ;
@@ -197,23 +201,23 @@ export const ImageTable: React.FunctionComponent = () => {
197
201
setFilterConfig ( [
198
202
{
199
203
category : 'provider' ,
200
- data : [ ...new Set ( data . map ( item => item [ 'provider' ] ) ) ]
204
+ data : [ ...new Set ( data . map ( ( item : string ) => item [ 'provider' ] ) ) ]
201
205
} ,
202
206
{
203
207
category : 'region' ,
204
- data : [ ...new Set ( data . map ( item => item [ 'region' ] ) ) ]
208
+ data : [ ...new Set ( data . map ( ( item : string ) => item [ 'region' ] ) ) ]
205
209
} ,
206
210
{
207
211
category : 'architecture' ,
208
- data : [ ...new Set ( data . map ( item => item [ 'arch' ] . toLowerCase ( ) ) ) ]
212
+ data : [ ...new Set ( data . map ( ( item : string ) => item [ 'arch' ] . toLowerCase ( ) ) ) ]
209
213
}
210
214
] ) ;
211
215
} )
212
216
} ;
213
217
214
- const handleSearch = ( event ) => {
218
+ const handleSearch = ( event : React . FormEvent < HTMLInputElement > ) => {
215
219
setIsExpanded ( false ) ;
216
- setSearch ( event . target . value ) ;
220
+ setSearch ( event . currentTarget . value ) ;
217
221
setPage ( 1 ) ;
218
222
} ;
219
223
@@ -284,6 +288,30 @@ export const ImageTable: React.FunctionComponent = () => {
284
288
details = { selectedImage } />
285
289
) ;
286
290
291
+ const emptyState = (
292
+ < EmptyState >
293
+ < EmptyStateIcon icon = { SearchIcon } />
294
+ < Title size = "lg" headingLevel = "h4" >
295
+ No results found
296
+ </ Title >
297
+ < EmptyStateBody > No results match the filter criteria. Clear all filters and try again.</ EmptyStateBody >
298
+ < EmptyStatePrimary >
299
+ < Button
300
+ variant = "link"
301
+ onClick = { ( ) => {
302
+ setIsExpanded ( false ) ;
303
+ setSearch ( '' ) ;
304
+ setPage ( 1 ) ;
305
+ onFilterDelete ( '' , '' ) ;
306
+ } }
307
+ >
308
+ Clear all filters
309
+ </ Button >
310
+ </ EmptyStatePrimary >
311
+ </ EmptyState >
312
+ ) ;
313
+ //add searchinput that clears once the setSearch is called
314
+
287
315
return (
288
316
< React . Fragment >
289
317
< Title headingLevel = 'h1' > Browse Images</ Title >
@@ -294,6 +322,7 @@ export const ImageTable: React.FunctionComponent = () => {
294
322
< ToolbarItem variant = "search-filter" >
295
323
< SearchInput
296
324
onChange = { handleSearch }
325
+ value = { search }
297
326
id = 'search'
298
327
placeholder = 'Search by name'
299
328
/>
@@ -356,24 +385,32 @@ export const ImageTable: React.FunctionComponent = () => {
356
385
</ Tr >
357
386
</ Thead >
358
387
< Tbody >
359
- { sortedImageData . map ( ( image : ImageData ) => (
360
- < Tr key = { image . name } >
361
- < Td dataLabel = { columnNames . name } > { image . name } </ Td >
362
- < Td dataLabel = { columnNames . provider } > { image . provider } </ Td >
363
- < Td dataLabel = { columnNames . region } > { image . region } </ Td >
364
- < Td dataLabel = { columnNames . arch } > { image . arch } </ Td >
365
- < Td dataLabel = { columnNames . date } > < p > { new Date ( image . date ) . toDateString ( ) } </ p > </ Td >
366
- < Td >
367
- < Button
368
- aria-expanded = { isDrawerExpanded }
369
- onClick = { e => onDrawerOpenClick ( image ) }
370
- variant = 'link'
371
- isInline >
372
- Launch now
373
- </ Button >
388
+ { sortedImageData . length > 0 &&
389
+ sortedImageData . map ( ( image : ImageData ) => (
390
+ < Tr key = { image . name } >
391
+ < Td dataLabel = { columnNames . name } > { image . name } </ Td >
392
+ < Td dataLabel = { columnNames . provider } > { image . provider } </ Td >
393
+ < Td dataLabel = { columnNames . region } > { image . region } </ Td >
394
+ < Td dataLabel = { columnNames . arch } > { image . arch } </ Td >
395
+ < Td dataLabel = { columnNames . date } > < p > { new Date ( image . date ) . toDateString ( ) } </ p > </ Td >
396
+ < Td >
397
+ < Button
398
+ aria-expanded = { isDrawerExpanded }
399
+ onClick = { e => onDrawerOpenClick ( image ) }
400
+ variant = 'link'
401
+ isInline >
402
+ Launch now
403
+ </ Button >
404
+ </ Td >
405
+ </ Tr >
406
+ ) ) }
407
+ { sortedImageData . length === 0 && (
408
+ < Tr >
409
+ < Td colSpan = { 8 } >
410
+ { emptyState }
374
411
</ Td >
375
412
</ Tr >
376
- ) ) }
413
+ ) }
377
414
</ Tbody >
378
415
</ Table >
379
416
</ DrawerContentBody >
0 commit comments