Skip to content

Commit

Permalink
[Lens] Drag and drop info bottom bar POC implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Feb 18, 2021
1 parent 2e67967 commit 5934d8b
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugins/lens/public/drag_drop/drag_drop.scss
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,8 @@
}
}
}

.lnsDragDrop-bottomBar {
text-align: center;
font-weight: $euiFontWeightBold;
}
77 changes: 77 additions & 0 deletions x-pack/plugins/lens/public/drag_drop/providers/bottom_bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { EuiBottomBar } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { DropIdentifier, DraggingIdentifier } from './types';

interface BottomBarProps {
dragging: DraggingIdentifier;
activeDropTarget?: DropIdentifier;
}

const DEFAULT_DRAGGING_MESSAGE = i18n.translate('xpack.lens.dragDrop.bottomBar.dragging', {
defaultMessage: `Drop a configuration to replace an existing one or add to a different dimension. (This copy doesn't say anything about reordering)`,
});

const REPLACE_INCOMPATIBLE_MESSAGE = i18n.translate(
'xpack.lens.dragDrop.bottomBar.replaceIncompatible',
{
defaultMessage: `A partial replace can only keep the field, not the function.`,
}
);

const MOVE_INCOMPATIBLE_MESSAGE = i18n.translate('xpack.lens.dragDrop.bottomBar.moveIncompatible', {
defaultMessage: `A partial move can only keep the field, not the function.`,
});

const MOVE_COMPATIBLE_MESSAGE = i18n.translate('xpack.lens.dragDrop.bottomBar.moveCompatible', {
defaultMessage: `Drop to move to new dimension.`,
});

const REPLACE_COMPATIBLE_MESSAGE = i18n.translate(
'xpack.lens.dragDrop.bottomBar.replaceCompatible',
{
defaultMessage: `Drop to replace the existing dimension.`,
}
);

const REORDER_MESSAGE = i18n.translate('xpack.lens.dragDrop.bottomBar.reorder', {
defaultMessage: `Drop to reorder.`,
});
const DUPLICATE_INGROUP_MESSAGE = i18n.translate('xpack.lens.dragDrop.bottomBar.duplicateInGroup', {
defaultMessage: `Drop to duplicate.`,
});

const getMessage = ({ activeDropTarget }: BottomBarProps) => {
if (activeDropTarget) {
switch (activeDropTarget.dropType) {
case 'replace_incompatible':
return REPLACE_INCOMPATIBLE_MESSAGE;
case 'move_incompatible':
return MOVE_INCOMPATIBLE_MESSAGE;
case 'move_compatible':
return MOVE_COMPATIBLE_MESSAGE;
case 'replace_compatible':
return REPLACE_COMPATIBLE_MESSAGE;
case 'reorder':
return REORDER_MESSAGE;
case 'duplicate_in_group':
return DUPLICATE_INGROUP_MESSAGE;
}
}
return DEFAULT_DRAGGING_MESSAGE;
};

export const BottomBar = ({ dragging, activeDropTarget }: BottomBarProps) => {
return (
<EuiBottomBar className="lnsDragDrop-bottomBar" paddingSize="m">
<span>{getMessage({ dragging, activeDropTarget })}</span>
</EuiBottomBar>
);
};
4 changes: 4 additions & 0 deletions x-pack/plugins/lens/public/drag_drop/providers/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React, { useState, useMemo } from 'react';
import { EuiScreenReaderOnly, EuiPortal } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { BottomBar } from './bottom_bar';
import {
DropIdentifier,
DraggingIdentifier,
Expand Down Expand Up @@ -122,6 +123,9 @@ export function RootDragDropProvider({ children }: { children: React.ReactNode }
</div>
</EuiScreenReaderOnly>
</EuiPortal>
{draggingState.dragging?.humanData.showBarOnDrag && (
<BottomBar dragging={draggingState.dragging} activeDropTarget={activeDropTargetState} />
)}
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/lens/public/drag_drop/providers/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface HumanData {
groupLabel?: string;
position?: number;
nextLabel?: string;
showBarOnDrag?: boolean;
}

export type DragDropIdentifier = Record<string, unknown> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function DraggableDimensionButton({
groupLabel: group.groupLabel,
position: accessorIndex + 1,
nextLabel: nextLabel || '',
showBarOnDrag: true,
},
}),
[columnId, group.groupId, accessorIndex, layerId, dropType, label, group.groupLabel, nextLabel]
Expand Down

0 comments on commit 5934d8b

Please sign in to comment.