fix(explore): reordering columns with dnd sometimes glitching (#16322)

* fix(explore): reordering columns with dnd sometimes glitching

* Fix metrics and filters popover being stale after reordering
This commit is contained in:
Kamil Gabryjelski
2021-08-18 18:39:05 +02:00
committed by GitHub
parent 2c595b09ea
commit a547dcb73e
7 changed files with 9 additions and 19 deletions

View File

@@ -401,7 +401,6 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => {
visible={newFilterPopoverVisible}
togglePopover={togglePopover}
closePopover={closePopover}
createNew
>
<div />
</AdhocFilterPopoverTrigger>

View File

@@ -378,7 +378,6 @@ export const DndMetricSelect = (props: any) => {
visible={newMetricPopoverVisible}
togglePopover={togglePopover}
closePopover={closePopover}
createNew
>
<div />
</AdhocMetricPopoverTrigger>

View File

@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import React, { useMemo, useRef } from 'react';
import React, { useRef } from 'react';
import {
useDrag,
useDrop,
@@ -63,15 +63,11 @@ export default function OptionWrapper(
const ref = useRef<HTMLDivElement>(null);
const labelRef = useRef<HTMLDivElement>(null);
const item: OptionItemInterface = useMemo(
() => ({
dragIndex: index,
type,
}),
[index, type],
);
const [{ isDragging }, drag] = useDrag({
item,
item: {
type,
dragIndex: index,
},
collect: (monitor: DragSourceMonitor) => ({
isDragging: monitor.isDragging(),
}),
@@ -99,8 +95,8 @@ export default function OptionWrapper(
// Determine mouse position
const clientOffset = monitor.getClientOffset();
// Get pixels to the top
const hoverClientY = clientOffset?.y
? clientOffset?.y - hoverBoundingRect.top
const hoverClientY = clientOffset
? clientOffset.y - hoverBoundingRect.top
: 0;
// Only perform the move when the mouse has crossed half of the items height
// When dragging downwards, only move when the cursor is below 50%