Skip to content

Commit

Permalink
Fix total count in show page
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekj117 committed Jul 30, 2024
1 parent 3a37dfc commit ae8b44e
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export const useRecordShowPagePagination = (

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 } =
useFindManyRecords({
Expand All @@ -78,7 +79,7 @@ export const useRecordShowPagePagination = (
objectNameSingular,
recordGqlFields,
onCompleted: (_, pagination) => {
setTotalCount(pagination?.totalCount ?? 0);
setTotalCountBefore(pagination?.totalCount ?? 0);
},
});

Expand All @@ -98,7 +99,7 @@ export const useRecordShowPagePagination = (
objectNameSingular,
recordGqlFields,
onCompleted: (_, pagination) => {
setTotalCount(pagination?.totalCount ?? 0);
setTotalCountAfter(pagination?.totalCount ?? 0);
},
});

Expand Down Expand Up @@ -147,6 +148,19 @@ export const useRecordShowPagePagination = (

const objectLabel = capitalize(objectMetadataItem.namePlural);

let totalCount = 0;

if (totalCountBefore !== 0 && totalCountAfter !== 0) {
totalCount = Math.max(totalCountBefore, totalCountAfter);
} else {
totalCount =
totalCountBefore === 0
? totalCountAfter === 0
? 1
: totalCountAfter
: totalCountBefore;
}

const viewNameWithCount = rankFoundInFiew
? `${rankInView + 1} of ${totalCount} in ${objectLabel}`
: `${objectLabel} (${totalCount})`;
Expand Down

0 comments on commit ae8b44e

Please sign in to comment.