diff --git a/uui-core/src/data/processing/views/__tests__/ArrayListView.patch-items.test.ts b/uui-core/src/data/processing/views/__tests__/ArrayListView.patch-items.test.ts index 5df90d01d8..c8873ca0fc 100644 --- a/uui-core/src/data/processing/views/__tests__/ArrayListView.patch-items.test.ts +++ b/uui-core/src/data/processing/views/__tests__/ArrayListView.patch-items.test.ts @@ -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> = { + 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({ diff --git a/uui-core/src/data/processing/views/__tests__/AsyncListView.patch-items.test.ts b/uui-core/src/data/processing/views/__tests__/AsyncListView.patch-items.test.ts index 4a6658b885..7d6ae4eba5 100644 --- a/uui-core/src/data/processing/views/__tests__/AsyncListView.patch-items.test.ts +++ b/uui-core/src/data/processing/views/__tests__/AsyncListView.patch-items.test.ts @@ -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> = { + 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({ diff --git a/uui-core/src/data/processing/views/__tests__/LazyListView.patch-items.test.ts b/uui-core/src/data/processing/views/__tests__/LazyListView.patch-items.test.ts index d9a285c915..0007ff35a6 100644 --- a/uui-core/src/data/processing/views/__tests__/LazyListView.patch-items.test.ts +++ b/uui-core/src/data/processing/views/__tests__/LazyListView.patch-items.test.ts @@ -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> = { + 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({ diff --git a/uui-core/src/data/processing/views/tree/hooks/strategies/asyncTree/useAsyncTree.ts b/uui-core/src/data/processing/views/tree/hooks/strategies/asyncTree/useAsyncTree.ts index 221d23574e..0145c2a187 100644 --- a/uui-core/src/data/processing/views/tree/hooks/strategies/asyncTree/useAsyncTree.ts +++ b/uui-core/src/data/processing/views/tree/hooks/strategies/asyncTree/useAsyncTree.ts @@ -34,6 +34,7 @@ export function useAsyncTree( selectAll, isLoaded, getItemTemporaryOrder, + fixItemBetweenSortings, } = props; const { itemsMap, setItems } = useItemsStorage({ @@ -122,6 +123,7 @@ export function useAsyncTree( isDeleted, getNewItemPosition, getItemTemporaryOrder, + fixItemBetweenSortings, sorting: dataSourceState.sorting, sortBy, }); diff --git a/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyTree.ts b/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyTree.ts index ecf71f8ef0..6f121435f9 100644 --- a/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyTree.ts +++ b/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyTree.ts @@ -19,7 +19,8 @@ export function useLazyTree( 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 }); @@ -164,6 +165,7 @@ export function useLazyTree( isDeleted, getNewItemPosition, getItemTemporaryOrder, + fixItemBetweenSortings, sorting: dataSourceState.sorting, sortBy, }); diff --git a/uui-core/src/data/processing/views/tree/hooks/strategies/syncTree/useSyncTree.ts b/uui-core/src/data/processing/views/tree/hooks/strategies/syncTree/useSyncTree.ts index 4eed9c6026..1375e3519e 100644 --- a/uui-core/src/data/processing/views/tree/hooks/strategies/syncTree/useSyncTree.ts +++ b/uui-core/src/data/processing/views/tree/hooks/strategies/syncTree/useSyncTree.ts @@ -32,6 +32,9 @@ export function useSyncTree( cascadeSelection, showSelectedOnly, selectAll, + fixItemBetweenSortings, + getNewItemPosition, + isDeleted, } = props; const { itemsMap, setItems } = useItemsStorage({ @@ -70,10 +73,11 @@ export function useSyncTree( 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(() => {