@@ -13,13 +13,11 @@ import { TableCell, TableCellContent } from "../TableCell/TableCell";
13
13
import { TableContext , TableElem } from "../TableContext" ;
14
14
import { getStyle } from "../utils" ;
15
15
import "./TableHead.scss" ;
16
- import { FF_DEV_2984 , FF_DEV_3873 , isFF } from "../../../../utils/feature-flags" ;
16
+ import { FF_DEV_3873 , isFF } from "../../../../utils/feature-flags" ;
17
17
import { getRoot } from "mobx-state-tree" ;
18
18
19
19
const { Block, Elem } = BemWithSpecifiContext ( ) ;
20
20
21
- const is2984FF = isFF ( FF_DEV_2984 ) ;
22
-
23
21
const DropdownWrapper = observer ( ( { column, cellViews, children, onChange } ) => {
24
22
const types = ViewColumnType . _types
25
23
. map ( ( t ) => t . value )
@@ -165,157 +163,132 @@ export const TableHead = observer(
165
163
ref ,
166
164
) => {
167
165
const { columns, headerRenderers, cellViews } = React . useContext ( TableContext ) ;
166
+ const states = useLocalStore ( ( ) => ( {
167
+ orderedColumns : { } ,
168
+ setOrderedColumns ( updatedColumns ) {
169
+ states . orderedColumns = { ...updatedColumns } ;
170
+ } ,
171
+ getOrderedColumns ( ) {
172
+ return toJS ( states . orderedColumns ) ?? { } ;
173
+ } ,
174
+ isDragging : false ,
175
+ setIsDragging ( isDragging ) {
176
+ states . isDragging = isDragging ;
177
+ } ,
178
+ getIsDragging ( ) {
179
+ return toJS ( states . isDragging ) ;
180
+ } ,
181
+ initialDragPos : false ,
182
+ setInitialDragPos ( initPos ) {
183
+ states . initialDragPos = initPos ;
184
+ } ,
185
+ getInitialDragPos ( ) {
186
+ return toJS ( states . initialDragPos ) ;
187
+ } ,
188
+ draggedCol : null ,
189
+ setDraggedCol ( draggedCol ) {
190
+ states . draggedCol = draggedCol ;
191
+ } ,
192
+ getDraggedCol ( ) {
193
+ return toJS ( states . draggedCol ) ;
194
+ } ,
195
+ } ) ) ;
196
+ const colRefs = useRef ( { } ) ;
197
+ const getUpdatedColOrder = useCallback (
198
+ ( cols ) => {
199
+ const orderedColumns = { } ;
168
200
169
- if ( is2984FF ) {
170
- const states = useLocalStore ( ( ) => ( {
171
- orderedColumns : { } ,
172
- setOrderedColumns ( updatedColumns ) {
173
- states . orderedColumns = { ...updatedColumns } ;
174
- } ,
175
- getOrderedColumns ( ) {
176
- return toJS ( states . orderedColumns ) ?? { } ;
177
- } ,
178
- isDragging : false ,
179
- setIsDragging ( isDragging ) {
180
- states . isDragging = isDragging ;
181
- } ,
182
- getIsDragging ( ) {
183
- return toJS ( states . isDragging ) ;
184
- } ,
185
- initialDragPos : false ,
186
- setInitialDragPos ( initPos ) {
187
- states . initialDragPos = initPos ;
188
- } ,
189
- getInitialDragPos ( ) {
190
- return toJS ( states . initialDragPos ) ;
191
- } ,
192
- draggedCol : null ,
193
- setDraggedCol ( draggedCol ) {
194
- states . draggedCol = draggedCol ;
195
- } ,
196
- getDraggedCol ( ) {
197
- return toJS ( states . draggedCol ) ;
198
- } ,
199
- } ) ) ;
200
- const colRefs = useRef ( { } ) ;
201
- const getUpdatedColOrder = useCallback (
202
- ( cols ) => {
203
- const orderedColumns = { } ;
204
-
205
- ( cols ?? columns ) . forEach ( ( col , colIndex ) => {
206
- orderedColumns [ col . id ] = colIndex ;
207
- } ) ;
208
- return orderedColumns ;
209
- } ,
210
- [ columns ] ,
211
- ) ;
201
+ ( cols ?? columns ) . forEach ( ( col , colIndex ) => {
202
+ orderedColumns [ col . id ] = colIndex ;
203
+ } ) ;
204
+ return orderedColumns ;
205
+ } ,
206
+ [ columns ] ,
207
+ ) ;
212
208
213
- useEffect ( ( ) => {
214
- ref . current ?. addEventListener ( "mousedown" , ( event ) => {
215
- const className = event . target . className ;
209
+ useEffect ( ( ) => {
210
+ ref . current ?. addEventListener ( "mousedown" , ( event ) => {
211
+ const className = event . target . className ;
216
212
217
- // This element could be an SVG element where className is an object, not a string.
218
- if ( className ?. includes ?. ( "handle" ) ) {
219
- event . preventDefault ( ) ;
220
- }
221
- } ) ;
222
- } , [ ] ) ;
213
+ // This element could be an SVG element where className is an object, not a string.
214
+ if ( className ?. includes ?. ( "handle" ) ) {
215
+ event . preventDefault ( ) ;
216
+ }
217
+ } ) ;
218
+ } , [ ] ) ;
223
219
224
- return (
225
- < Block
226
- name = "table-head"
227
- ref = { ref }
228
- style = { {
229
- ...style ,
230
- height : isFF ( FF_DEV_3873 ) && 42 ,
231
- } }
232
- mod = { { droppable : true } }
233
- mix = "horizontal-shadow"
234
- onDragOver = { useCallback (
235
- ( e ) => {
236
- const draggedCol = states . getDraggedCol ( ) ;
220
+ return (
221
+ < Block
222
+ name = "table-head"
223
+ ref = { ref }
224
+ style = { {
225
+ ...style ,
226
+ height : isFF ( FF_DEV_3873 ) && 42 ,
227
+ } }
228
+ mod = { { droppable : true } }
229
+ mix = "horizontal-shadow"
230
+ onDragOver = { useCallback (
231
+ ( e ) => {
232
+ const draggedCol = states . getDraggedCol ( ) ;
237
233
238
- colRefs . current [ draggedCol ] . style . setProperty ( "--scale" , "0" ) ;
239
- e . stopPropagation ( ) ;
240
- } ,
241
- [ states ] ,
242
- ) }
243
- >
244
- { columns . map ( ( col ) => {
245
- return (
246
- < Elem
247
- name = "draggable"
248
- draggable = { true }
249
- ref = { ( ele ) => ( colRefs . current [ col . id ] = ele ) }
250
- key = { col . id }
251
- onDragStart = { ( e ) => {
252
- e . dataTransfer . effectAllowed = "none" ;
253
- const ele = colRefs . current [ col . id ] ;
234
+ colRefs . current [ draggedCol ] . style . setProperty ( "--scale" , "0" ) ;
235
+ e . stopPropagation ( ) ;
236
+ } ,
237
+ [ states ] ,
238
+ ) }
239
+ >
240
+ { columns . map ( ( col ) => {
241
+ return (
242
+ < Elem
243
+ name = "draggable"
244
+ draggable = { true }
245
+ ref = { ( ele ) => ( colRefs . current [ col . id ] = ele ) }
246
+ key = { col . id }
247
+ onDragStart = { ( e ) => {
248
+ e . dataTransfer . effectAllowed = "none" ;
249
+ const ele = colRefs . current [ col . id ] ;
254
250
255
- states . setInitialDragPos ( {
256
- x : ele . offsetLeft ,
257
- y : ele . offsetTop ,
258
- } ) ;
259
- states . setDraggedCol ( col . id ) ;
260
- } }
261
- onDragEnd = { ( e ) => {
262
- e . stopPropagation ( ) ;
263
- const draggedCol = states . getDraggedCol ( ) ;
264
- const curColumns = columns . filter ( ( curCol ) => curCol . id !== draggedCol ) ;
265
- const newIndex = curColumns . findIndex ( ( curCol ) => {
266
- const colRefrence = colRefs . current [ curCol . id ] ;
267
- const mousePos = e . clientX + ( ref ?. current ?. parentElement ?. parentElement . scrollLeft ?? 0 ) ;
268
- const isGreaterThanPos = mousePos < colRefrence . offsetLeft + colRefrence . clientWidth / 2 ;
251
+ states . setInitialDragPos ( {
252
+ x : ele . offsetLeft ,
253
+ y : ele . offsetTop ,
254
+ } ) ;
255
+ states . setDraggedCol ( col . id ) ;
256
+ } }
257
+ onDragEnd = { ( e ) => {
258
+ e . stopPropagation ( ) ;
259
+ const draggedCol = states . getDraggedCol ( ) ;
260
+ const curColumns = columns . filter ( ( curCol ) => curCol . id !== draggedCol ) ;
261
+ const newIndex = curColumns . findIndex ( ( curCol ) => {
262
+ const colRefrence = colRefs . current [ curCol . id ] ;
263
+ const mousePos = e . clientX + ( ref ?. current ?. parentElement ?. parentElement . scrollLeft ?? 0 ) ;
264
+ const isGreaterThanPos = mousePos < colRefrence . offsetLeft + colRefrence . clientWidth / 2 ;
269
265
270
- return isGreaterThanPos ;
271
- } ) ;
266
+ return isGreaterThanPos ;
267
+ } ) ;
272
268
273
- colRefs . current [ draggedCol ] . style . setProperty ( "--scale" , "" ) ;
269
+ colRefs . current [ draggedCol ] . style . setProperty ( "--scale" , "" ) ;
274
270
275
- states . setDraggedCol ( null ) ;
276
- curColumns . splice ( newIndex , 0 , col ) ;
277
- const updatedColOrder = getUpdatedColOrder ( curColumns ) ;
271
+ states . setDraggedCol ( null ) ;
272
+ curColumns . splice ( newIndex , 0 , col ) ;
273
+ const updatedColOrder = getUpdatedColOrder ( curColumns ) ;
278
274
279
- onDragEnd ?. ( updatedColOrder ) ;
280
- } }
281
- >
282
- < ColumnRenderer
283
- column = { col }
284
- mod = { { draggable : true } }
285
- headerRenderers = { headerRenderers }
286
- cellViews = { cellViews }
287
- columnHeaderExtra = { columnHeaderExtra }
288
- sortingEnabled = { sortingEnabled }
289
- stopInteractions = { stopInteractions }
290
- decoration = { decoration }
291
- onTypeChange = { onTypeChange }
292
- onResize = { onResize }
293
- onReset = { onReset }
294
- />
295
- </ Elem >
296
- ) ;
297
- } ) }
298
- < Elem name = "extra" > { extra } </ Elem >
299
- </ Block >
300
- ) ;
301
- }
302
- return (
303
- < Block name = "table-head" ref = { ref } style = { style } mix = "horizontal-shadow" >
304
- { columns . map ( ( col ) => {
305
- return (
306
- < ColumnRenderer
307
- key = { col . id }
308
- column = { col }
309
- headerRenderers = { headerRenderers }
310
- cellViews = { cellViews }
311
- columnHeaderExtra = { columnHeaderExtra }
312
- sortingEnabled = { sortingEnabled }
313
- stopInteractions = { stopInteractions }
314
- decoration = { decoration }
315
- onTypeChange = { onTypeChange }
316
- onResize = { onResize }
317
- onReset = { onReset }
318
- />
275
+ onDragEnd ?. ( updatedColOrder ) ;
276
+ } }
277
+ >
278
+ < ColumnRenderer
279
+ column = { col }
280
+ mod = { { draggable : true } }
281
+ headerRenderers = { headerRenderers }
282
+ cellViews = { cellViews }
283
+ columnHeaderExtra = { columnHeaderExtra }
284
+ sortingEnabled = { sortingEnabled }
285
+ stopInteractions = { stopInteractions }
286
+ decoration = { decoration }
287
+ onTypeChange = { onTypeChange }
288
+ onResize = { onResize }
289
+ onReset = { onReset }
290
+ />
291
+ </ Elem >
319
292
) ;
320
293
} ) }
321
294
< Elem name = "extra" > { extra } </ Elem >
0 commit comments