@@ -19,6 +19,7 @@ import { IStatsProps } from "./StatsInterfaces";
1919import { useGetBookComprehensionEventStats } from "./useGetBookStats" ;
2020import { useProvideDataForExport } from "../../export/exportData" ;
2121import { useIntl } from "react-intl" ;
22+ import { StatsGridWrapper } from "./StatsGridWrapper" ;
2223
2324export const ComprehensionQuestionsReport : React . FunctionComponent < IStatsProps > = (
2425 props
@@ -63,10 +64,10 @@ export const ComprehensionQuestionsReport: React.FunctionComponent<IStatsProps>
6364
6465 // Configure numeric sorts for the last two columns (so 453 is not less than 5)
6566 const [ integratedSortingColumnExtensions ] = useState ( [
66- { columnName : "questions" , compare : compareNumbers } ,
67- { columnName : "quizzesTaken" , compare : compareNumbers } ,
68- { columnName : "meanCorrect" , compare : compareNumbers } ,
69- { columnName : "medianCorrect" , compare : compareNumbers } ,
67+ { columnName : "questions" } ,
68+ { columnName : "quizzesTaken" } ,
69+ { columnName : "meanCorrect" } ,
70+ { columnName : "medianCorrect" } ,
7071 ] ) ;
7172
7273 const CustomTableHeaderCell = ( cellProps : any ) => {
@@ -121,81 +122,38 @@ export const ComprehensionQuestionsReport: React.FunctionComponent<IStatsProps>
121122 }
122123 } ;
123124
124- const gotRows = stats && stats . length > 0 ;
125-
126125 // const [headerColumnExtensions] = useState([
127126 // { columnName: "quizzesTaken", wordWrapEnabled: true },
128127 // { columnName: "meanCorrect", wordWrapEnabled: true },
129128 // { columnName: "medianCorrect", wordWrapEnabled: true },
130129 // ]);
131130 return (
132- < div
133- css = { css `
134- background-color : ${ gotRows && "white" } ;
135- thead .MuiTableHead-root * {
136- line-height : 15px ;
137- vertical-align : top;
138- }
139- // make the table line up with the rest of the page
140- // (but don't interfere with the space between columns)
141- th : first-child ,
142- td : first-child {
143- padding-left : 0 !important ;
144- }
145- ` }
146- >
147- { gotRows || < div > No data found</ div > }
148- { gotRows && (
149- < Grid rows = { stats ! } columns = { columns } >
150- < SortingState
151- defaultSorting = { [
152- { columnName : "quizzesTaken" , direction : "desc" } ,
153- ] }
154- />
155- < IntegratedSorting
156- columnExtensions = { integratedSortingColumnExtensions }
157- />
158- < Table
159- columnExtensions = { tableColumnExtensions }
160- cellComponent = { CustomTableCell }
161- />
162- < TableColumnResizing
163- resizingMode = { "nextColumn" }
164- defaultColumnWidths = { columns . map ( ( c ) => ( {
165- columnName : c . name ,
166- width : "auto" ,
167- } ) ) }
168- />
169- < TableHeaderRow
170- cellComponent = { CustomTableHeaderCell }
171- showSortingControls
172- />
173- </ Grid >
174- ) }
175- </ div >
131+ < StatsGridWrapper stats = { stats } >
132+ < Grid rows = { stats ! } columns = { columns } >
133+ < SortingState
134+ defaultSorting = { [
135+ { columnName : "quizzesTaken" , direction : "desc" } ,
136+ ] }
137+ />
138+ < IntegratedSorting
139+ columnExtensions = { integratedSortingColumnExtensions }
140+ />
141+ < Table
142+ columnExtensions = { tableColumnExtensions }
143+ cellComponent = { CustomTableCell }
144+ />
145+ < TableColumnResizing
146+ resizingMode = { "nextColumn" }
147+ defaultColumnWidths = { columns . map ( ( c ) => ( {
148+ columnName : c . name ,
149+ width : "auto" ,
150+ } ) ) }
151+ />
152+ < TableHeaderRow
153+ cellComponent = { CustomTableHeaderCell }
154+ showSortingControls
155+ />
156+ </ Grid >
157+ </ StatsGridWrapper >
176158 ) ;
177159} ;
178-
179- const compareNumbers = (
180- a : string | undefined | null ,
181- b : string | undefined | null
182- ) : number => {
183- // First check for falsy strings. These are problematic.
184- // If you don't handle them, the list will become sorted in arbitrary order.
185- // We'll just define nulls as being worse than 0... so... negative infinity.
186- let numA = a ? parseFloat ( a ) : Number . NEGATIVE_INFINITY ;
187- if ( isNaN ( numA ) ) {
188- // Parse errors are also problematic.
189- numA = Number . NEGATIVE_INFINITY ;
190- }
191-
192- let numB = b ? parseFloat ( b ) : Number . NEGATIVE_INFINITY ;
193- if ( isNaN ( numB ) ) {
194- numB = Number . NEGATIVE_INFINITY ;
195- }
196-
197- if ( numA === numB ) {
198- return 0 ;
199- }
200- return numA < numB ? - 1 : 1 ;
201- } ;
0 commit comments