Simplify Code on FetchMore (#15465)

Simplifying a bit more fetchMore / lazyQuery api
This commit is contained in:
Charles Bochet
2025-10-30 13:36:30 +01:00
committed by GitHub
parent a82b74c1ff
commit eba3b0ca88
@@ -58,33 +58,6 @@ export const useLazyFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
const hasReadPermission = objectPermissions.canReadObjectRecords;
const handleFindManyRecordsCompleted = useRecoilCallback(
({ set, snapshot }) =>
(data: RecordGqlOperationFindManyResult) => {
const pageInfo = data?.[objectMetadataItem.namePlural]?.pageInfo;
const existingCursor = snapshot
.getLoadable(cursorFamilyState(queryIdentifier))
.getValue();
const existingHasNextPage = snapshot
.getLoadable(hasNextPageFamilyState(queryIdentifier))
.getValue();
if (isDefined(data?.[objectMetadataItem.namePlural])) {
if (existingCursor !== pageInfo.endCursor) {
set(cursorFamilyState(queryIdentifier), pageInfo.endCursor ?? '');
}
if (existingHasNextPage !== pageInfo.hasNextPage) {
set(
hasNextPageFamilyState(queryIdentifier),
pageInfo.hasNextPage ?? false,
);
}
}
},
[objectMetadataItem.namePlural, queryIdentifier],
);
const [findManyRecords, { data, error, fetchMore }] =
useLazyQuery<RecordGqlOperationFindManyResult>(findManyRecordsQuery, {
variables: {
@@ -128,10 +101,6 @@ export const useLazyFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
handleFindManyRecordsError(result.error);
}
if (isDefined(result?.data)) {
handleFindManyRecordsCompleted(result.data);
}
const hasNextPage =
result?.data?.[objectMetadataItem.namePlural]?.pageInfo.hasNextPage ??
false;
@@ -173,7 +142,6 @@ export const useLazyFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
objectMetadataItem.namePlural,
queryIdentifier,
handleFindManyRecordsError,
handleFindManyRecordsCompleted,
],
);