Skip to content

Commit

Permalink
Merge branch 'develop' into feature/new-ds-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuznietsov committed Apr 4, 2024
2 parents 0c9a960 + 40c329d commit e2e9c60
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 4 deletions.
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

0 comments on commit e2e9c60

Please sign in to comment.