Skip to content

Commit

Permalink
Add conditional to table name tooltip to only show when overflowing
Browse files Browse the repository at this point in the history
  • Loading branch information
Corbin Robb authored and Corbin Robb committed Nov 9, 2021
1 parent 561d1ac commit 20b7391
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions superset-frontend/src/SqlLab/components/TableElement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import Collapse from 'src/components/Collapse';
import Card from 'src/components/Card';
import ButtonGroup from 'src/components/ButtonGroup';
Expand Down Expand Up @@ -77,6 +77,15 @@ const Fade = styled.div`
const TableElement = ({ table, actions, ...props }: TableElementProps) => {
const [sortColumns, setSortColumns] = useState(false);
const [hovered, setHovered] = useState(false);
const [tableNameOverflow, setTableNameOverflow] = useState(false);
const tableNameRef = React.useRef<HTMLInputElement>(null);

useEffect(() => {
const element = tableNameRef.current;
if (element && element.offsetWidth < element.scrollWidth) {
setTableNameOverflow(true);
}
}, []);

const setHover = (hovered: boolean) => {
debounce(() => setHovered(hovered), 100)();
Expand Down Expand Up @@ -221,12 +230,15 @@ const TableElement = ({ table, actions, ...props }: TableElementProps) => {
>
<Tooltip
id="copy-to-clipboard-tooltip"
placement="topLeft"
style={{ cursor: 'pointer' }}
title={table.name}
trigger={['hover']}
trigger={tableNameOverflow ? ['hover'] : []}
>
<StyledSpan data-test="collapse" className="table-name">
<StyledSpan
data-test="collapse"
ref={tableNameRef}
className="table-name"
>
<strong>{table.name}</strong>
</StyledSpan>
</Tooltip>
Expand Down

0 comments on commit 20b7391

Please sign in to comment.