The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix record show page request errors (#6345)
Lucas Bordeau187b6f9335b2
diff --git a/packages/twenty-front/src/modules/object-record/record-show/hooks/useFindRecordCursorFromFindManyCacheRootQuery.ts b/packages/twenty-front/src/modules/object-record/record-show/hooks/useFindRecordCursorFromFindManyCacheRootQuery.tsdeleted file mode 100644index 878309217a1..00000000000--- a/packages/twenty-front/src/modules/object-record/record-show/hooks/useFindRecordCursorFromFindManyCacheRootQuery.ts+++ /dev/null@@ -1,34 +0,0 @@-import { RecordGqlRefEdge } from '@/object-record/cache/types/RecordGqlRefEdge';-import { useApolloClient } from '@apollo/client';-import { createApolloStoreFieldName } from '~/utils/createApolloStoreFieldName';--export const useFindRecordCursorFromFindManyCacheRootQuery = ({- objectNamePlural,- fieldVariables,-}: {- objectNamePlural: string;- fieldVariables: {- filter: any;- orderBy: any;- };-}) => {- const apollo = useApolloClient();-- const testsFieldNameOnRootQuery = createApolloStoreFieldName({- fieldName: objectNamePlural,- fieldVariables: fieldVariables,- });-- const findCursorInCache = (recordId: string) => {- const extractedCache = apollo.cache.extract() as any;-- const edgesInCache =- extractedCache?.['ROOT_QUERY']?.[testsFieldNameOnRootQuery]?.edges ?? [];-- return edgesInCache.find(- (edge: RecordGqlRefEdge) => edge.node?.__ref.split(':')[1] === recordId,- )?.cursor;- };-- return { findCursorInCache };-};diff --git a/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.ts b/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.tsindex d22878e7d16..3dbe0e2976d 100644--- a/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.ts+++ b/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.ts@@ -11,7 +11,6 @@ import { buildShowPageURL } from '@/object-record/record-show/utils/buildShowPagimport { 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 = (@@ -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,@@ -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,@@ -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;diff --git a/packages/twenty-front/src/modules/views/utils/getQueryVariablesFromView.ts b/packages/twenty-front/src/modules/views/utils/getQueryVariablesFromView.tsindex f946d83892f..7120068f842 100644--- a/packages/twenty-front/src/modules/views/utils/getQueryVariablesFromView.ts+++ b/packages/twenty-front/src/modules/views/utils/getQueryVariablesFromView.ts@@ -20,8 +20,8 @@ export const getQueryVariablesFromView = ({}) => {if (!isDefined(view)) {return {- filter: {},- orderBy: [],+ filter: undefined,+ orderBy: undefined,};}diff --git a/packages/twenty-front/src/utils/getRelayCursorFromRecordId.ts b/packages/twenty-front/src/utils/getRelayCursorFromRecordId.tsdeleted file mode 100644index 60fa31c080b..00000000000--- a/packages/twenty-front/src/utils/getRelayCursorFromRecordId.ts+++ /dev/null@@ -1,3 +0,0 @@-export const getRelayCursorFromRecordId = (recordId: string) => {- return btoa(`[1, "${recordId}"]`);-};