@@ -29,11 +29,13 @@ import {
29
29
ValueMatcher ,
30
30
withTr ,
31
31
} from '@kubev2v/common' ;
32
+ import { BulkSelect , BulkSelectValue } from '@patternfly/react-component-groups' ;
32
33
import {
33
34
Level ,
34
35
LevelItem ,
35
36
PageSection ,
36
37
Pagination ,
38
+ Split ,
37
39
Title ,
38
40
Toolbar ,
39
41
ToolbarContent ,
@@ -224,11 +226,6 @@ export interface StandardPageProps<T> {
224
226
* Expanded ids
225
227
*/
226
228
expandedIds ?: string [ ] ;
227
-
228
- /**
229
- * Label to show count of selected items
230
- */
231
- selectedCountLabel ?: ( selectedIdCount : number ) => string ;
232
229
}
233
230
234
231
/**
@@ -286,7 +283,7 @@ export function StandardPage<T>({
286
283
expandedIds,
287
284
className,
288
285
selectedIds,
289
- selectedCountLabel ,
286
+ onSelect ,
290
287
} : StandardPageProps < T > ) {
291
288
const { t } = useForkliftTranslation ( ) ;
292
289
const [ sortedData , setSortedData ] = useState ( [ ] ) ;
@@ -340,6 +337,8 @@ export function StandardPage<T>({
340
337
const errorFetchingData = error ;
341
338
const noResults = loaded && ! error && sortedData . length == 0 ;
342
339
const noMatchingResults = loaded && ! error && filteredData . length === 0 && sortedData . length > 0 ;
340
+ const pageDataIds = pageData . map ( toId ) ;
341
+ const filteredDataIds = filteredData . map ( toId ) ;
343
342
344
343
const primaryFilters = fields
345
344
. filter ( ( field ) => field . filter ?. primary )
@@ -366,6 +365,15 @@ export function StandardPage<T>({
366
365
setPage ( page ) ;
367
366
} ;
368
367
368
+ const onBulkSelect = ( value : BulkSelectValue ) => {
369
+ value === BulkSelectValue . none && onSelect ( [ ] ) ;
370
+ value === BulkSelectValue . all && onSelect ( filteredDataIds ) ;
371
+ value === BulkSelectValue . nonePage &&
372
+ onSelect ( selectedIds . filter ( ( item ) => ! pageDataIds . includes ( item ) ) ) ;
373
+ value === BulkSelectValue . page &&
374
+ onSelect ( Array . from ( new Set ( [ ...selectedIds , ...pageDataIds ] ) ) ) ;
375
+ } ;
376
+
369
377
return (
370
378
< span className = { className } >
371
379
{ title && (
@@ -382,49 +390,59 @@ export function StandardPage<T>({
382
390
< PageSection variant = "light" >
383
391
< Toolbar clearAllFilters = { clearAllFilters } clearFiltersButtonText = { t ( 'Clear all filters' ) } >
384
392
< ToolbarContent >
385
- < ToolbarToggleGroup toggleIcon = { < FilterIcon /> } breakpoint = "xl" >
386
- { primaryFilters . length > 0 && (
387
- < FilterGroup
388
- fieldFilters = { primaryFilters }
389
- onFilterUpdate = { setSelectedFilters }
390
- selectedFilters = { selectedFilters }
391
- supportedFilterTypes = { supportedFilters }
392
- />
393
- ) }
394
- < AttributeValueFilter
395
- fieldFilters = { fields
396
- . filter ( ( { filter } ) => filter && ! filter . primary && ! filter . standalone )
397
- . map ( toFieldFilter ( flatData ) ) }
398
- onFilterUpdate = { setSelectedFilters }
399
- selectedFilters = { selectedFilters }
400
- supportedFilterTypes = { supportedFilters }
393
+ < Split hasGutter >
394
+ < BulkSelect
395
+ canSelectAll
396
+ selectedCount = { selectedIds . length }
397
+ pageCount = { pageDataIds . length }
398
+ totalCount = { filteredDataIds . length }
399
+ onSelect = { onBulkSelect }
400
+ { ...( pageDataIds . length && {
401
+ pageSelected : pageDataIds . every ( ( item ) => selectedIds . includes ( item ) ) ,
402
+ pagePartiallySelected :
403
+ pageDataIds . some ( ( item ) => selectedIds . includes ( item ) ) &&
404
+ ! pageDataIds . every ( ( item ) => selectedIds . includes ( item ) ) ,
405
+ } ) }
401
406
/>
402
- { ! ! fields . find ( ( field ) => field . filter ?. standalone ) && (
403
- < FilterGroup
407
+
408
+ < ToolbarToggleGroup toggleIcon = { < FilterIcon /> } breakpoint = "xl" >
409
+ { primaryFilters . length > 0 && (
410
+ < FilterGroup
411
+ fieldFilters = { primaryFilters }
412
+ onFilterUpdate = { setSelectedFilters }
413
+ selectedFilters = { selectedFilters }
414
+ supportedFilterTypes = { supportedFilters }
415
+ />
416
+ ) }
417
+ < AttributeValueFilter
404
418
fieldFilters = { fields
405
- . filter ( ( field ) => field . filter ? .standalone )
419
+ . filter ( ( { filter } ) => filter && ! filter . primary && ! filter . standalone )
406
420
. map ( toFieldFilter ( flatData ) ) }
407
421
onFilterUpdate = { setSelectedFilters }
408
422
selectedFilters = { selectedFilters }
409
423
supportedFilterTypes = { supportedFilters }
410
424
/>
411
- ) }
412
- < ManageColumnsToolbar
413
- resourceFields = { fields }
414
- defaultColumns = { fieldsMetadata }
415
- setColumns = { setFields }
416
- />
417
- { GlobalActionToolbarItems ?. length > 0 &&
418
- GlobalActionToolbarItems . map ( ( Action , index ) => (
419
- < Action key = { index } dataOnScreen = { showPagination ? pageData : filteredData } />
420
- ) ) }
421
- </ ToolbarToggleGroup >
422
-
423
- { selectedCountLabel && (
424
- < ToolbarItem className = "forklift-page__toolbar-item__selected-count" >
425
- { selectedCountLabel ( selectedIds . length ?? 0 ) }
426
- </ ToolbarItem >
427
- ) }
425
+ { ! ! fields . find ( ( field ) => field . filter ?. standalone ) && (
426
+ < FilterGroup
427
+ fieldFilters = { fields
428
+ . filter ( ( field ) => field . filter ?. standalone )
429
+ . map ( toFieldFilter ( flatData ) ) }
430
+ onFilterUpdate = { setSelectedFilters }
431
+ selectedFilters = { selectedFilters }
432
+ supportedFilterTypes = { supportedFilters }
433
+ />
434
+ ) }
435
+ < ManageColumnsToolbar
436
+ resourceFields = { fields }
437
+ defaultColumns = { fieldsMetadata }
438
+ setColumns = { setFields }
439
+ />
440
+ { GlobalActionToolbarItems ?. length > 0 &&
441
+ GlobalActionToolbarItems . map ( ( Action , index ) => (
442
+ < Action key = { index } dataOnScreen = { showPagination ? pageData : filteredData } />
443
+ ) ) }
444
+ </ ToolbarToggleGroup >
445
+ </ Split >
428
446
429
447
{ showPagination && (
430
448
< ToolbarItem variant = "pagination" >
0 commit comments