@@ -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
/**
@@ -285,8 +282,8 @@ export function StandardPage<T>({
285
282
toId,
286
283
expandedIds,
287
284
className,
288
- selectedIds,
289
- selectedCountLabel ,
285
+ selectedIds = [ ] ,
286
+ onSelect ,
290
287
} : StandardPageProps < T > ) {
291
288
const { t } = useForkliftTranslation ( ) ;
292
289
const [ sortedData , setSortedData ] = useState ( [ ] ) ;
@@ -341,6 +338,14 @@ export function StandardPage<T>({
341
338
const noResults = loaded && ! error && sortedData . length == 0 ;
342
339
const noMatchingResults = loaded && ! error && filteredData . length === 0 && sortedData . length > 0 ;
343
340
341
+ let pageDataIds = [ ] ;
342
+ let filteredDataIds = [ ] ;
343
+
344
+ if ( selectedIds . length && pageData ?. length && filteredData ?. length ) {
345
+ pageDataIds = pageData . map ( toId ) ;
346
+ filteredDataIds = filteredData . map ( toId ) ;
347
+ }
348
+
344
349
const primaryFilters = fields
345
350
. filter ( ( field ) => field . filter ?. primary )
346
351
. map ( toFieldFilter ( sortedData ) ) ;
@@ -366,6 +371,15 @@ export function StandardPage<T>({
366
371
setPage ( page ) ;
367
372
} ;
368
373
374
+ const onBulkSelect = ( value : BulkSelectValue ) => {
375
+ value === BulkSelectValue . none && onSelect ( [ ] ) ;
376
+ value === BulkSelectValue . all && onSelect ( filteredDataIds ) ;
377
+ value === BulkSelectValue . nonePage &&
378
+ onSelect ( selectedIds . filter ( ( item ) => ! pageDataIds . includes ( item ) ) ) ;
379
+ value === BulkSelectValue . page &&
380
+ onSelect ( Array . from ( new Set ( [ ...selectedIds , ...pageDataIds ] ) ) ) ;
381
+ } ;
382
+
369
383
return (
370
384
< span className = { className } >
371
385
{ title && (
@@ -382,49 +396,59 @@ export function StandardPage<T>({
382
396
< PageSection variant = "light" >
383
397
< Toolbar clearAllFilters = { clearAllFilters } clearFiltersButtonText = { t ( 'Clear all filters' ) } >
384
398
< 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 }
399
+ < Split hasGutter >
400
+ < BulkSelect
401
+ canSelectAll
402
+ selectedCount = { selectedIds . length }
403
+ pageCount = { pageDataIds . length }
404
+ totalCount = { filteredDataIds . length }
405
+ onSelect = { onBulkSelect }
406
+ { ...( pageDataIds . length && {
407
+ pageSelected : pageDataIds . every ( ( item ) => selectedIds . includes ( item ) ) ,
408
+ pagePartiallySelected :
409
+ pageDataIds . some ( ( item ) => selectedIds . includes ( item ) ) &&
410
+ ! pageDataIds . every ( ( item ) => selectedIds . includes ( item ) ) ,
411
+ } ) }
401
412
/>
402
- { ! ! fields . find ( ( field ) => field . filter ?. standalone ) && (
403
- < FilterGroup
413
+
414
+ < ToolbarToggleGroup toggleIcon = { < FilterIcon /> } breakpoint = "xl" >
415
+ { primaryFilters . length > 0 && (
416
+ < FilterGroup
417
+ fieldFilters = { primaryFilters }
418
+ onFilterUpdate = { setSelectedFilters }
419
+ selectedFilters = { selectedFilters }
420
+ supportedFilterTypes = { supportedFilters }
421
+ />
422
+ ) }
423
+ < AttributeValueFilter
404
424
fieldFilters = { fields
405
- . filter ( ( field ) => field . filter ? .standalone )
425
+ . filter ( ( { filter } ) => filter && ! filter . primary && ! filter . standalone )
406
426
. map ( toFieldFilter ( flatData ) ) }
407
427
onFilterUpdate = { setSelectedFilters }
408
428
selectedFilters = { selectedFilters }
409
429
supportedFilterTypes = { supportedFilters }
410
430
/>
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
- ) }
431
+ { ! ! fields . find ( ( field ) => field . filter ?. standalone ) && (
432
+ < FilterGroup
433
+ fieldFilters = { fields
434
+ . filter ( ( field ) => field . filter ?. standalone )
435
+ . map ( toFieldFilter ( flatData ) ) }
436
+ onFilterUpdate = { setSelectedFilters }
437
+ selectedFilters = { selectedFilters }
438
+ supportedFilterTypes = { supportedFilters }
439
+ />
440
+ ) }
441
+ < ManageColumnsToolbar
442
+ resourceFields = { fields }
443
+ defaultColumns = { fieldsMetadata }
444
+ setColumns = { setFields }
445
+ />
446
+ { GlobalActionToolbarItems ?. length > 0 &&
447
+ GlobalActionToolbarItems . map ( ( Action , index ) => (
448
+ < Action key = { index } dataOnScreen = { showPagination ? pageData : filteredData } />
449
+ ) ) }
450
+ </ ToolbarToggleGroup >
451
+ </ Split >
428
452
429
453
{ showPagination && (
430
454
< ToolbarItem variant = "pagination" >
0 commit comments