@@ -6,10 +6,16 @@ import {
66 Grid ,
77 TableHeaderRow ,
88 Table ,
9+ PagingPanel ,
910} from "@devexpress/dx-react-grid-material-ui" ;
10- import { SortingState , IntegratedSorting } from "@devexpress/dx-react-grid" ;
11+ import {
12+ SortingState ,
13+ IntegratedSorting ,
14+ PagingState ,
15+ IntegratedPaging ,
16+ } from "@devexpress/dx-react-grid" ;
1117import { IGridColumn } from "../Grid/GridColumns" ;
12- import React , { useState , useContext } from "react" ;
18+ import React , { useState , useContext , useMemo } from "react" ;
1319import { IStatsPageProps } from "./StatsInterfaces" ;
1420import { useGetBookStats } from "./useGetBookStats" ;
1521import { useProvideDataForExport } from "../../export/exportData" ;
@@ -22,21 +28,27 @@ export const BookStatsReport: React.FunctionComponent<IStatsPageProps> = (
2228 props
2329) => {
2430 const l10n = useIntl ( ) ;
25- const stats = useGetBookStats ( props ) ;
26- useProvideDataForExport ( stats , props ) ;
31+ const rawStats = useGetBookStats ( props ) ;
2732 const { languagesByBookCount : languages } = useContext ( CachedTablesContext ) ;
2833
29- if ( stats ) {
30- for ( const stat of stats ) {
34+ const stats = useMemo ( ( ) => {
35+ if ( ! rawStats ) return undefined ;
36+
37+ // Create a new array to avoid mutating the original
38+ return rawStats . map ( ( stat ) => {
3139 const languageDisplayName = getDisplayNamesFromLanguageCode (
3240 stat . language ,
3341 languages
3442 ) ?. combined ;
43+
3544 if ( languageDisplayName ) {
36- stat . languageName = languageDisplayName ;
45+ return { ... stat , languageName : languageDisplayName } ;
3746 }
38- }
39- }
47+ return stat ;
48+ } ) ;
49+ } , [ rawStats , languages ] ) ;
50+
51+ useProvideDataForExport ( stats , props ) ;
4052
4153 const columns : IGridColumn [ ] = [
4254 { name : "title" , title : "Book Title" , l10nId : "bookTitle" } ,
@@ -132,6 +144,11 @@ export const BookStatsReport: React.FunctionComponent<IStatsPageProps> = (
132144 { columnName : "startedCount" } ,
133145 ] ) ;
134146
147+ // Configure paging with 1000 records per page
148+ const [ currentPage , setCurrentPage ] = useState ( 0 ) ;
149+ const [ pageSize , setPageSize ] = useState ( 1000 ) ;
150+ const pageSizes = [ 100 , 500 , 1000 , 2000 ] ;
151+
135152 return (
136153 < StatsGridWrapper stats = { stats } >
137154 < Grid rows = { stats ! } columns = { columns } >
@@ -141,6 +158,13 @@ export const BookStatsReport: React.FunctionComponent<IStatsPageProps> = (
141158 < IntegratedSorting
142159 columnExtensions = { integratedSortingColumnExtensions }
143160 />
161+ < PagingState
162+ currentPage = { currentPage }
163+ onCurrentPageChange = { setCurrentPage }
164+ pageSize = { pageSize }
165+ onPageSizeChange = { setPageSize }
166+ />
167+ < IntegratedPaging />
144168 < Table
145169 columnExtensions = { tableColumnExtensions }
146170 //cellComponent={CustomTableCell}
@@ -149,6 +173,7 @@ export const BookStatsReport: React.FunctionComponent<IStatsPageProps> = (
149173 cellComponent = { CustomTableHeaderCell }
150174 showSortingControls
151175 />
176+ < PagingPanel pageSizes = { pageSizes } />
152177 </ Grid >
153178 </ StatsGridWrapper >
154179 ) ;
0 commit comments