@@ -6,71 +6,50 @@ import { createPropertyFilterPredicate } from './property-filter.js';
66import { createComparator } from './sort.js' ;
77import { createPageProps } from './pagination.js' ;
88import { composeFilters } from './compose-filters.js' ;
9- import { getTrackableValue , SelectionTree } from '@cloudscape-design/component-toolkit/internal ' ;
9+ import { getTrackableValue } from './trackby-utils.js ' ;
1010import { computeFlatItems , computeTreeItems } from './items-tree.js' ;
1111
1212export function processItems < T > (
1313 allItems : ReadonlyArray < T > ,
14- state : Partial < CollectionState < T > > ,
15- { filtering, sorting, pagination, propertyFiltering, expandableRows, selection } : UseCollectionOptions < T >
14+ { filteringText , sortingState , currentPageIndex , propertyFilteringQuery } : Partial < CollectionState < T > > ,
15+ { filtering, sorting, pagination, propertyFiltering, expandableRows } : UseCollectionOptions < T >
1616) : {
1717 items : readonly T [ ] ;
1818 allPageItems : readonly T [ ] ;
1919 pagesCount : number | undefined ;
2020 actualPageIndex : number | undefined ;
21- totalItemsCount : number ;
2221 filteredItemsCount : number | undefined ;
23- selectedItems : undefined | T [ ] ;
24- getItemsCount ?: ( item : T ) => number ;
25- getSelectedItemsCount ?: ( item : T ) => number ;
2622 getChildren : ( item : T ) => T [ ] ;
2723} {
2824 const filterPredicate = composeFilters (
29- createPropertyFilterPredicate ( propertyFiltering , state . propertyFilteringQuery ) ,
30- createFilterPredicate ( filtering , state . filteringText )
25+ createPropertyFilterPredicate ( propertyFiltering , propertyFilteringQuery ) ,
26+ createFilterPredicate ( filtering , filteringText )
3127 ) ;
32- const sortingComparator = createComparator ( sorting , state . sortingState ) ;
33- const { items, totalItemsCount , getChildren, getItemsCount } = expandableRows
28+ const sortingComparator = createComparator ( sorting , sortingState ) ;
29+ const { items, size , getChildren } = expandableRows
3430 ? computeTreeItems ( allItems , expandableRows , filterPredicate , sortingComparator )
3531 : computeFlatItems ( allItems , filterPredicate , sortingComparator ) ;
36- const filteredItemsCount = filterPredicate ? totalItemsCount : undefined ;
3732
38- let getSelectedItemsCount : undefined | ( ( item : T ) => number ) = undefined ;
39- let selectedItems : undefined | T [ ] = undefined ;
40- if ( selection && expandableRows ?. dataGrouping && state . groupSelection ) {
41- const trackBy = selection ?. trackBy ?? expandableRows ?. getId ;
42- const selectionTreeProps = { getChildren : getChildren , trackBy } ;
43- const selectionTree = new SelectionTree ( items , selectionTreeProps , state . groupSelection ) ;
44- getSelectedItemsCount = selectionTree . getSelectedItemsCount ;
45- selectedItems = selectionTree . getSelectedItems ( ) ;
46- }
33+ const filteredItemsCount = filterPredicate ? size : undefined ;
4734
48- const pageProps = createPageProps ( pagination , state . currentPageIndex , items ) ;
35+ const pageProps = createPageProps ( pagination , currentPageIndex , items ) ;
4936 if ( pageProps ) {
5037 return {
5138 items : items . slice ( ( pageProps . pageIndex - 1 ) * pageProps . pageSize , pageProps . pageIndex * pageProps . pageSize ) ,
5239 allPageItems : items ,
53- totalItemsCount,
5440 filteredItemsCount,
5541 pagesCount : pageProps ?. pagesCount ,
5642 actualPageIndex : pageProps ?. pageIndex ,
57- selectedItems,
58- getItemsCount,
59- getSelectedItemsCount,
6043 getChildren,
6144 } ;
6245 }
6346
6447 return {
6548 items : items ,
6649 allPageItems : items ,
67- totalItemsCount,
6850 filteredItemsCount,
6951 pagesCount : undefined ,
7052 actualPageIndex : undefined ,
71- selectedItems,
72- getItemsCount,
73- getSelectedItemsCount,
7453 getChildren,
7554 } ;
7655}
0 commit comments