diff --git a/src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx b/src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx index dfaddceec1..edf5521c6d 100644 --- a/src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx +++ b/src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx @@ -4,12 +4,6 @@ import {Gear, Grip, Lock} from '@gravity-ui/icons'; import {DragDropContext, Draggable, Droppable} from 'react-beautiful-dnd'; import type {OnDragEndResponder} from 'react-beautiful-dnd'; -import type { - TreeSelectProps, - TreeSelectRenderContainer, - TreeSelectRenderItem, -} from 'src/components/TreeSelect/types'; - import {useUniqId} from '../../../../../hooks'; import type {PopperPlacement} from '../../../../../hooks/private'; import {createOnKeyDownHandler} from '../../../../../hooks/useActionHandlers/useActionHandlers'; @@ -18,6 +12,11 @@ import {Icon} from '../../../../Icon'; import {TreeSelect} from '../../../../TreeSelect/TreeSelect'; import {TreeSelectItem} from '../../../../TreeSelect/TreeSelectItem'; import type {TreeSelectItemProps} from '../../../../TreeSelect/TreeSelectItem'; +import type { + TreeSelectProps, + TreeSelectRenderContainer, + TreeSelectRenderItem, +} from '../../../../TreeSelect/types'; import {ListContainerView} from '../../../../useList'; import {block} from '../../../../utils/cn'; import type {TableColumnSetupItem, TableSetting} from '../withTableSettings'; @@ -136,95 +135,95 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => { }); }; - const renderContainer = React.useCallback>( - ({renderItem, visibleFlattenIds, items: _items, containerRef, id}) => { - const handleDrugEnd: OnDragEndResponder = ({destination, source}) => { - if (destination?.index !== undefined && destination?.index !== source.index) { - setItems((prevItems) => { - return reorderArray(prevItems, source.index, destination.index); - }); - } - }; - - const visibleFlattenItemList = visibleFlattenIds.map((visibleFlattenId, idx) => - renderItem(visibleFlattenId, idx), - ); - - return ( - - - - - {(droppableProvided) => { - return ( -
- {visibleFlattenItemList} - {droppableProvided.placeholder} -
- ); - }} -
-
-
- -
- ); - }, - [], - ); + const renderContainer: TreeSelectRenderContainer = ({ + renderItem, + visibleFlattenIds, + items: _items, + containerRef, + id, + }) => { + const handleDrugEnd: OnDragEndResponder = ({destination, source}) => { + if (destination?.index !== undefined && destination?.index !== source.index) { + setItems((prevItems) => { + return reorderArray(prevItems, source.index, destination.index); + }); + } + }; - const renderItem = React.useCallback>( - ({data, props, index}) => { - const isDragDisabled = sortable === false; - - const endSlot = - data.endSlot ?? (isDragDisabled ? undefined : ); - - const commonProps = { - ...props, - ...data, - endSlot, - }; - - return ( - - {(provided, snapshot) => { - const style: React.CSSProperties = { - ...provided.draggableProps.style, - }; - - // not expected offset appears, one way to fix - remove this offsets explicitly - if (snapshot.isDragging) { - style.left = undefined; - style.top = undefined; - } - - return ( - - ); - }} - - ); - }, - [sortable], - ); + const visibleFlattenItemList = visibleFlattenIds.map((visibleFlattenId, idx) => + renderItem(visibleFlattenId, idx), + ); + + return ( + + + + + {(droppableProvided) => { + return ( +
+ {visibleFlattenItemList} + {droppableProvided.placeholder} +
+ ); + }} +
+
+
+ +
+ ); + }; + + const renderItem: TreeSelectRenderItem = ({data, props, index}) => { + const isDragDisabled = sortable === false; + + const endSlot = + data.endSlot ?? (isDragDisabled ? undefined : ); + + const commonProps = { + ...props, + ...data, + endSlot, + }; + + return ( + + {(provided, snapshot) => { + const style: React.CSSProperties = { + ...provided.draggableProps.style, + }; + + // not expected offset appears, one way to fix - remove this offsets explicitly + if (snapshot.isDragging) { + style.left = undefined; + style.top = undefined; + } + + return ( + + ); + }} + + ); + }; const value = React.useMemo(() => { const selectedIds: string[] = []; diff --git a/src/components/Table/hoc/withTableSettings/withTableSettings.tsx b/src/components/Table/hoc/withTableSettings/withTableSettings.tsx index 5307390327..b46f4269f1 100644 --- a/src/components/Table/hoc/withTableSettings/withTableSettings.tsx +++ b/src/components/Table/hoc/withTableSettings/withTableSettings.tsx @@ -5,11 +5,10 @@ import _get from 'lodash/get'; import _isString from 'lodash/isString'; import _last from 'lodash/last'; -import type {TreeSelectProps} from 'src/components/TreeSelect'; - import type {PopperPlacement} from '../../../../hooks/private'; import {Button} from '../../../Button'; import {Icon} from '../../../Icon'; +import type {TreeSelectProps} from '../../../TreeSelect'; import {block} from '../../../utils/cn'; import {getComponentName} from '../../../utils/getComponentName'; import type {TableColumnConfig, TableDataItem, TableProps} from '../../Table'; diff --git a/src/components/TreeSelect/components/TreeListContainer/TreeListContainer.tsx b/src/components/TreeSelect/components/TreeListContainer/TreeListContainer.tsx index 22ec09a1ee..9b1f6cf39d 100644 --- a/src/components/TreeSelect/components/TreeListContainer/TreeListContainer.tsx +++ b/src/components/TreeSelect/components/TreeListContainer/TreeListContainer.tsx @@ -1,9 +1,8 @@ import React from 'react'; -import type {TreeSelectRenderContainerProps} from 'src/components/TreeSelect/types'; - import {ListContainerView} from '../../../useList'; import {ListItemRecursiveRenderer} from '../../../useList/components/ListRecursiveRenderer/ListRecursiveRenderer'; +import type {TreeSelectRenderContainerProps} from '../../types'; export const TreeListContainer = ({ items,