Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3757 update frontend to show correct view count #3967

Merged
merged 6 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ export const triggerCreateRecordsOptimisticEffect = ({
'edges',
rootQueryCachedObjectRecordConnection,
);

const rootQueryCachedRecordTotalCount =
readField<number>(
'totalCount',
rootQueryCachedObjectRecordConnection,
) || 0;

const nextRootQueryCachedRecordEdges = rootQueryCachedRecordEdges
? [...rootQueryCachedRecordEdges]
: [];
Expand Down Expand Up @@ -109,6 +116,7 @@ export const triggerCreateRecordsOptimisticEffect = ({
return {
...rootQueryCachedObjectRecordConnection,
edges: nextRootQueryCachedRecordEdges,
totalCount: rootQueryCachedRecordTotalCount + 1,
};
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export const triggerDeleteRecordsOptimisticEffect = ({
rootQueryCachedObjectRecordConnection,
);

const totalCount =
readField<number>(
'totalCount',
rootQueryCachedObjectRecordConnection,
) || 0;

const nextCachedEdges =
cachedEdges?.filter((cachedEdge) => {
const nodeId = readField<string>('id', cachedEdge.node);
Expand All @@ -71,6 +77,7 @@ export const triggerDeleteRecordsOptimisticEffect = ({
return {
...rootQueryCachedObjectRecordConnection,
edges: nextCachedEdges,
totalCount: totalCount - recordIdsToDelete.length,
};
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const emptyConnectionMock: ObjectRecordConnection = {
startCursor: '',
endCursor: '',
},
totalCount: 0,
__typename: 'ObjectRecordConnection',
};

Expand Down Expand Up @@ -46,6 +47,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand Down Expand Up @@ -86,6 +88,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
startCursor:
'WyJjODVhODY3Yy01YThmLTQ4NjEtOGVkMi05NmMzOTAyNDg0MjMiXQ==',
},
totalCount: 1,
},
},
},
Expand All @@ -106,6 +109,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -126,6 +130,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -146,6 +151,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -166,6 +172,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -186,6 +193,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -198,6 +206,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
startCursor:
'WyIyNDBkYTJlYy0yZDQwLTRlNDktOGRmNC05YzZhMDQ5MTkwZGYiXQ==',
},
totalCount: 6,
},
},
},
Expand Down Expand Up @@ -225,6 +234,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -245,6 +255,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -257,6 +268,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
startCursor:
'WyI5M2M3MmQyZS1mNTE3LTQyZmQtODBhZS0xNDE3M2IzYjcwYWUiXQ==',
},
totalCount: 2,
},
},
},
Expand All @@ -273,6 +285,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand Down Expand Up @@ -300,6 +313,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -320,6 +334,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -340,6 +355,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -352,6 +368,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
startCursor:
'WyIxZDE1MTg1Mi00OTBmLTQ0NjYtODM5MS03MzNjZmQ2NmEwYzgiXQ==',
},
totalCount: 3,
},
},
},
Expand All @@ -368,6 +385,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -384,6 +402,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -400,6 +419,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand Down Expand Up @@ -427,6 +447,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -439,6 +460,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
startCursor:
'WyIyNDBkYTJlYy0yZDQwLTRlNDktOGRmNC05YzZhMDQ5MTkxZGYiXQ==',
},
totalCount: 1,
},
},
},
Expand Down Expand Up @@ -466,6 +488,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -478,6 +501,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
startCursor:
'WyIyNDBkYTJlYy0yZDQwLTRlNDktOGRmNC05YzZhMDQ5MTkxZGUiXQ==',
},
totalCount: 1,
},
},
},
Expand All @@ -494,6 +518,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -510,6 +535,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand Down Expand Up @@ -550,6 +576,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
startCursor:
'WyIzN2I5NzE0MC0yNmI5LTQ5OGMtODM3Yi00ZjNkZTQ5OWFkODMiXQ==',
},
totalCount: 1,
},
},
},
Expand All @@ -570,6 +597,7 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
hasPreviousPage: false,
startCursor: null,
},
totalCount: 0,
},
},
},
Expand All @@ -582,10 +610,12 @@ export const companiesConnectionWithPeopleConnectionWithFavoritesConnectionMock:
startCursor:
'WyIwYWEwMGJlYi1hYzczLTQ3OTctODI0ZS04N2ExZjVhZWE5ZTAiXQ==',
},
totalCount: 2,
},
},
},
],
totalCount: 13,
};

export const peopleWithTheirUniqueCompanies: ObjectRecordConnection<
Expand All @@ -597,6 +627,7 @@ export const peopleWithTheirUniqueCompanies: ObjectRecordConnection<
hasPreviousPage: false,
startCursor: 'WyIwYWEwMGJlYi1hYzczLTQ3OTctODI0ZS04N2ExZjVhZWE5ZTAiXQ==',
},
totalCount: 15,
edges: [
{
cursor: 'WyIwYWEwMGJlYi1hYzczLTQ3OTctODI0ZS04N2ExZjVhZWE5ZTAiXQ==',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
edges: newEdges,
pageInfo:
fetchMoreResult?.[objectMetadataItem.namePlural].pageInfo,
totalCount:
fetchMoreResult?.[objectMetadataItem.namePlural].totalCount,
});

return Object.assign({}, prev, {
Expand All @@ -156,6 +158,8 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
edges: newEdges,
pageInfo:
fetchMoreResult?.[objectMetadataItem.namePlural].pageInfo,
totalCount:
fetchMoreResult?.[objectMetadataItem.namePlural].totalCount,
},
} as ObjectRecordQueryResult<T>);
},
Expand Down Expand Up @@ -224,6 +228,7 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
return {
objectMetadataItem,
records: useRecordsWithoutConnection ? recordsWithoutConnection : records,
totalCount: data?.[objectMetadataItem.namePlural].totalCount || 0,
loading,
error,
fetchMoreRecords,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const useGenerateFindManyRecordsQuery = () => {
startCursor
endCursor
}
totalCount
}
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ export const useLoadRecordIndexBoard = ({
recordIndexIsCompactModeActiveState,
);

const { records, loading, fetchMoreRecords, queryStateIdentifier } =
useFindManyRecords({
objectNameSingular,
filter: requestFilters,
orderBy,
});
const {
records,
totalCount,
loading,
fetchMoreRecords,
queryStateIdentifier,
} = useFindManyRecords({
objectNameSingular,
filter: requestFilters,
orderBy,
});

const { setEntityCountInCurrentView } = useViewBar({
viewBarId,
Expand All @@ -80,8 +85,8 @@ export const useLoadRecordIndexBoard = ({
}, [records, setRecordsInStore]);

useEffect(() => {
setEntityCountInCurrentView(records.length);
}, [records.length, setEntityCountInCurrentView]);
setEntityCountInCurrentView(totalCount);
}, [totalCount, setEntityCountInCurrentView]);

useEffect(() => {
setIsCompactModeActive(recordIndexIsCompactModeActive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ export const useLoadRecordIndexTable = (objectNameSingular: string) => {
objectMetadataItem?.fields ?? [],
);

const { records, loading, fetchMoreRecords, queryStateIdentifier } =
useFindManyRecords({
objectNameSingular,
filter: requestFilters,
orderBy,
onCompleted: () => {
setLastRowVisible(false);
setIsRecordTableInitialLoading(false);
},
});
const {
records,
loading,
totalCount,
fetchMoreRecords,
queryStateIdentifier,
} = useFindManyRecords({
objectNameSingular,
filter: requestFilters,
orderBy,
onCompleted: () => {
setLastRowVisible(false);
setIsRecordTableInitialLoading(false);
},
});

return {
records: isCurrentWorkspaceActive ? records : signInBackgroundMockCompanies,
totalCount: totalCount || 0,
loading,
fetchMoreRecords,
queryStateIdentifier,
Expand Down
Loading
Loading