Skip to content

Commit

Permalink
Fix record show page request errors (twentyhq#6345)
Browse files Browse the repository at this point in the history
- Removed getCursorFromRecordId
- Get cursor from request
- Fixed problem with navigation and optimistic rendering
  • Loading branch information
lucasbordeau authored Jul 19, 2024
1 parent 12c3315 commit 187b6f9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 46 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { buildShowPageURL } from '@/object-record/record-show/utils/buildShowPag
import { buildIndexTablePageURL } from '@/object-record/record-table/utils/buildIndexTableURL';
import { useQueryVariablesFromActiveFieldsOfViewOrDefaultView } from '@/views/hooks/useQueryVariablesFromActiveFieldsOfViewOrDefaultView';
import { isNonEmptyString } from '@sniptt/guards';
import { getRelayCursorFromRecordId } from '~/utils/getRelayCursorFromRecordId';
import { capitalize } from '~/utils/string/capitalize';

export const useRecordShowPagePagination = (
Expand Down Expand Up @@ -47,19 +46,32 @@ export const useRecordShowPagePagination = (
viewId: viewIdQueryParam,
});

const cursor = getRelayCursorFromRecordId(objectRecordId);
const { loading: loadingCursor, pageInfo: currentRecordsPageInfo } =
useFindManyRecords({
filter: {
id: { eq: objectRecordId },
},
orderBy,
limit: 1,
objectNameSingular,
recordGqlFields,
});

const cursorFromRequest = currentRecordsPageInfo?.endCursor;

const {
loading: loadingRecordBefore,
records: recordsBefore,
totalCount: totalCountBefore,
} = useFindManyRecords({
skip: loadingCursor,
fetchPolicy: 'network-only',
filter,
orderBy,
cursorFilter: isNonEmptyString(cursor)
cursorFilter: isNonEmptyString(cursorFromRequest)
? {
cursorDirection: 'before',
cursor: cursor,
cursor: cursorFromRequest,
limit: 1,
}
: undefined,
Expand All @@ -72,12 +84,14 @@ export const useRecordShowPagePagination = (
records: recordsAfter,
totalCount: totalCountAfter,
} = useFindManyRecords({
skip: loadingCursor,
filter,
fetchPolicy: 'network-only',
orderBy,
cursorFilter: cursor
cursorFilter: cursorFromRequest
? {
cursorDirection: 'after',
cursor: cursor,
cursor: cursorFromRequest,
limit: 1,
}
: undefined,
Expand All @@ -87,7 +101,7 @@ export const useRecordShowPagePagination = (

const totalCount = Math.max(totalCountBefore ?? 0, totalCountAfter ?? 0);

const loading = loadingRecordAfter || loadingRecordBefore;
const loading = loadingRecordAfter || loadingRecordBefore || loadingCursor;

const isThereARecordBefore = recordsBefore.length > 0;
const isThereARecordAfter = recordsAfter.length > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const getQueryVariablesFromView = ({
}) => {
if (!isDefined(view)) {
return {
filter: {},
orderBy: [],
filter: undefined,
orderBy: undefined,
};
}

Expand Down
3 changes: 0 additions & 3 deletions packages/twenty-front/src/utils/getRelayCursorFromRecordId.ts

This file was deleted.

0 comments on commit 187b6f9

Please sign in to comment.