Skip to content

Commit

Permalink
Merge branch 'lens/dnd-design' of github.com:cchaos/kibana into lens-…
Browse files Browse the repository at this point in the history
…dnd-design
  • Loading branch information
wylieconlon committed Sep 30, 2020
2 parents f59b0ed + a6c954e commit ff803d3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/lens/public/drag_drop/drag_drop.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import '../variables';
@import '../mixins';

.lnsDragDrop {
Expand Down
17 changes: 13 additions & 4 deletions x-pack/plugins/lens/public/drag_drop/drag_drop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ interface BaseProps {
*/
value?: unknown;

/**
* Optional comparison function to check whether a value is the dragged one
*/
isValueEqual?: (value1: unknown, value2: unknown) => boolean;

/**
* The React element which will be passed the draggable handlers
*/
Expand Down Expand Up @@ -110,12 +115,14 @@ type Props = DraggableProps | NonDraggableProps;

export const DragDrop = (props: Props) => {
const { dragging, setDragging } = useContext(DragContext);
const { value, draggable, droppable } = props;
const { value, draggable, droppable, isValueEqual } = props;
return (
<DragDropInner
{...props}
dragging={droppable ? dragging : undefined}
isDragging={!!(draggable && value === dragging)}
isDragging={
!!(draggable && ((isValueEqual && isValueEqual(value, dragging)) || value === dragging))
}
isNotDroppable={
// If the configuration has provided a droppable flag, but this particular item is not
// droppable, then it should be less prominent. Ignores items that are both
Expand Down Expand Up @@ -154,16 +161,18 @@ const DragDropInner = React.memo(function DragDropInner(
dropType = 'add',
} = 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,
'lnsDragDrop-isActiveDropTarget': droppable && state.isActive,
'lnsDragDrop-isNotDroppable': isNotDroppable,
'lnsDragDrop-isNotDroppable': !isMoveDragging && isNotDroppable,
'lnsDragDrop-isReplacing': droppable && state.isActive && dropType === 'replace',
},
className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ const initialDimensionContainerState = {
addingToGroupId: null,
};

function isConfiguration(
value: unknown
): value is { columnId: string; groupId: string; layerId: string } {
return (
value &&
typeof value === 'object' &&
'columnId' in value &&
'groupId' in value &&
'layerId' in value
);
}

function isSameConfiguration(config1: unknown, config2: unknown) {
return (
isConfiguration(config1) &&
isConfiguration(config2) &&
config1.columnId === config2.columnId &&
config1.groupId === config2.groupId &&
config1.layerId === config2.layerId
);
}

export function LayerPanel(
props: Exclude<ConfigPanelWrapperProps, 'state' | 'setState'> & {
layerId: string;
Expand Down Expand Up @@ -217,6 +239,7 @@ export function LayerPanel(
data-test-subj={group.dataTestSubj}
draggable={!dimensionContainerState.isOpen}
value={{ columnId: accessor, groupId: group.groupId, layerId }}
isValueEqual={isSameConfiguration}
label={group.groupLabel}
droppable={
Boolean(dragDropContext.dragging) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

.lnsInnerIndexPatternDataPanel__fieldItems {
// Quick fix for making sure the shadow and focus rings are visible outside the accordion bounds
padding: $euiSizeXS $euiSizeXS 0;
padding: $euiSizeXS;
}

.lnsInnerIndexPatternDataPanel__textField {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const InnerFieldItem = function InnerFieldItem(props: FieldItemProps) {
ownFocus
className="lnsFieldItem__popoverAnchor"
display="block"
data-test-sub="lnsFieldListPanelField"
data-test-subj="lnsFieldListPanelField"
container={document.querySelector<HTMLElement>('.application') || undefined}
button={
<DragDrop
Expand Down Expand Up @@ -514,7 +514,7 @@ function FieldItemPopoverContents(props: State & FieldItemProps) {
</EuiFlexItem>

<EuiFlexItem grow={false} className="eui-textTruncate">
<EuiText size="s" color="subdued">
<EuiText size="xs" color="subdued">
{Math.round((otherCount / props.sampledValues!) * 100)}%
</EuiText>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ export const DraggableBucketContainer = ({
children: React.ReactNode;
} & BucketContainerProps) => {
return (
<EuiDraggable spacing="m" index={idx} draggableId={id} disableInteractiveElementBlocking>
<EuiDraggable
style={{ marginBottom: 4 }}
spacing="none"
index={idx}
draggableId={id}
disableInteractiveElementBlocking
>
{(provided) => <BucketContainer {...bucketContainerProps}>{children}</BucketContainer>}
</EuiDraggable>
);
Expand Down Expand Up @@ -134,7 +140,7 @@ export const DragDropBuckets = ({
};
return (
<EuiDragDropContext onDragEnd={handleDragEnd} onDragStart={onDragStart}>
<EuiDroppable droppableId={droppableId} spacing="s">
<EuiDroppable droppableId={droppableId} spacing="none">
{children}
</EuiDroppable>
</EuiDragDropContext>
Expand Down

0 comments on commit ff803d3

Please sign in to comment.