From 51183955a40288fded98baf1032e12e9edfc242c Mon Sep 17 00:00:00 2001 From: Corbin Robb <31329271+corbinrobb@users.noreply.github.com> Date: Fri, 19 Nov 2021 10:34:28 -0700 Subject: [PATCH] fix(sqllab): Have table name tooltip only show when name is truncated (#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 --- .../SqlLab/components/TableElement/index.tsx | 72 +++++++++++-------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/TableElement/index.tsx b/superset-frontend/src/SqlLab/components/TableElement/index.tsx index 4be3935d7a1ce..0d1624d96211d 100644 --- a/superset-frontend/src/SqlLab/components/TableElement/index.tsx +++ b/superset-frontend/src/SqlLab/components/TableElement/index.tsx @@ -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(null); const setHover = (hovered: boolean) => { debounce(() => setHovered(hovered), 100)(); @@ -213,39 +214,50 @@ const TableElement = ({ table, actions, ...props }: TableElementProps) => { ); }; - const renderHeader = () => ( -
setHover(true)} - onMouseLeave={() => setHover(false)} - > - - - {table.name} - - + const renderHeader = () => { + const element: HTMLInputElement | null = tableNameRef.current; + let trigger: string[] = []; + if (element && element.offsetWidth < element.scrollWidth) { + trigger = ['hover']; + } -
- {table.isMetadataLoading || table.isExtraMetadataLoading ? ( - - ) : ( - e.stopPropagation()} + return ( +
setHover(true)} + onMouseLeave={() => setHover(false)} + > + + - {renderControls()} - - )} + {table.name} + + + +
+ {table.isMetadataLoading || table.isExtraMetadataLoading ? ( + + ) : ( + e.stopPropagation()} + > + {renderControls()} + + )} +
-
- ); + ); + }; const renderBody = () => { let cols;