Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9b27dfc
fix:- added elipsis and tooltip to the button content in table widget…
skjameela Oct 14, 2024
b1ebb20
Merge remote-tracking branch 'contributor-fork/fix/button-tooltip-in-…
rahulbarwal Oct 17, 2024
48d92df
resolved review comments
skjameela Oct 21, 2024
92a26c9
resolved review comments for button tooltip
skjameela Oct 21, 2024
f35baf7
Merge branch 'fix/button-tooltip-in-table_widgetV2' of https://github…
rahulbarwal Oct 22, 2024
dd9b0b4
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Oct 22, 2024
8ffde6e
resolved the prettier and linting issues
skjameela Oct 22, 2024
f1be30b
Merge branch 'fix/button-tooltip-in-table_widgetV2' of https://github…
rahulbarwal Oct 23, 2024
39d624e
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Oct 23, 2024
8f9d8d8
resolved review comments and added test cases
skjameela Oct 24, 2024
4798350
removed duplicate test cases
skjameela Oct 24, 2024
fa303f9
Resolved merge conflict in AutoTooltipComponent.test.tsx
skjameela Oct 24, 2024
7afdc68
Merge branch 'fix/button-tooltip-in-table_widgetV2' of https://github…
rahulbarwal Oct 25, 2024
cd9a5b0
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Oct 25, 2024
af3c8c4
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Oct 25, 2024
36bfa53
resolved linting and prettier issues
skjameela Oct 28, 2024
79e485c
Merge branch 'fix/button-tooltip-in-table_widgetV2' of https://github…
rahulbarwal Oct 28, 2024
0f11e80
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Oct 28, 2024
6696227
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Oct 29, 2024
44de49c
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Oct 30, 2024
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 @@ -473,6 +473,7 @@ export const MenuColumnWrapper = styled.div<{ selected: boolean }>`

export const ActionWrapper = styled.div<{ disabled: boolean }>`
margin: 0 5px 0 0;
max-width: 100%;
${(props) => (props.disabled ? "cursor: not-allowed;" : null)}
&&&&&& {
.bp3-button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,63 @@ const MAX_WIDTH = 500;
const TOOLTIP_OPEN_DELAY = 500;
const MAX_CHARS_ALLOWED_IN_TOOLTIP = 200;

function useToolTip(children: React.ReactNode, title?: string) {
function isButtonTextTruncated(element: HTMLElement) {
const spanElement = element.querySelector("span");
const offsetWidth = spanElement?.offsetWidth ?? 0;
const scrollWidth = spanElement?.scrollWidth ?? 0;

return scrollWidth > offsetWidth;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Check for null spanElement before accessing properties

If spanElement is null, accessing its properties will cause an error.

Apply this diff to handle the null case:

function isButtonTextTruncated(element: HTMLElement) {
  const spanElement = element.querySelector("span");
+ if (!spanElement) return false;
  const offsetWidth = spanElement.offsetWidth;
  const scrollWidth = spanElement.scrollWidth;
  return scrollWidth > offsetWidth;
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function isButtonTextTruncated(element: HTMLElement) {
const spanElement = element.querySelector("span");
const offsetWidth = spanElement?.offsetWidth ?? 0;
const scrollWidth = spanElement?.scrollWidth ?? 0;
return scrollWidth > offsetWidth;
}
function isButtonTextTruncated(element: HTMLElement) {
const spanElement = element.querySelector("span");
if (!spanElement) return false;
const offsetWidth = spanElement.offsetWidth;
const scrollWidth = spanElement.scrollWidth;
return scrollWidth > offsetWidth;
}


function useToolTip(
children: React.ReactNode,
title?: string,
isButton?: boolean,
) {
const ref = createRef<HTMLDivElement>();
const [requiresTooltip, setRequiresTooltip] = useState(false);

useEffect(() => {
let timeout: ReturnType<typeof setTimeout>;
const currentRef = ref.current;

const mouseEnterHandler = () => {
const element = ref.current?.querySelector("div") as HTMLDivElement;
if (!currentRef) return;

/*
* Using setTimeout to simulate hoverOpenDelay of the tooltip
* during initial render
*/
const mouseEnterHandler = () => {
timeout = setTimeout(() => {
const element = currentRef?.querySelector("div") as HTMLDivElement;

/*
* Using setTimeout to simulate hoverOpenDelay of the tooltip
* during initial render
*/
if (element && element.offsetWidth < element.scrollWidth) {
setRequiresTooltip(true);
} else if (isButton && element && isButtonTextTruncated(element)) {
setRequiresTooltip(true);
} else {
setRequiresTooltip(false);
}

ref.current?.removeEventListener("mouseenter", mouseEnterHandler);
ref.current?.removeEventListener("mouseleave", mouseLeaveHandler);
currentRef?.removeEventListener("mouseenter", mouseEnterHandler);
currentRef?.removeEventListener("mouseleave", mouseLeaveHandler);
}, TOOLTIP_OPEN_DELAY);
};

const mouseLeaveHandler = () => {
setRequiresTooltip(false);
clearTimeout(timeout);
};

ref.current?.addEventListener("mouseenter", mouseEnterHandler);
ref.current?.addEventListener("mouseleave", mouseLeaveHandler);
currentRef?.addEventListener("mouseenter", mouseEnterHandler);
currentRef?.addEventListener("mouseleave", mouseLeaveHandler);

return () => {
ref.current?.removeEventListener("mouseenter", mouseEnterHandler);
ref.current?.removeEventListener("mouseleave", mouseLeaveHandler);
currentRef?.removeEventListener("mouseenter", mouseEnterHandler);
currentRef?.removeEventListener("mouseleave", mouseLeaveHandler);
clearTimeout(timeout);
};
}, [children]);
}, [children,isButton]);

return requiresTooltip && children ? (
<Tooltip
Expand Down Expand Up @@ -165,6 +183,11 @@ function AutoToolTipComponent(props: Props) {
return <LinkWrapper {...props} />;
}

if (props.columnType === ColumnTypes.BUTTON && props.title) {
const buttonContent = useToolTip(props.children, props.title, true);
return buttonContent;
}

return (
<ColumnWrapper className={props.className} textColor={props.textColor}>
<CellWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import React, { useState } from "react";

import { ActionWrapper } from "../TableStyledWrappers";
import { BaseButton } from "widgets/ButtonWidget/component";
import type { ButtonColumnActions } from "widgets/TableWidgetV2/constants";
import {
ColumnTypes,
type ButtonColumnActions,
} from "widgets/TableWidgetV2/constants";
import styled from "styled-components";
import AutoToolTipComponent from "widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent";

const StyledButton = styled(BaseButton)<{
compactMode?: string;
Expand Down Expand Up @@ -39,12 +43,16 @@ export function Button(props: ButtonProps) {

return (
<ActionWrapper
disabled={!!props.isDisabled}
onClick={(e) => {
e.stopPropagation();
}}
>
{props.isCellVisible && props.action.isVisible ? (
disabled={!!props.isDisabled}
onClick={(e) => {
e.stopPropagation();
}}
>
{props.isCellVisible && props.action.isVisible && props.action.label ? (
<AutoToolTipComponent
columnType={ColumnTypes.BUTTON}
title={props.action.label}
>
<StyledButton
borderRadius={props.action.borderRadius}
boxShadow={props.action.boxShadow}
Expand All @@ -58,7 +66,9 @@ export function Button(props: ButtonProps) {
onClick={handleClick}
text={props.action.label}
/>
) : null}
</ActionWrapper>
</AutoToolTipComponent>
)
: null}
</ActionWrapper>
);
}