Fix total count in show page (#6462)
Fixes #6405 We need to take into account both the totalCount of **before cursor** results and **after cursor** results.
This commit is contained in:
@ -60,7 +60,8 @@ export const useRecordShowPagePagination = (
|
|||||||
|
|
||||||
const cursorFromRequest = currentRecordsPageInfo?.endCursor;
|
const cursorFromRequest = currentRecordsPageInfo?.endCursor;
|
||||||
|
|
||||||
const [totalCount, setTotalCount] = useState<number>(0);
|
const [totalCountBefore, setTotalCountBefore] = useState<number>(0);
|
||||||
|
const [totalCountAfter, setTotalCountAfter] = useState<number>(0);
|
||||||
|
|
||||||
const { loading: loadingRecordBefore, records: recordsBefore } =
|
const { loading: loadingRecordBefore, records: recordsBefore } =
|
||||||
useFindManyRecords({
|
useFindManyRecords({
|
||||||
@ -78,7 +79,7 @@ export const useRecordShowPagePagination = (
|
|||||||
objectNameSingular,
|
objectNameSingular,
|
||||||
recordGqlFields,
|
recordGqlFields,
|
||||||
onCompleted: (_, pagination) => {
|
onCompleted: (_, pagination) => {
|
||||||
setTotalCount(pagination?.totalCount ?? 0);
|
setTotalCountBefore(pagination?.totalCount ?? 0);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ export const useRecordShowPagePagination = (
|
|||||||
objectNameSingular,
|
objectNameSingular,
|
||||||
recordGqlFields,
|
recordGqlFields,
|
||||||
onCompleted: (_, pagination) => {
|
onCompleted: (_, pagination) => {
|
||||||
setTotalCount(pagination?.totalCount ?? 0);
|
setTotalCountAfter(pagination?.totalCount ?? 0);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -147,6 +148,8 @@ export const useRecordShowPagePagination = (
|
|||||||
|
|
||||||
const objectLabel = capitalize(objectMetadataItem.namePlural);
|
const objectLabel = capitalize(objectMetadataItem.namePlural);
|
||||||
|
|
||||||
|
const totalCount = Math.max(1, totalCountBefore, totalCountAfter);
|
||||||
|
|
||||||
const viewNameWithCount = rankFoundInFiew
|
const viewNameWithCount = rankFoundInFiew
|
||||||
? `${rankInView + 1} of ${totalCount} in ${objectLabel}`
|
? `${rankInView + 1} of ${totalCount} in ${objectLabel}`
|
||||||
: `${objectLabel} (${totalCount})`;
|
: `${objectLabel} (${totalCount})`;
|
||||||
|
|||||||
Reference in New Issue
Block a user