1+ import { closestCenter , DndContext , KeyboardSensor , PointerSensor , useSensor , useSensors } from '@dnd-kit/core' ;
2+ import { SortableContext , sortableKeyboardCoordinates , verticalListSortingStrategy } from '@dnd-kit/sortable' ;
13import C from '@generatedata/config/constants' ;
24import { PrimaryButton , Tooltip } from '@generatedata/core' ;
35import { DataTypeFolder } from '@generatedata/plugins' ;
46import CloseIcon from '@mui/icons-material/Close' ;
57import IconButton from '@mui/material/IconButton' ;
68import { useMeasure } from '@uidotdev/usehooks' ;
79import React , { useMemo } from 'react' ;
8- import { DragDropContext , Droppable } from 'react-beautiful-dnd' ;
910import { useWindowSize } from 'react-hooks-window-size' ;
1011import { DataRow } from '~store/generator/generator.reducer' ;
1112import { useClasses } from './Grid.styles' ;
12- import GridRow from './GridRow.container ' ;
13+ import { GridRow } from './GridRow.component ' ;
1314
1415export type GridProps = {
1516 rows : DataRow [ ] ;
@@ -28,6 +29,13 @@ const Grid = ({ rows, onAddRows, onSort, i18n, columnTitle, toggleGrid, changeSm
2829 const [ measureRef , { width = 0 , height = 0 } ] = useMeasure ( ) ;
2930 const classNames = useClasses ( ) ;
3031
32+ const sensors = useSensors (
33+ useSensor ( PointerSensor ) ,
34+ useSensor ( KeyboardSensor , {
35+ coordinateGetter : sortableKeyboardCoordinates
36+ } )
37+ ) ;
38+
3139 let gridSizeClass = '' ;
3240 if ( width && width < C . GRID . SMALL_BREAKPOINT ) {
3341 gridSizeClass = classNames . gridSmall ;
@@ -48,6 +56,25 @@ const Grid = ({ rows, onAddRows, onSort, i18n, columnTitle, toggleGrid, changeSm
4856 // to prevent repaints
4957 const memoizedDimensions = useMemo ( ( ) => ( { width, height } ) , [ width , height ] ) as { width : number ; height : number } ;
5058
59+ // <DragDropContext onDragEnd={({ draggableId, destination }: any): any => onSort(draggableId, destination.index)}>
60+ // <Droppable droppableId="droppable">
61+ // {(provided: any): any => (
62+ // <div className={classNames.grid} {...provided.droppableProps} ref={provided.innerRef}>
63+ // {rows.map((row, index) => (
64+ // <GridRow
65+ // row={row}
66+ // key={row.id}
67+ // index={index}
68+ // gridPanelDimensions={memoizedDimensions}
69+ // showHelpDialog={showHelpDialog}
70+ // />
71+ // ))}
72+ // {provided.placeholder}
73+ // </div>
74+ // )}
75+ // </Droppable>
76+ // </DragDropContext>
77+
5178 return (
5279 < >
5380 < div style = { { position : 'fixed' , right : 0 , padding : 10 } } >
@@ -76,25 +103,25 @@ const Grid = ({ rows, onAddRows, onSort, i18n, columnTitle, toggleGrid, changeSm
76103 </ div >
77104 < div className = { `${ classNames . scrollableGridRows } tour-scrollableGridRows` } >
78105 < div className = { `${ classNames . gridRowsWrapper } tour-gridRows` } >
79- < DragDropContext onDragEnd = { ( { draggableId , destination } : any ) : any => onSort ( draggableId , destination . index ) } >
80- < Droppable droppableId = "droppable" >
81- { ( provided : any ) : any => (
82- < div className = { classNames . grid } { ... provided . droppableProps } ref = { provided . innerRef } >
83- { rows . map ( ( row , index ) => (
84- < GridRow
85- row = { row }
86- key = { row . id }
87- index = { index }
88- gridPanelDimensions = { memoizedDimensions }
89- showHelpDialog = { showHelpDialog }
90- />
91- ) ) }
92- { provided . placeholder }
93- </ div >
94- ) }
95- </ Droppable >
96- </ DragDropContext >
97-
106+ < DndContext
107+ sensors = { sensors }
108+ collisionDetection = { closestCenter }
109+ onDragEnd = { ( { draggableId , destination } : any ) : any => onSort ( draggableId , destination . index ) }
110+ >
111+ < div className = { classNames . grid } >
112+ < SortableContext items = { rows } strategy = { verticalListSortingStrategy } >
113+ { rows . map ( ( row , index ) => (
114+ < GridRow
115+ row = { row }
116+ key = { row . id }
117+ index = { index }
118+ gridPanelDimensions = { memoizedDimensions }
119+ showHelpDialog = { showHelpDialog }
120+ / >
121+ ) ) }
122+ </ SortableContext >
123+ </ div >
124+ </ DndContext >
98125 < form onSubmit = { ( e ) : any => e . preventDefault ( ) } className = { `${ classNames . addRows } tour-addRows` } >
99126 < span > { i18n . add } </ span >
100127 < input
0 commit comments