Skip to content

Commit

Permalink
fix(sqllab): Have table name tooltip only show when name is truncated (
Browse files Browse the repository at this point in the history
…#17386)

* Add conditional to table name tooltip to only show when overflowing

* Remove uneccessary state and useEffect, a little clean up and slight refactoring

Co-authored-by: Corbin Robb <corbin@Corbins-MacBook-Pro.local>
  • Loading branch information
2 people authored and AAfghahi committed Jan 10, 2022
1 parent 7bd477a commit 5118395
Showing 1 changed file with 42 additions and 30 deletions.
72 changes: 42 additions & 30 deletions superset-frontend/src/SqlLab/components/TableElement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const Fade = styled.div`
const TableElement = ({ table, actions, ...props }: TableElementProps) => {
const [sortColumns, setSortColumns] = useState(false);
const [hovered, setHovered] = useState(false);
const tableNameRef = React.useRef<HTMLInputElement>(null);

const setHover = (hovered: boolean) => {
debounce(() => setHovered(hovered), 100)();
Expand Down Expand Up @@ -213,39 +214,50 @@ const TableElement = ({ table, actions, ...props }: TableElementProps) => {
);
};

const renderHeader = () => (
<div
className="clearfix header-container"
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
>
<Tooltip
id="copy-to-clipboard-tooltip"
placement="topLeft"
style={{ cursor: 'pointer' }}
title={table.name}
trigger={['hover']}
>
<StyledSpan data-test="collapse" className="table-name">
<strong>{table.name}</strong>
</StyledSpan>
</Tooltip>
const renderHeader = () => {
const element: HTMLInputElement | null = tableNameRef.current;
let trigger: string[] = [];
if (element && element.offsetWidth < element.scrollWidth) {
trigger = ['hover'];
}

<div className="pull-right header-right-side">
{table.isMetadataLoading || table.isExtraMetadataLoading ? (
<Loading position="inline" />
) : (
<Fade
data-test="fade"
hovered={hovered}
onClick={e => e.stopPropagation()}
return (
<div
className="clearfix header-container"
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
>
<Tooltip
id="copy-to-clipboard-tooltip"
style={{ cursor: 'pointer' }}
title={table.name}
trigger={trigger}
>
<StyledSpan
data-test="collapse"
ref={tableNameRef}
className="table-name"
>
{renderControls()}
</Fade>
)}
<strong>{table.name}</strong>
</StyledSpan>
</Tooltip>

<div className="pull-right header-right-side">
{table.isMetadataLoading || table.isExtraMetadataLoading ? (
<Loading position="inline" />
) : (
<Fade
data-test="fade"
hovered={hovered}
onClick={e => e.stopPropagation()}
>
{renderControls()}
</Fade>
)}
</div>
</div>
</div>
);
);
};

const renderBody = () => {
let cols;
Expand Down

0 comments on commit 5118395

Please sign in to comment.