Skip to content

Commit

Permalink
[LazyDataSource]: fixed reload data on DS deps change and fixed fetch…
Browse files Browse the repository at this point in the history
…ing minus count on scroll up.
  • Loading branch information
Kuznietsov authored and AlekseyManetov committed Jun 21, 2024
1 parent a213010 commit 8ea0e83
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { usePrevious } from '../../../../../../../hooks/usePrevious';
import { DataSourceState } from '../../../../../../../types';
import { isQueryChanged } from './helpers';
import { useCallback, useMemo } from 'react';
import { useDepsChanged } from '../../common/useDepsChanged';

export interface UseLazyFetchingAdvisorProps<TId, TFilter = any> {
dataSourceState: DataSourceState<TFilter, TId>;
Expand All @@ -12,13 +13,17 @@ export interface UseLazyFetchingAdvisorProps<TId, TFilter = any> {
showSelectedOnly?: boolean;
}

export function useLazyFetchingAdvisor<TId, TFilter = any>({
dataSourceState,
filter,
forceReload,
backgroundReload,
showSelectedOnly,
}: UseLazyFetchingAdvisorProps<TId, TFilter>) {
export function useLazyFetchingAdvisor<TId, TFilter = any>(
{
dataSourceState,
filter,
forceReload,
backgroundReload,
showSelectedOnly,
}: UseLazyFetchingAdvisorProps<TId, TFilter>,
deps: any[] = [],
) {
const depsChanged = useDepsChanged(deps);
const areMoreRowsNeeded = useCallback((
prevValue?: DataSourceState<TFilter, TId>,
newValue?: DataSourceState<TFilter, TId>,
Expand All @@ -40,8 +45,9 @@ export function useLazyFetchingAdvisor<TId, TFilter = any>({
|| !isEqual(prevFilter, filter)
|| isQueryChanged(prevDataSourceState, dataSourceState)
|| (prevShowSelectedOnly !== showSelectedOnly && !showSelectedOnly)
|| forceReload,
[dataSourceState, filter, forceReload],
|| forceReload
|| depsChanged,
[dataSourceState, filter, forceReload, depsChanged],
);

const moreRowsNeeded = areMoreRowsNeeded(prevDataSourceState, dataSourceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function useLazyTree<TItem, TId, TFilter = any>(
forceReload: isForceReload,
backgroundReload,
showSelectedOnly,
});
}, [...deps]);

useEffect(() => {
if (showSelectedOnly && isSelectedOrCheckedChanged(dataSourceState, prevDataSourceState)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class FetchingHelper {
remainingRowsCount = Number.MAX_SAFE_INTEGER;
}

const missingCount = remainingRowsCount - ids.length;
const missingCount = Math.max(0, remainingRowsCount - ids.length);

const availableCount = childrenCount != null ? childrenCount - ids.length : missingCount;

Expand Down

0 comments on commit 8ea0e83

Please sign in to comment.