Skip to content

Commit

Permalink
Remove uneccessary state and useEffect, a little clean up and slight …
Browse files Browse the repository at this point in the history
…refactoring
  • Loading branch information
Corbin Robb authored and Corbin Robb committed Nov 10, 2021
1 parent 20b7391 commit 218961d
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 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, useEffect } from 'react';
import React, { useState } 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,16 +77,8 @@ 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 @@ -222,42 +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"
style={{ cursor: 'pointer' }}
title={table.name}
trigger={tableNameOverflow ? ['hover'] : []}
const renderHeader = () => {
const element: HTMLInputElement | null = tableNameRef.current;
let trigger: string[] = [];
if (element && element.offsetWidth < element.scrollWidth) {
trigger = ['hover'];
}

return (
<div
className="clearfix header-container"
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
>
<StyledSpan
data-test="collapse"
ref={tableNameRef}
className="table-name"
<Tooltip
id="copy-to-clipboard-tooltip"
style={{ cursor: 'pointer' }}
title={table.name}
trigger={trigger}
>
<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()}
<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 218961d

Please sign in to comment.