From 8a1ed82c138b38d7a21aee3d9f7b7cd34a1c7b1e Mon Sep 17 00:00:00 2001 From: Matteo Guarnaccia Date: Thu, 28 Mar 2024 16:01:10 +0000 Subject: [PATCH 01/28] implemented logic to show total row count on tables #441 --- .../items/catalogueItemsTable.component.tsx | 21 +++++++++++++++++++ src/items/itemsTable.component.tsx | 21 +++++++++++++++++++ src/manufacturer/manufacturer.component.tsx | 20 ++++++++++++++++++ src/systems/systemItemsTable.component.tsx | 21 +++++++++++++++++++ 4 files changed, 83 insertions(+) diff --git a/src/catalogue/items/catalogueItemsTable.component.tsx b/src/catalogue/items/catalogueItemsTable.component.tsx index 4b8efbf84..e9789b3d5 100644 --- a/src/catalogue/items/catalogueItemsTable.component.tsx +++ b/src/catalogue/items/catalogueItemsTable.component.tsx @@ -772,6 +772,27 @@ const CatalogueItemsTable = (props: CatalogueItemsTableProps) => { ); }, + renderBottomToolbarCustomActions: ({ table }) => ( + + {`Showing rows ${ + Math.min( + table.getState().pagination.pageIndex * + table.getState().pagination.pageSize + + table.getState().pagination.pageSize, + table.getRowCount() + ) === 0 + ? 0 + : ( + table.getState().pagination.pageIndex * + table.getState().pagination.pageSize + + 1 + ).toLocaleString() + } + - ${Math.min(table.getState().pagination.pageIndex * table.getState().pagination.pageSize + table.getState().pagination.pageSize, table.getRowCount()).toLocaleString()} + of ${table.getRowCount()}`} + + ), + renderTopToolbarCustomActions: ({ table }) => dense && requestOrigin === 'move to' ? undefined : ( diff --git a/src/items/itemsTable.component.tsx b/src/items/itemsTable.component.tsx index 980cbf107..dd54ba8dc 100644 --- a/src/items/itemsTable.component.tsx +++ b/src/items/itemsTable.component.tsx @@ -457,6 +457,27 @@ export function ItemsTable(props: ItemTableProps) { , ]; }, + renderBottomToolbarCustomActions: ({ table }) => ( + + {`Showing rows ${ + Math.min( + table.getState().pagination.pageIndex * + table.getState().pagination.pageSize + + table.getState().pagination.pageSize, + table.getRowCount() + ) === 0 + ? 0 + : ( + table.getState().pagination.pageIndex * + table.getState().pagination.pageSize + + 1 + ).toLocaleString() + } + - ${Math.min(table.getState().pagination.pageIndex * table.getState().pagination.pageSize + table.getState().pagination.pageSize, table.getRowCount()).toLocaleString()} + of ${table.getRowCount()}`} + + ), + renderDetailPanel: dense ? ({ row }) => ( , ]; }, + renderBottomToolbarCustomActions: ({ table }) => ( + + {`Showing rows ${ + Math.min( + table.getState().pagination.pageIndex * + table.getState().pagination.pageSize + + table.getState().pagination.pageSize, + table.getRowCount() + ) === 0 + ? 0 + : ( + table.getState().pagination.pageIndex * + table.getState().pagination.pageSize + + 1 + ).toLocaleString() + } + - ${Math.min(table.getState().pagination.pageIndex * table.getState().pagination.pageSize + table.getState().pagination.pageSize, table.getRowCount()).toLocaleString()} + of ${table.getRowCount()}`} + + ), }); const navigate = useNavigate(); diff --git a/src/systems/systemItemsTable.component.tsx b/src/systems/systemItemsTable.component.tsx index 15d778cb1..31a62adc1 100644 --- a/src/systems/systemItemsTable.component.tsx +++ b/src/systems/systemItemsTable.component.tsx @@ -328,6 +328,27 @@ export function SystemItemsTable(props: SystemItemsTableProps) { /> ), + renderBottomToolbarCustomActions: ({ table }) => ( + + {`Showing rows ${ + Math.min( + table.getState().pagination.pageIndex * + table.getState().pagination.pageSize + + table.getState().pagination.pageSize, + table.getRowCount() + ) === 0 + ? 0 + : ( + table.getState().pagination.pageIndex * + table.getState().pagination.pageSize + + 1 + ).toLocaleString() + } + - ${Math.min(table.getState().pagination.pageIndex * table.getState().pagination.pageSize + table.getState().pagination.pageSize, table.getRowCount()).toLocaleString()} + of ${table.getRowCount()}`} + + ), + renderDetailPanel: ({ row }) => row.original.catalogueItem !== undefined ? ( Date: Tue, 2 Apr 2024 09:35:24 +0100 Subject: [PATCH 02/28] abstracted logic for total row counts #441 --- .../items/catalogueItemsTable.component.tsx | 22 +++++---------- src/items/itemsTable.component.tsx | 27 +++++++------------ src/manufacturer/manufacturer.component.tsx | 27 +++++++------------ src/systems/systemItemsTable.component.tsx | 23 +++++----------- src/utils.tsx | 16 +++++++++++ 5 files changed, 48 insertions(+), 67 deletions(-) diff --git a/src/catalogue/items/catalogueItemsTable.component.tsx b/src/catalogue/items/catalogueItemsTable.component.tsx index e9789b3d5..c7bda276b 100644 --- a/src/catalogue/items/catalogueItemsTable.component.tsx +++ b/src/catalogue/items/catalogueItemsTable.component.tsx @@ -41,6 +41,7 @@ import { formatDateTimeStrings, generateUniqueName, getPageHeightCalc, + showTotalRowCounts, } from '../../utils'; import CatalogueItemsDetailsPanel from './catalogueItemsDetailsPanel.component'; import CatalogueItemDirectoryDialog from './catalogueItemDirectoryDialog.component'; @@ -774,22 +775,11 @@ const CatalogueItemsTable = (props: CatalogueItemsTableProps) => { }, renderBottomToolbarCustomActions: ({ table }) => ( - {`Showing rows ${ - Math.min( - table.getState().pagination.pageIndex * - table.getState().pagination.pageSize + - table.getState().pagination.pageSize, - table.getRowCount() - ) === 0 - ? 0 - : ( - table.getState().pagination.pageIndex * - table.getState().pagination.pageSize + - 1 - ).toLocaleString() - } - - ${Math.min(table.getState().pagination.pageIndex * table.getState().pagination.pageSize + table.getState().pagination.pageSize, table.getRowCount()).toLocaleString()} - of ${table.getRowCount()}`} + {showTotalRowCounts( + table.getState().pagination.pageIndex, + table.getState().pagination.pageSize, + table.getRowCount() + )} ), diff --git a/src/items/itemsTable.component.tsx b/src/items/itemsTable.component.tsx index dd54ba8dc..4bb4589e4 100644 --- a/src/items/itemsTable.component.tsx +++ b/src/items/itemsTable.component.tsx @@ -37,7 +37,11 @@ import { import { MRT_Localization_EN } from 'material-react-table/locales/en'; import { useItems } from '../api/items'; import ItemsDetailsPanel from './itemsDetailsPanel.component'; -import { formatDateTimeStrings, getPageHeightCalc } from '../utils'; +import { + formatDateTimeStrings, + getPageHeightCalc, + showTotalRowCounts, +} from '../utils'; import DeleteItemDialog from './deleteItemDialog.component'; export interface ItemTableProps { @@ -459,22 +463,11 @@ export function ItemsTable(props: ItemTableProps) { }, renderBottomToolbarCustomActions: ({ table }) => ( - {`Showing rows ${ - Math.min( - table.getState().pagination.pageIndex * - table.getState().pagination.pageSize + - table.getState().pagination.pageSize, - table.getRowCount() - ) === 0 - ? 0 - : ( - table.getState().pagination.pageIndex * - table.getState().pagination.pageSize + - 1 - ).toLocaleString() - } - - ${Math.min(table.getState().pagination.pageIndex * table.getState().pagination.pageSize + table.getState().pagination.pageSize, table.getRowCount()).toLocaleString()} - of ${table.getRowCount()}`} + {showTotalRowCounts( + table.getState().pagination.pageIndex, + table.getState().pagination.pageSize, + table.getRowCount() + )} ), diff --git a/src/manufacturer/manufacturer.component.tsx b/src/manufacturer/manufacturer.component.tsx index 898c29735..fa763cff7 100644 --- a/src/manufacturer/manufacturer.component.tsx +++ b/src/manufacturer/manufacturer.component.tsx @@ -26,7 +26,11 @@ import { Manufacturer } from '../app.types'; import DeleteManufacturerDialog from './deleteManufacturerDialog.component'; import ManufacturerDialog from './manufacturerDialog.component'; import Breadcrumbs from '../view/breadcrumbs.component'; -import { formatDateTimeStrings, getPageHeightCalc } from '../utils'; +import { + formatDateTimeStrings, + getPageHeightCalc, + showTotalRowCounts, +} from '../utils'; function ManufacturerComponent() { const { data: ManufacturerData, isLoading: ManufacturerDataLoading } = @@ -270,22 +274,11 @@ function ManufacturerComponent() { }, renderBottomToolbarCustomActions: ({ table }) => ( - {`Showing rows ${ - Math.min( - table.getState().pagination.pageIndex * - table.getState().pagination.pageSize + - table.getState().pagination.pageSize, - table.getRowCount() - ) === 0 - ? 0 - : ( - table.getState().pagination.pageIndex * - table.getState().pagination.pageSize + - 1 - ).toLocaleString() - } - - ${Math.min(table.getState().pagination.pageIndex * table.getState().pagination.pageSize + table.getState().pagination.pageSize, table.getRowCount()).toLocaleString()} - of ${table.getRowCount()}`} + {showTotalRowCounts( + table.getState().pagination.pageIndex, + table.getState().pagination.pageSize, + table.getRowCount() + )} ), }); diff --git a/src/systems/systemItemsTable.component.tsx b/src/systems/systemItemsTable.component.tsx index 31a62adc1..7f1da2ca7 100644 --- a/src/systems/systemItemsTable.component.tsx +++ b/src/systems/systemItemsTable.component.tsx @@ -16,7 +16,7 @@ import { useItems } from '../api/items'; import { CatalogueItem, Item, System, UsageStatusType } from '../app.types'; import ItemsDetailsPanel from '../items/itemsDetailsPanel.component'; import SystemItemsDialog from './systemItemsDialog.component'; -import { formatDateTimeStrings } from '../utils'; +import { formatDateTimeStrings, showTotalRowCounts } from '../utils'; const MoveItemsButton = (props: { selectedItems: Item[]; @@ -330,22 +330,11 @@ export function SystemItemsTable(props: SystemItemsTableProps) { ), renderBottomToolbarCustomActions: ({ table }) => ( - {`Showing rows ${ - Math.min( - table.getState().pagination.pageIndex * - table.getState().pagination.pageSize + - table.getState().pagination.pageSize, - table.getRowCount() - ) === 0 - ? 0 - : ( - table.getState().pagination.pageIndex * - table.getState().pagination.pageSize + - 1 - ).toLocaleString() - } - - ${Math.min(table.getState().pagination.pageIndex * table.getState().pagination.pageSize + table.getState().pagination.pageSize, table.getRowCount()).toLocaleString()} - of ${table.getRowCount()}`} + {showTotalRowCounts( + table.getState().pagination.pageIndex, + table.getState().pagination.pageSize, + table.getRowCount() + )} ), diff --git a/src/utils.tsx b/src/utils.tsx index 87f77b826..a7a2a453d 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -87,3 +87,19 @@ export const formatDateTimeStrings = ( return formattedDate; }; + +/* returns a string with the total rows and current rows for table views */ +export const showTotalRowCounts = ( + pageIndex: number, + pageSize: number, + totalRowCount: number +): string => { + const firstRowIndex = pageIndex * pageSize; + const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount); + + return `Showing rows ${ + lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString() + } + - ${lastRowIndex.toLocaleString()} + of ${totalRowCount}`; +}; From 068743b83622f94d3819cbaa168e7fd9fb3d9249 Mon Sep 17 00:00:00 2001 From: Matteo Guarnaccia Date: Tue, 2 Apr 2024 09:41:50 +0100 Subject: [PATCH 03/28] updated snapshots #441 --- ...atalogueItemsTable.component.test.tsx.snap | 12 +++-- .../itemsTable.component.test.tsx.snap | 52 +++++++++++++------ .../manufacturer.component.test.tsx.snap | 31 ++++++++--- .../systemItemsTable.component.test.tsx.snap | 24 +++++---- 4 files changed, 82 insertions(+), 37 deletions(-) diff --git a/src/catalogue/items/__snapshots__/catalogueItemsTable.component.test.tsx.snap b/src/catalogue/items/__snapshots__/catalogueItemsTable.component.test.tsx.snap index f7a4ce62a..ebf07a42d 100644 --- a/src/catalogue/items/__snapshots__/catalogueItemsTable.component.test.tsx.snap +++ b/src/catalogue/items/__snapshots__/catalogueItemsTable.component.test.tsx.snap @@ -840,7 +840,7 @@ exports[`Catalogue Items Table > renders the dense table correctly 1`] = ` class="MuiCollapse-wrapperInner MuiCollapse-vertical css-9l5vo-MuiCollapse-wrapperInner" >