Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Oct 19, 2020
1 parent 029e3c8 commit b56f8a3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/lens/public/drag_drop/drag_drop.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import React from 'react';
import { act } from 'react-dom/test-utils';
import { render, mount } from 'enzyme';
import { DragDrop, ReorderableDragDrop } from './drag_drop';
import { ChildDragDropProvider, ReorderProvider } from './providers';
Expand Down Expand Up @@ -367,7 +366,6 @@ describe('DragDrop', () => {
let dragging: { id: '1' } | undefined = { id: '1' };
const preventDefault = jest.fn();
const stopPropagation = jest.fn();
const setDragging = jest.fn();
const onDrop = jest.fn();
const component = mount(
<ChildDragDropProvider
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/lens/public/drag_drop/drag_drop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,17 @@ const DragDropInner = React.memo(function DragDropInner(
itemsInGroup,
} = props;

const isMoveDragging = isDragging && dragType === 'move';
const classes = classNames(
'lnsDragDrop',
{
'lnsDragDrop-isDraggable': draggable,
'lnsDragDrop-isDragging': isDragging,
'lnsDragDrop-isHidden': isDragging && dragType === 'move',
'lnsDragDrop-isHidden': isMoveDragging,
'lnsDragDrop-isDroppable': !draggable,
'lnsDragDrop-isDropTarget': droppable && dragType !== 'reorder',
'lnsDragDrop-isActiveDropTarget': droppable && state.isActive && dragType !== 'reorder',
'lnsDragDrop-isNotDroppable': isNotDroppable,
'lnsDragDrop-isNotDroppable': !isMoveDragging && isNotDroppable,
'lnsDragDrop-isReplacing': droppable && state.isActive && dropType === 'replace',
},
className,
Expand All @@ -186,6 +187,14 @@ const DragDropInner = React.memo(function DragDropInner(
// Setting stopPropgagation causes Chrome failures, so
// we are manually checking if we've already handled this
// in a nested child, and doing nothing if so...
function clearSelection() {
if (window.getSelection) {
window.getSelection().removeAllRanges();
} else if (document.selection) {
document.selection.empty();
}
}
clearSelection();
if (e.dataTransfer.getData('text')) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,9 @@ describe('LayerPanel', () => {
);

expect(mockDatasource.canHandleDrop).not.toHaveBeenCalled();
const reorderableGroupElement = component.find('DragDrop[data-test-subj="lnsGroup"]').at(1);
reorderableGroupElement?.prop('onDrop')!((draggingOperation as unknown) as DroppableEvent)!;
component.find('DragDrop[data-test-subj="lnsGroup"]').at(1).prop('onDrop')!(
(draggingOperation as unknown) as DroppableEvent
);
expect(mockDatasource.onDrop).toHaveBeenCalledWith(
expect.objectContaining({
isReorder: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
layers: {
myLayer: {
...testState.layers.myLayer,
columnOrder: columnOrder,
columnOrder,
columns: {
...testState.layers.myLayer.columns,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export function onDrop(props: DatasourceDimensionDropHandlerProps<IndexPatternPr
// Time to replace
setState(
mergeLayer({
state: state,
layerId: layerId,
state,
layerId,
newLayer: {
columnOrder: newColumnOrder,
columns: newColumns,
Expand Down Expand Up @@ -163,9 +163,9 @@ export function onDrop(props: DatasourceDimensionDropHandlerProps<IndexPatternPr

setState(
changeColumn({
state: state,
state,
layerId,
columnId: columnId,
columnId,
newColumn,
// If the field has changed, the onFieldChange method needs to take care of everything including moving
// over params. If we create a new column above we want changeColumn to move over params.
Expand Down

0 comments on commit b56f8a3

Please sign in to comment.