From b4202d882f46cfead3c06bdea30d915468cea05d Mon Sep 17 00:00:00 2001 From: fnguyen Date: Thu, 14 Dec 2023 16:28:44 -0500 Subject: [PATCH] Fix pagination --- .../clinicalGenomic/search/SearchHandler.js | 5 +--- .../clinicalGenomic/widgets/clinicalData.js | 25 +++++++++++++++++++ .../clinicalGenomic/widgets/patientCounts.js | 11 ++++++-- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/views/clinicalGenomic/search/SearchHandler.js b/src/views/clinicalGenomic/search/SearchHandler.js index acb1a43c..5a9c0b31 100644 --- a/src/views/clinicalGenomic/search/SearchHandler.js +++ b/src/views/clinicalGenomic/search/SearchHandler.js @@ -76,9 +76,6 @@ function SearchHandler() { useEffect(() => { // First, we abort any currently-running search promises // controller.abort(); - console.log('Query re-initiated'); - console.log(reader.query); - const CollateSummary = (data, statName) => { const summaryStat = {}; data.forEach((site) => { @@ -146,7 +143,7 @@ function SearchHandler() { const clinicalData = {}; data.forEach((site) => { discoveryCounts.patients_per_cohort[site.location.name] = site.results?.summary?.patients_per_cohort; - clinicalData[site.location.name] = site?.results?.results; + clinicalData[site.location.name] = site?.results; }); const genomicData = data diff --git a/src/views/clinicalGenomic/widgets/clinicalData.js b/src/views/clinicalGenomic/widgets/clinicalData.js index 977d6152..7147c3a6 100644 --- a/src/views/clinicalGenomic/widgets/clinicalData.js +++ b/src/views/clinicalGenomic/widgets/clinicalData.js @@ -12,6 +12,10 @@ import { useSearchQueryWriterContext, useSearchResultsReaderContext } from '../S function ClinicalView() { const theme = useTheme(); + const [paginationModel, setPaginationModel] = React.useState({ + pageSize: 25, + page: 0 + }); // Mobile const [desktopResolution, setdesktopResolution] = React.useState(window.innerWidth > 1200); @@ -24,6 +28,7 @@ function ClinicalView() { if (searchResults) { rows = Object.values(searchResults) + ?.map((results) => results.results) ?.flat(1) ?.map((patient, index) => { // Make sure each row has an ID and a deceased status @@ -52,6 +57,22 @@ function ClinicalView() { { field: 'date_of_death', headerName: 'Date of Death', minWidth: 220, sortable: false } ]; + const HandlePageChange = (newPage) => { + if (newPage !== paginationModel.page) { + writerContext((old) => ({ ...old, query: { ...old.query, page: newPage } })); + } + setPaginationModel({ + pageSize: 10, + page: newPage + }); + }; + + const totalRows = searchResults + ? Object.values(searchResults) + ?.map((site) => site.count) + .reduce((partial, a) => partial + a, 0) + : 0; + return ( @@ -62,8 +83,12 @@ function ClinicalView() { rows={rows} columns={columns} pageSize={10} + rowCount={totalRows} rowsPerPageOptions={[10]} onRowClick={(rowData) => handleRowClick(rowData.row)} + paginationModel={paginationModel} + onPageChange={HandlePageChange} + paginationMode="server" hideFooterSelectedRowCount /> diff --git a/src/views/clinicalGenomic/widgets/patientCounts.js b/src/views/clinicalGenomic/widgets/patientCounts.js index 4af074a8..5b383387 100644 --- a/src/views/clinicalGenomic/widgets/patientCounts.js +++ b/src/views/clinicalGenomic/widgets/patientCounts.js @@ -33,7 +33,14 @@ function PatientCounts() { // Has this node been excluded from the results? if (!(filters && filters?.node?.includes(entry.location.name))) { const match = searchResults[entry.location.name]; - // Iterate through each donor in this site + Object.keys(match.summary.patients_per_cohort).forEach((cohort) => { + if (cohort in counts) { + counts[cohort] += match.summary.patients_per_cohort[cohort]; + } else { + counts[cohort] = match.summary.patients_per_cohort[cohort]; + } + }); + /* // Iterate through each donor in this site match.forEach((donor) => { if (filters && filters?.program_id?.includes(donor.program_id)) { // Exclude based on cohort @@ -45,7 +52,7 @@ function PatientCounts() { } else { counts[donor.program_id] = 1; } - }); + }); */ } }