From a1e18ed11079d9d06a141d537f01ad1c31eb6a48 Mon Sep 17 00:00:00 2001 From: Geido <60598000+geido@users.noreply.github.com> Date: Thu, 12 Aug 2021 19:48:16 +0200 Subject: [PATCH] fix(Explore): Show the tooltip only when label does not fit the container in METRICS/FILTERS/GROUP BY/SORT BY of the DATA panel (#16060) * Implement dynamic tooltip * Normalize and consolidate * Clean up * Refactor and clean up * Remove unnecessary var * Fix type import * Update superset-frontend/src/explore/components/controls/OptionControls/index.tsx Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> * Remove unnecessary styled span * Show full tooltip title * Force show tooltip * Force show tooltip D&D off Co-authored-by: Ville Brofeldt Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> --- .../DndColumnSelect.tsx | 6 +- .../DndFilterSelect.tsx | 8 +-- .../OptionWrapper.test.tsx | 15 ++--- .../DndColumnSelectControl/OptionWrapper.tsx | 65 ++++++++++++++++++- .../controls/DndColumnSelectControl/types.ts | 5 +- .../controls/OptionControls/index.tsx | 42 ++++++++++-- .../explore/components/optionRenderers.tsx | 1 + 7 files changed, 115 insertions(+), 27 deletions(-) diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndColumnSelect.tsx b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndColumnSelect.tsx index 46b3889fdd68..788b4e27cc77 100644 --- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndColumnSelect.tsx +++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndColumnSelect.tsx @@ -26,7 +26,6 @@ import OptionWrapper from 'src/explore/components/controls/DndColumnSelectContro import { OptionSelector } from 'src/explore/components/controls/DndColumnSelectControl/utils'; import { DatasourcePanelDndItem } from 'src/explore/components/DatasourcePanel/types'; import { DndItemType } from 'src/explore/components/DndItemType'; -import { StyledColumnOption } from 'src/explore/components/optionRenderers'; import { useComponentDidUpdate } from 'src/common/hooks/useComponentDidUpdate'; export const DndColumnSelect = (props: LabelProps) => { @@ -121,9 +120,8 @@ export const DndColumnSelect = (props: LabelProps) => { onShiftOptions={onShiftOptions} type={`${DndItemType.ColumnOption}_${name}_${label}`} canDelete={canDelete} - > - - + column={column} + /> )), [ canDelete, diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx index 66849b2d1f50..1e2eba8a6b0b 100644 --- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx +++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx @@ -26,7 +26,6 @@ import { t, } from '@superset-ui/core'; import { ColumnMeta } from '@superset-ui/chart-controls'; -import { Tooltip } from 'src/components/Tooltip'; import { OPERATOR_ENUM_TO_OPERATOR_TYPE, Operators, @@ -299,6 +298,7 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => { () => values.map((adhocFilter: AdhocFilter, index: number) => { const label = adhocFilter.getDefaultLabel(); + const tooltipTitle = adhocFilter.getTooltipTitle(); return ( { - {label} - + /> ); }), diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.test.tsx b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.test.tsx index c46f49be0107..e237cea989a5 100644 --- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.test.tsx +++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.test.tsx @@ -28,9 +28,8 @@ test('renders with default props', () => { clickClose={jest.fn()} type={'Column' as DndItemType} onShiftOptions={jest.fn()} - > - Option - , + label="Option" + />, { useDnd: true }, ); expect(container).toBeInTheDocument(); @@ -46,17 +45,15 @@ test('triggers onShiftOptions on drop', () => { clickClose={jest.fn()} type={'Column' as DndItemType} onShiftOptions={onShiftOptions} - > - Option 1 - + label="Option 1" + /> - Option 2 - + label="Option 2" + /> , { useDnd: true }, ); diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.tsx b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.tsx index d624817de3c4..485919099069 100644 --- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.tsx +++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.tsx @@ -28,8 +28,19 @@ import { OptionProps, OptionItemInterface, } from 'src/explore/components/controls/DndColumnSelectControl/types'; +import { Tooltip } from 'src/components/Tooltip'; +import { StyledColumnOption } from 'src/explore/components/optionRenderers'; +import { styled } from '@superset-ui/core'; +import { ColumnMeta } from '@superset-ui/chart-controls'; import Option from './Option'; +export const OptionLabel = styled.div` + width: 100%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +`; + export default function OptionWrapper( props: OptionProps & { type: string; @@ -38,16 +49,19 @@ export default function OptionWrapper( ) { const { index, + label, + tooltipTitle, + column, type, onShiftOptions, clickClose, withCaret, isExtra, canDelete = true, - children, ...rest } = props; const ref = useRef(null); + const labelRef = useRef(null); const item: OptionItemInterface = useMemo( () => ({ @@ -56,7 +70,7 @@ export default function OptionWrapper( }), [index, type], ); - const [, drag] = useDrag({ + const [{ isDragging }, drag] = useDrag({ item, collect: (monitor: DragSourceMonitor) => ({ isDragging: monitor.isDragging(), @@ -107,6 +121,51 @@ export default function OptionWrapper( }, }); + const shouldShowTooltip = + (!isDragging && tooltipTitle && label && tooltipTitle !== label) || + (!isDragging && + labelRef && + labelRef.current && + labelRef.current.scrollWidth > labelRef.current.clientWidth); + + const LabelContent = () => { + if (!shouldShowTooltip) { + return {label}; + } + return ( + + {label} + + ); + }; + + const ColumnOption = () => ( + + ); + + const Label = () => { + if (label) { + return ( + + + + ); + } + if (column) { + return ( + + + + ); + } + return null; + }; + drag(drop(ref)); return ( @@ -118,7 +177,7 @@ export default function OptionWrapper( isExtra={isExtra} canDelete={canDelete} > - {children} +