Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪟 ⏪ Revert show text overflow on hover PR + remove its usage #22200

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ $large: 200px;
.tableCell {
flex: 1 0 $medium;
min-width: $medium;

[data-type="text"] {
word-break: break-word;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
word-break: break-word;
overflow: hidden;
text-overflow: ellipsis;

&.xsmall {
flex-basis: $xsmall;
Expand All @@ -29,11 +25,3 @@ $large: 200px;
min-width: $large;
}
}

.noEllipsis > * {
overflow: visible;
}

.fullWidthTooltip {
max-width: none;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import classNames from "classnames";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { useWindowSize } from "react-use";

import { Tooltip } from "components/ui/Tooltip";
import React from "react";

import styles from "./CatalogTreeTableCell.module.scss";

Expand All @@ -11,7 +8,6 @@ type Sizes = "xsmall" | "small" | "medium" | "large";
interface CatalogTreeTableCellProps {
size?: Sizes;
className?: string;
withTooltip?: boolean;
}

// This lets us avoid the eslint complaint about unused styles
Expand All @@ -22,71 +18,10 @@ const sizeMap: Record<Sizes, string> = {
large: styles.large,
};

const TooltipText: React.FC<{ textNodes: Element[] }> = ({ textNodes }) => {
if (!textNodes.length) {
return null;
}
const text = textNodes.map((t) => decodeURIComponent(t.innerHTML)).join(" | ");
// This is not a safe use, and need to be removed still.
// https://github.com/airbytehq/airbyte/issues/22196
// eslint-disable-next-line react/no-danger
return <div dangerouslySetInnerHTML={{ __html: text }} />;
};

export const CatalogTreeTableCell: React.FC<React.PropsWithChildren<CatalogTreeTableCellProps>> = ({
size = "medium",
withTooltip,
className,
children,
}) => {
const [tooltipDisabled, setTooltipDisabled] = useState(true);
const [textNodes, setTextNodes] = useState<Element[]>([]);
const cell = useRef<HTMLDivElement | null>(null);

const { width: windowWidth } = useWindowSize();

const getTextNodes = useCallback(() => {
if (withTooltip && cell.current) {
setTextNodes(Array.from(cell.current.querySelectorAll(`[data-type="text"]`)));
}
}, [withTooltip]);

useEffect(() => {
// windowWidth is only here so this functionality changes based on window width
if (textNodes.length && windowWidth) {
const [scrollWidths, clientWidths] = textNodes.reduce(
([scrollWidths, clientWidths], textNode) => {
if (textNode) {
scrollWidths += textNode.scrollWidth;
clientWidths += textNode.clientWidth;
}
return [scrollWidths, clientWidths];
},
[0, 0]
);

if (scrollWidths > clientWidths) {
setTooltipDisabled(false);
} else {
setTooltipDisabled(true);
}
}
}, [textNodes, windowWidth]);

return (
<div ref={cell} className={classNames(styles.tableCell, className, sizeMap[size])} onMouseEnter={getTextNodes}>
{withTooltip ? (
<Tooltip
className={classNames(styles.noEllipsis, styles.fullWidthTooltip)}
control={children}
placement="bottom-start"
disabled={tooltipDisabled}
>
<TooltipText textNodes={textNodes} />
</Tooltip>
) : (
children
)}
</div>
);
return <div className={classNames(styles.tableCell, className, sizeMap[size])}>{children}</div>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ export const CatalogTreeTableRow: React.FC<StreamHeaderProps> = ({
<Switch size="sm" checked={stream.config?.selected} onChange={onSelectStream} disabled={disabled} />
</CatalogTreeTableCell>
{/* <Cell>{fieldCount}</Cell> */}
<CatalogTreeTableCell withTooltip>
<CatalogTreeTableCell>
<Text size="md" className={styles.cellText}>
{stream.stream?.namespace || <FormattedMessage id="form.noNamespace" />}
</Text>
</CatalogTreeTableCell>
<CatalogTreeTableCell withTooltip>
<CatalogTreeTableCell>
<Text size="md" className={styles.cellText}>
{stream.stream?.name}
</Text>
Expand Down Expand Up @@ -104,7 +104,7 @@ export const CatalogTreeTableRow: React.FC<StreamHeaderProps> = ({
/>
)}
</CatalogTreeTableCell>
<CatalogTreeTableCell withTooltip={pkType === "sourceDefined"}>
<CatalogTreeTableCell>
{pkType && (
<StreamPathSelect
pathType={pkType}
Expand All @@ -120,12 +120,12 @@ export const CatalogTreeTableRow: React.FC<StreamHeaderProps> = ({
<CatalogTreeTableCell size="xsmall">
<ArrowRightIcon />
</CatalogTreeTableCell>
<CatalogTreeTableCell withTooltip>
<CatalogTreeTableCell>
<Text size="md" className={styles.cellText}>
{destNamespace}
</Text>
</CatalogTreeTableCell>
<CatalogTreeTableCell withTooltip>
<CatalogTreeTableCell>
<Text size="md" className={styles.cellText}>
{destName}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { CursorCell } from "./CursorCell";
import { PKCell } from "./PKCell";
import styles from "./StreamFieldsTable.module.scss";
import { SyncFieldCell } from "./SyncFieldCell";
import { CatalogTreeTableCell } from "../../CatalogTreeTableCell";

export interface TableStream {
field: SyncSchemaField;
Expand Down Expand Up @@ -157,11 +156,7 @@ export const StreamFieldsTable: React.FC<StreamFieldsTableProps> = ({
columnHelper.accessor("path", {
id: "sourcePath",
header: () => <FormattedMessage id="form.field.name" />,
cell: ({ getValue }) => (
<CatalogTreeTableCell size="small" withTooltip>
<Text size="sm">{pathDisplayName(getValue())}</Text>
</CatalogTreeTableCell>
),
cell: ({ getValue }) => <Text size="sm">{pathDisplayName(getValue())}</Text>,
meta: {
thClassName: styles.headerCell,
tdClassName: styles.textCell,
Expand Down Expand Up @@ -239,11 +234,7 @@ export const StreamFieldsTable: React.FC<StreamFieldsTableProps> = ({
columnHelper.accessor("path", {
id: "destinationPath",
header: () => <FormattedMessage id="form.field.name" />,
cell: ({ getValue }) => (
<CatalogTreeTableCell size="small" withTooltip>
<Text size="sm">{pathDisplayName(getValue())}</Text>
</CatalogTreeTableCell>
),
cell: ({ getValue }) => <Text size="sm">{pathDisplayName(getValue())}</Text>,
meta: {
thClassName: styles.headerCell,
tdClassName: styles.textCell,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ exports[`<BulkEditPanel /> should render 1`] = `
>
<span
class="<removed-for-snapshot-test>"
data-type="text"
/>
</div>
<svg
Expand Down Expand Up @@ -147,7 +146,6 @@ exports[`<BulkEditPanel /> should render 1`] = `
>
<span
class="<removed-for-snapshot-test>"
data-type="text"
>
Not available
</span>
Expand Down Expand Up @@ -212,7 +210,6 @@ exports[`<BulkEditPanel /> should render 1`] = `
>
<span
class="<removed-for-snapshot-test>"
data-type="text"
>
Not available
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ exports[`SchemaChangesBackdrop renders with breaking changes and prevents backgr
</div>
<p
class="text md text"
data-type="text"
>
Please review the schema updates before making changes to the connection
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ exports[`CreateConnectionForm should render 1`] = `
</span>
<p
class="<removed-for-snapshot-test>"
data-type="text"
>
Optional
</p>
Expand Down Expand Up @@ -1195,13 +1194,11 @@ exports[`CreateConnectionForm should render with an error 1`] = `
</div>
<p
class="<removed-for-snapshot-test>"
data-type="text"
>
Failed to fetch schema. Please try again
</p>
<p
class="<removed-for-snapshot-test>"
data-type="text"
>
Error: Test Error
</p>
Expand Down
1 change: 0 additions & 1 deletion airbyte-webapp/src/components/ui/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const Text: React.FC<React.PropsWithChildren<TextProps>> = React.memo(

return React.createElement(as, {
...remainingProps,
"data-type": "text",
className,
children,
});
Expand Down
15 changes: 7 additions & 8 deletions airbyte-webapp/src/components/ui/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jsx-a11y/mouse-events-have-key-events */
import { autoUpdate, flip, offset, shift, useFloating, UseFloatingProps } from "@floating-ui/react-dom";
import classNames from "classnames";
import React, { useState, useEffect, useMemo } from "react";
import React, { useState, useEffect } from "react";
import { createPortal } from "react-dom";

import { tooltipContext } from "./context";
Expand Down Expand Up @@ -54,7 +54,7 @@ export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = (props)
};
}, [isMouseOver]);

const canShowTooltip = useMemo(() => isVisible && !disabled, [disabled, isVisible]);
const canShowTooltip = isVisible && !disabled;

const onMouseOver = () => {
setIsMouseOver(true);
Expand All @@ -75,8 +75,8 @@ export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = (props)
>
{control}
</span>
{createPortal(
canShowTooltip ? (
{canShowTooltip &&
createPortal(
<div
role="tooltip"
ref={floating}
Expand All @@ -96,10 +96,9 @@ export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = (props)
onMouseOut={onMouseOut}
>
<tooltipContext.Provider value={props}>{children}</tooltipContext.Provider>
</div>
) : null,
document.body
)}
</div>,
document.body
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ exports[`ConnectionReplicationPage should render 1`] = `
</span>
<p
class="<removed-for-snapshot-test>"
data-type="text"
>
Optional
</p>
Expand Down Expand Up @@ -1006,7 +1005,6 @@ exports[`ConnectionReplicationPage should show an error if there is a schemaErro
</div>
<p
class="<removed-for-snapshot-test>"
data-type="text"
>
Failed to fetch schema. Please try again
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ exports[`<mockFrequentlyUsedConnectors /> should renders with mock data without
>
<p
class="<removed-for-snapshot-test>"
data-type="text"
>
Most frequently used destinations
</p>
Expand Down