@@ -19,11 +19,11 @@ import PlusIcon from "components/img/Plus";
1919import { LOGGER } from "services/Logger" ;
2020import DefaultCell from "components/Cell" ;
2121import Header from "components/Header" ;
22- import { useDraggableInPortal } from "components/portals/UseDraggableInPortal" ;
2322import { c } from "helpers/StylesHelper" ;
2423import { HeaderNavBar } from "components/NavBar" ;
2524import { getColumnsWidthStyle } from "components/styles/ColumnWidthStyle" ;
2625import { HeaderContext } from "components/contexts/HeaderContext" ;
26+ import { getDndListStyle , getDndItemStyle } from "./styles/DnDStyle" ;
2727
2828const defaultColumn = {
2929 minWidth : 50 ,
@@ -191,11 +191,8 @@ export function Table(initialState: TableDataType) {
191191 const [ columnsWidthState , setColumnsWidthState ] = React . useState (
192192 getColumnsWidthStyle ( rows , columns )
193193 ) ;
194-
195- const [ isDragUpdate , setDragUpdate ] = React . useState ( false ) ;
196194 // Manage DnD
197195 const currentColOrder = React . useRef ( null ) ;
198- const renderDraggable = useDraggableInPortal ( ) ;
199196 // Manage input of new row
200197 const [ inputNewRow , setInputNewRow ] = React . useState ( "" ) ;
201198 const newRowRef = React . useRef ( null ) ;
@@ -248,9 +245,6 @@ export function Table(initialState: TableDataType) {
248245 currentColOrder . current = allColumns . map ( ( o : Column ) => o . id ) ;
249246 } }
250247 onDragUpdate = { ( dragUpdateObj , b ) => {
251- if ( ! isDragUpdate ) {
252- setDragUpdate ( true ) ;
253- }
254248 const colOrder = [ ...currentColOrder . current ] ;
255249 const sIndex = dragUpdateObj . source . index ;
256250 const dIndex =
@@ -272,24 +266,23 @@ export function Table(initialState: TableDataType) {
272266
273267 // clear the current order
274268 currentColOrder . current = null ;
275- setDragUpdate ( false ) ;
276269 } }
277270 >
278271 < Droppable
279272 key = { `Droppable-${ i } ` }
280273 droppableId = "droppable"
281274 direction = "horizontal"
282275 >
283- { ( droppableProvided , snapshot ) => (
276+ { ( provided , snapshot ) => (
284277 < div
285278 key = { `div-Droppable-${ i } ` }
279+ { ...provided . droppableProps }
286280 { ...headerGroup . getHeaderGroupProps ( {
287281 style : {
288- ...headerGroup . getHeaderGroupProps ( ) . style ,
289- maxWidth : `${ totalColumnsWidth } px` ,
282+ ...getDndListStyle ( snapshot . isDraggingOver ) ,
290283 } ,
291284 } ) }
292- ref = { droppableProvided . innerRef }
285+ ref = { provided . innerRef }
293286 className = { `${ c ( "tr header-group" ) } ` }
294287 >
295288 { headerGroup . headers . map ( ( column , index ) => (
@@ -299,29 +292,28 @@ export function Table(initialState: TableDataType) {
299292 index = { index }
300293 isDragDisabled = { ( column as any ) . skipPersist }
301294 >
302- { renderDraggable ( ( provided ) => {
295+ { ( provided , snapshot ) => {
303296 const tableCellBaseProps = {
304- ...column . getHeaderProps ( ) ,
305- className : `${ c ( "th noselect" ) } header` ,
306- key : `div-Draggable-${ column . id } ` ,
307297 ...provided . draggableProps ,
308298 ...provided . dragHandleProps ,
299+ ...column . getHeaderProps ( {
300+ style : {
301+ width : `${
302+ columnsWidthState . widthRecord [ column . id ]
303+ } px`,
304+ ...getDndItemStyle (
305+ snapshot . isDragging ,
306+ provided . draggableProps . style
307+ ) ,
308+ } ,
309+ } ) ,
310+ className : `${ c ( "th noselect" ) } header` ,
311+ key : `div-Draggable-${ column . id } ` ,
309312 // {...extraProps}
310313 ref : provided . innerRef ,
311314 } ;
312- const tableCellProps = isDragUpdate
313- ? tableCellBaseProps
314- : {
315- ...tableCellBaseProps ,
316- style : {
317- ...column . getHeaderProps ( ) . style ,
318- width : `${ columnsWidthState . widthRecord [ column . id ]
319- } px`,
320- } ,
321- } ;
322-
323315 return (
324- < div { ...tableCellProps } >
316+ < div { ...tableCellBaseProps } >
325317 < HeaderContext . Provider
326318 value = { {
327319 columnWidthState : columnsWidthState ,
@@ -332,10 +324,10 @@ export function Table(initialState: TableDataType) {
332324 </ HeaderContext . Provider >
333325 </ div >
334326 ) ;
335- } ) }
327+ } }
336328 </ Draggable >
337329 ) ) }
338- { droppableProvided . placeholder }
330+ { provided . placeholder }
339331 </ div >
340332 ) }
341333 </ Droppable >
@@ -347,27 +339,27 @@ export function Table(initialState: TableDataType) {
347339 { rows . map ( ( row , i ) => {
348340 prepareRow ( row ) ;
349341 return (
350- < div { ...row . getRowProps ( ) } className = { `${ c ( "tr" ) } ` } key = { row . id } >
342+ < div
343+ { ...row . getRowProps ( {
344+ style : {
345+ maxWidth : `${ totalColumnsWidth } px` ,
346+ } ,
347+ } ) }
348+ className = { `${ c ( "tr" ) } ` }
349+ key = { row . id }
350+ >
351351 { row . cells . map ( ( cell ) => {
352352 const tableCellBaseProps = {
353353 ...cell . getCellProps ( {
354354 style : {
355- ...cell . getCellProps ( ) . style ,
356- maxWidth : `${ totalColumnsWidth } px` ,
355+ width : columnsWidthState . widthRecord [ cell . column . id ] ,
357356 } ,
358357 } ) ,
359358 className : `${ c ( "td" ) } ` ,
360359 } ;
361- const tableCellProps = isDragUpdate
362- ? tableCellBaseProps
363- : {
364- ...tableCellBaseProps ,
365- style : {
366- ...tableCellBaseProps . style ,
367- width : columnsWidthState . widthRecord [ cell . column . id ] ,
368- } ,
369- } ;
370- return < div { ...tableCellProps } > { cell . render ( "Cell" ) } </ div > ;
360+ return (
361+ < div { ...tableCellBaseProps } > { cell . render ( "Cell" ) } </ div >
362+ ) ;
371363 } ) }
372364 </ div >
373365 ) ;
@@ -383,14 +375,17 @@ export function Table(initialState: TableDataType) {
383375 placeholder = "filename of new row"
384376 />
385377 </ div >
386- < div className = { `${ c ( "td" ) } ` } onClick = { ( ) => {
387- dataDispatch ( {
388- type : ActionTypes . ADD_ROW ,
389- filename : inputNewRow ,
390- } ) ;
391- setInputNewRow ( "" ) ;
392- newRowRef . current . value = "" ;
393- } } >
378+ < div
379+ className = { `${ c ( "td" ) } ` }
380+ onClick = { ( ) => {
381+ dataDispatch ( {
382+ type : ActionTypes . ADD_ROW ,
383+ filename : inputNewRow ,
384+ } ) ;
385+ setInputNewRow ( "" ) ;
386+ newRowRef . current . value = "" ;
387+ } }
388+ >
394389 < span className = "svg-icon svg-gray" style = { { marginRight : 4 } } >
395390 < PlusIcon />
396391 </ span >
0 commit comments