diff --git a/src/atoms/tableScope/table.ts b/src/atoms/tableScope/table.ts index dd87eea2..fdf8820c 100644 --- a/src/atoms/tableScope/table.ts +++ b/src/atoms/tableScope/table.ts @@ -239,5 +239,8 @@ export type AuditChangeFunction = ( */ export const auditChangeAtom = atom(undefined); -/** Store total number of rows in firestore collection */ -export const serverDocCountAtom = atom(0); +/** + * Store total number of rows in the table, respecting current filters. + * If `undefined`, the query hasn’t loaded yet. + */ +export const serverDocCountAtom = atom(undefined); diff --git a/src/components/TableToolbar/LoadedRowsStatus.tsx b/src/components/TableToolbar/LoadedRowsStatus.tsx index e1ad6dcb..6a1465fa 100644 --- a/src/components/TableToolbar/LoadedRowsStatus.tsx +++ b/src/components/TableToolbar/LoadedRowsStatus.tsx @@ -69,8 +69,9 @@ function LoadedRowsStatus() { Loaded {!tableNextPage.available && "all "} - {tableRows.length} {tableNextPage.available && `of ${serverDocCount}`}{" "} - row{serverDocCount !== 1 && "s"} + {tableRows.length} + {serverDocCount !== undefined && ` of ${serverDocCount}`} row + {(serverDocCount ?? tableRows.length) !== 1 && "s"} ); diff --git a/src/hooks/useFirestoreCollectionWithAtom.ts b/src/hooks/useFirestoreCollectionWithAtom.ts index 14d1ffc4..fb4ec621 100644 --- a/src/hooks/useFirestoreCollectionWithAtom.ts +++ b/src/hooks/useFirestoreCollectionWithAtom.ts @@ -64,7 +64,7 @@ interface IUseFirestoreCollectionWithAtomOptions { /** Update this atom when we’re loading the next page, and if there is a next page available. Uses same scope as `dataScope`. */ nextPageAtom?: PrimitiveAtom; /** Set this atom's value to the number of docs in the collection on each new snapshot */ - serverDocCountAtom?: PrimitiveAtom | undefined; + serverDocCountAtom?: PrimitiveAtom; } /** @@ -235,6 +235,7 @@ export function useFirestoreCollectionWithAtom( handleError, nextPageAtom, setNextPageAtom, + serverDocCountAtom, setServerDocCountAtom, ]);