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

Fix infinite scroll issue on table #5996

Merged
merged 2 commits into from
Jun 24, 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
@@ -1,4 +1,4 @@
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useRecoilValue } from 'recoil';

import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
Expand Down Expand Up @@ -41,8 +41,6 @@ export const useLoadRecordIndexTable = (objectNameSingular: string) => {

const { setRecordTableData, setIsRecordTableInitialLoading } =
useRecordTable();
const { tableLastRowVisibleState } = useRecordTableStates();
const setLastRowVisible = useSetRecoilState(tableLastRowVisibleState);
const currentWorkspace = useRecoilValue(currentWorkspaceState);
const params = useFindManyParams(objectNameSingular);

Expand All @@ -58,7 +56,6 @@ export const useLoadRecordIndexTable = (objectNameSingular: string) => {
...params,
recordGqlFields,
onCompleted: () => {
setLastRowVisible(false);
setIsRecordTableInitialLoading(false);
},
onError: () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';
import { useRecoilValue } from 'recoil';

import { useLoadRecordIndexTable } from '@/object-record/record-index/hooks/useLoadRecordIndexTable';
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
Expand All @@ -18,20 +18,18 @@ export const RecordTableBodyEffect = ({
records,
totalCount,
setRecordTableData,
queryStateIdentifier,
loading,
queryStateIdentifier,
} = useLoadRecordIndexTable(objectNameSingular);

const { tableLastRowVisibleState } = useRecordTableStates();

const [tableLastRowVisible, setTableLastRowVisible] = useRecoilState(
tableLastRowVisibleState,
);

const isFetchingMoreObjects = useRecoilValue(
isFetchingMoreRecordsFamilyState(queryStateIdentifier),
);

const { tableLastRowVisibleState } = useRecordTableStates();

const tableLastRowVisible = useRecoilValue(tableLastRowVisibleState);

const rowHeight = 32;
const viewportHeight = records.length * rowHeight;

Expand All @@ -44,15 +42,13 @@ export const RecordTableBodyEffect = ({
}, [records, totalCount, setRecordTableData, loading]);

useEffect(() => {
if (tableLastRowVisible && !isFetchingMoreObjects) {
fetchMoreObjects();
}
}, [
fetchMoreObjects,
isFetchingMoreObjects,
setTableLastRowVisible,
tableLastRowVisible,
]);
// We are adding a setTimeout here to give the user some room to scroll if they want to within this throttle window
setTimeout(async () => {
if (!isFetchingMoreObjects && tableLastRowVisible) {
await fetchMoreObjects();
}
}, 100);
}, [fetchMoreObjects, isFetchingMoreObjects, tableLastRowVisible]);

return <></>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const RecordTableBodyLoading = () => {
isDragging={false}
data-testid={`row-id-${rowIndex}`}
data-selectable-id={`row-id-${rowIndex}`}
key={rowIndex}
>
<StyledTd data-select-disable>
<GripCell isDragging={false} />
Expand Down
Loading