-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Enhance URL handling in table by rendering URL column types with…
… `<a>` tag. (#37179) ## Description <ins>Problem</ins> URLs in table were not being rendered as links, resulting in inconsistent user experience(missing context menus. <ins>Root cause</ins> URLs were rendered in `<div>` instead of `<a>`, making the component lack links related features.. <ins>Solution</ins> This PR handles... - Rendering URLs as links in BasicCell for a better user experience. - Adding specific types for column properties for more robust data validation and type checking. - Adding unit tests for BasicCell functionality to ensure accurate rendering and behavior. - Simplifies the AutoToolTipComponent by removing unncessary `LinkWrapper` component Fixes #24769 _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.Table" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11681339029> > Commit: b7c5d17 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11681339029&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Table` > Spec: > <hr>Tue, 05 Nov 2024 10:23:38 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Enhanced type safety for `compactMode` and `columnType` properties across various components. - Improved rendering logic in the `AutoToolTipComponent` for better control based on `columnType`. - Optimized rendering in the `BasicCell` component using `useMemo`. - **Bug Fixes** - Resolved inconsistencies in type definitions for `BasicCell`, `PlainTextCell`, and `SelectCell` components. - Updated tooltip behavior in the `AutoToolTipComponent` to ensure accurate rendering. - **Tests** - Introduced a new test suite for the `BasicCell` component, ensuring proper rendering and interaction behaviors. - Refined test cases for the `AutoToolTipComponent` to verify accurate rendering under various conditions. - Updated test case for URL column verification to check attributes directly instead of navigation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
1 parent
4e18827
commit 0288f5b
Showing
8 changed files
with
120 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from "react"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import { BasicCell, type PropType } from "./BasicCell"; | ||
import { ColumnTypes } from "widgets/TableWidgetV2/constants"; | ||
import { CompactModeTypes } from "widgets/TableWidget/component/Constants"; | ||
|
||
describe("BasicCell Component", () => { | ||
const defaultProps: PropType = { | ||
value: "Test Value", | ||
onEdit: jest.fn(), | ||
isCellEditable: false, | ||
hasUnsavedChanges: false, | ||
columnType: ColumnTypes.TEXT, | ||
url: "", | ||
compactMode: CompactModeTypes.DEFAULT, | ||
isHidden: false, | ||
isCellVisible: true, | ||
accentColor: "", | ||
tableWidth: 100, | ||
disabledEditIcon: false, | ||
disabledEditIconMessage: "", | ||
}; | ||
|
||
it("renders the value", () => { | ||
render(<BasicCell {...defaultProps} />); | ||
expect(screen.getByText("Test Value")).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders a link when columnType is URL", () => { | ||
render( | ||
<BasicCell | ||
{...defaultProps} | ||
columnType={ColumnTypes.URL} | ||
url="http://example.com" | ||
/>, | ||
); | ||
const link = screen.getByText("Test Value"); | ||
|
||
expect(link).toBeInTheDocument(); | ||
expect(link).toHaveAttribute("href", "http://example.com"); | ||
}); | ||
|
||
it("calls onEdit when double-clicked", () => { | ||
render(<BasicCell {...defaultProps} isCellEditable />); | ||
fireEvent.doubleClick(screen.getByText("Test Value")); | ||
expect(defaultProps.onEdit).toHaveBeenCalled(); | ||
}); | ||
|
||
it("forwards ref to the div element", () => { | ||
const ref = React.createRef<HTMLDivElement>(); | ||
|
||
render(<BasicCell {...defaultProps} ref={ref} />); | ||
expect(ref.current).toBeInstanceOf(HTMLDivElement); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters