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

[useTree]: fixed missing fixItemBetweenSortings. #2114

Merged
merged 2 commits into from
Apr 4, 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 @@ -306,6 +306,57 @@ describe('ArrayListView - patch items', () => {
});
});

it('should apply sort to the item during editing if fixItemBetweenSortings = false', async () => {
const getNewItemPosition = () => PatchOrdering.TOP;
const patch = createItemsMap({
'c-EU': {
id: 'c-EU',
type: 'continent',
name: '0 Europe',
__typename: 'Location',
childCount: 1,
},
});

const dataSource = getArrayLocationsDS({});

currentValue.visibleCount = 10;
currentValue.sorting = [{ field: 'name', direction: 'desc' }];
const props: Partial<ArrayListViewProps<LocationItem, string, any>> = {
patch,
getNewItemPosition,
fixItemBetweenSortings: false,
};

const hookResult = renderHook(
({ value, onValueChange, props }) => dataSource.useView(value, onValueChange, props),
{ initialProps: {
value: currentValue,
onValueChange: onValueChanged,
props,
} },
);

await waitFor(() => {
const view = hookResult.result.current;
expectViewToLookLike(view, [
{ id: 'c-AF' },
{ id: 'c-EU',
value: {
id: 'c-EU',
type: 'continent',
name: '0 Europe',
__typename: 'Location',
childCount: 1,
},
},
]);
});

const view = hookResult.result.current;
expect(view.getListProps().rowsCount).toEqual(2);
});

it('should fix position of item from patch till the next sorting change and apply sorting after sorting change', async () => {
const getNewItemPosition = () => PatchOrdering.TOP;
const patch = createItemsMap({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,57 @@ describe('AsyncListView - patch items', () => {
});
});

it('should apply sort to the item during editing if fixItemBetweenSortings = false', async () => {
const getNewItemPosition = () => PatchOrdering.TOP;
const patch = createItemsMap({
'c-EU': {
id: 'c-EU',
type: 'continent',
name: '0 Europe',
__typename: 'Location',
childCount: 1,
},
});

const { dataSource } = getAsyncLocationsDS({});

currentValue.visibleCount = 10;
currentValue.sorting = [{ field: 'name', direction: 'desc' }];
const props: Partial<AsyncListViewProps<LocationItem, string, any>> = {
patch,
getNewItemPosition,
fixItemBetweenSortings: false,
};

const hookResult = renderHook(
({ value, onValueChange, props }) => dataSource.useView(value, onValueChange, props),
{ initialProps: {
value: currentValue,
onValueChange: onValueChanged,
props,
} },
);

await waitFor(() => {
const view = hookResult.result.current;
expectViewToLookLike(view, [
{ id: 'c-AF' },
{ id: 'c-EU',
value: {
id: 'c-EU',
type: 'continent',
name: '0 Europe',
__typename: 'Location',
childCount: 1,
},
},
]);
});

const view = hookResult.result.current;
expect(view.getListProps().rowsCount).toEqual(2);
});

it('should delete items from tree', async () => {
const getNewItemPosition = () => PatchOrdering.TOP;
const patch = createItemsMap({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,57 @@ describe('LazyListView - patch items', () => {
});
});

it('should apply sort to the item during editing if fixItemBetweenSortings = false', async () => {
const getNewItemPosition = () => PatchOrdering.TOP;
const patch = createItemsMap({
'c-EU': {
id: 'c-EU',
type: 'continent',
name: '0 Europe',
__typename: 'Location',
childCount: 1,
},
});

const { dataSource } = getLazyLocationsDS({});

currentValue.visibleCount = 10;
currentValue.sorting = [{ field: 'name', direction: 'desc' }];
const props: Partial<LazyListViewProps<LocationItem, string, any>> = {
patch,
getNewItemPosition,
fixItemBetweenSortings: false,
};

const hookResult = renderHook(
({ value, onValueChange, props }) => dataSource.useView(value, onValueChange, props),
{ initialProps: {
value: currentValue,
onValueChange: onValueChanged,
props,
} },
);

await waitFor(() => {
const view = hookResult.result.current;
expectViewToLookLike(view, [
{ id: 'c-AF' },
{ id: 'c-EU',
value: {
id: 'c-EU',
type: 'continent',
name: '0 Europe',
__typename: 'Location',
childCount: 1,
},
},
]);
});

const view = hookResult.result.current;
expect(view.getListProps().rowsCount).toEqual(2);
});

it('should fix position of item from patch till the next sorting change and apply sorting after sorting change', async () => {
const getNewItemPosition = () => PatchOrdering.TOP;
const patch = createItemsMap({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function useAsyncTree<TItem, TId, TFilter = any>(
selectAll,
isLoaded,
getItemTemporaryOrder,
fixItemBetweenSortings,
} = props;

const { itemsMap, setItems } = useItemsStorage({
Expand Down Expand Up @@ -122,6 +123,7 @@ export function useAsyncTree<TItem, TId, TFilter = any>(
isDeleted,
getNewItemPosition,
getItemTemporaryOrder,
fixItemBetweenSortings,
sorting: dataSourceState.sorting,
sortBy,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function useLazyTree<TItem, TId, TFilter = any>(
filter, backgroundReload, showSelectedOnly,
isFoldedByDefault, getId, getParentId, setDataSourceState,
cascadeSelection, getRowOptions, rowOptions, selectAll, fetchStrategy,
getChildCount, itemsStatusMap, complexIds, patch, isDeleted, getNewItemPosition, sortBy, getItemTemporaryOrder,
getChildCount, itemsStatusMap, complexIds, patch, isDeleted, getNewItemPosition, sortBy,
fixItemBetweenSortings, getItemTemporaryOrder,
} = props;

const dataSourceState = useDataSourceStateWithDefaults({ dataSourceState: props.dataSourceState });
Expand Down Expand Up @@ -164,6 +165,7 @@ export function useLazyTree<TItem, TId, TFilter = any>(
isDeleted,
getNewItemPosition,
getItemTemporaryOrder,
fixItemBetweenSortings,
sorting: dataSourceState.sorting,
sortBy,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export function useSyncTree<TItem, TId, TFilter = any>(
cascadeSelection,
showSelectedOnly,
selectAll,
fixItemBetweenSortings,
getNewItemPosition,
isDeleted,
} = props;

const { itemsMap, setItems } = useItemsStorage({
Expand Down Expand Up @@ -70,10 +73,11 @@ export function useSyncTree<TItem, TId, TFilter = any>(
const tree = usePatchTree({
tree: treeWithSelectedOnly,
patch: showSelectedOnly ? null : restProps.patch,
isDeleted: restProps.isDeleted,
getNewItemPosition: restProps.getNewItemPosition,
isDeleted,
getNewItemPosition,
fixItemBetweenSortings,
sorting: dataSourceState.sorting,
sortBy: restProps.sortBy,
sortBy,
});

const reload = useCallback(() => {
Expand Down
Loading