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

feat:[POC] HTML column type support in table #37603

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Nov 20, 2024

Description

Tip

Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR.

Fixes #13681
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=""

🔍 Cypress test results

Warning

Tests have not run on the HEAD cd9422d yet


Mon, 02 Dec 2024 09:42:54 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

Fixes #Issue Number
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=""

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new HTMLCell component for rendering HTML content within table cells.
    • Added support for HTML column types in the table widget, enhancing data representation flexibility.
    • Expanded configuration options to include HTML as a selectable column type.
    • Added a new property control for handling HTML computed values.
  • Bug Fixes

    • Improved column resizing logic to prevent widths from dropping below a minimum threshold.
  • Enhancements

    • Updated rendering logic to accommodate new HTML column types and ensure consistent styling across table cells.
    • Enhanced handling of multiline strings for more robust input processing.

## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes #`Issue Number`  
_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=""

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]  
> If you modify the content in this section, you are likely to disrupt
the CI result for your PR.

<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes in this pull request enhance the TableWidgetV2 component by introducing support for HTML content in table cells. This is achieved through the addition of a new HTMLCell component and modifications to the existing Table.tsx file to accommodate new column type logic. The ColumnTypes enum is updated to include HTML, and the configuration for table columns is expanded to allow for HTML as a selectable type. Additionally, column resizing behavior is refined to ensure minimum widths, improving the overall functionality of the table widget.

Changes

File Path Change Summary
app/client/src/widgets/TableWidgetV2/component/Table.tsx Updated import statements and enhanced logic for column properties, including conditions for virtual rendering and column resizing.
app/client/src/widgets/TableWidgetV2/component/cellComponents/HTMLCell.tsx Introduced new HTMLCell component for rendering HTML content in a table cell, including props for value and font size, using Interweave for safe HTML rendering.
app/client/src/widgets/TableWidgetV2/constants.ts Added new constant HTML to ColumnTypes enum, allowing HTML content in table columns.
app/client/src/widgets/TableWidgetV2/widget/index.tsx Integrated HTMLCell into renderCell method of TableWidgetV2, adding case for ColumnTypes.HTML in the switch statement.
app/client/src/widgets/TableWidgetV2/widget/propertyConfig/PanelConfig/Data.ts Added "HTML" option to columnType configuration, updated hidden conditions for related properties to include ColumnTypes.HTML.
app/client/src/components/propertyControls/HTMLTableComputeValue.tsx Introduced HTMLComputeTablePropertyControl component for handling HTML table properties, extending existing controls with new props.
app/client/src/components/propertyControls/TableComputeValue.tsx Enhanced handling of multiline strings with new utility function normalizedMultilineValue.
app/client/src/components/propertyControls/index.ts Added HTMLComputeTablePropertyControl to the PropertyControls export object, updating the type union for property controls.
app/client/src/components/propertyControls/utils.ts Introduced normalizedMultilineValue utility function for normalizing multiline strings.

Assessment against linked issues

Objective Addressed Explanation
Support HTML as a column type in the table widget (#13681)

Possibly related PRs

Suggested labels

Bug, Production, Medium, ok-to-test, UI Building Product, Help enterprise

Suggested reviewers

  • ApekshaBhosale
  • jacquesikot

"In the table where data flows,
HTML shines, as content grows.
With cells that wrap and styles that gleam,
Our widgets now fulfill the dream!
So raise a toast to code so neat,
In every row, our triumphs meet!" 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rahulbarwal rahulbarwal self-assigned this Nov 20, 2024
@github-actions github-actions bot added Enhancement New feature or request High This issue blocks a user from building or impacts a lot of users Table Widget Table Widget V2 Issues related to Table Widget V2 Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Nov 20, 2024
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11934394632.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37603.
recreate: .

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
app/client/src/widgets/TableWidgetV2/constants.ts (1)

149-149: Consider adding HTML to ReadOnlyColumnTypes

If HTML columns are meant to be read-only (which is typical for security reasons), consider adding the HTML type to the ReadOnlyColumnTypes enum.

Also applies to: 151-161

app/client/src/widgets/TableWidgetV2/component/Table.tsx (1)

333-335: Add documentation for virtual rendering conditions.

The logic correctly disables virtual rendering for HTML columns, but consider adding a comment explaining why HTML columns require static rendering (e.g., variable height content).

  shouldUseVirtual =
    props.serverSidePaginationEnabled &&
    !props.columns.some(
      (column) =>
+       // Disable virtual rendering for wrapped cells and HTML content due to variable heights
        !!column.columnProperties.allowCellWrapping ||
        column.metaProperties?.type === ColumnTypes.HTML,
    );
app/client/src/widgets/TableWidgetV2/component/cellComponents/HTMLCell.tsx (1)

68-68: Remove unused prop 'fontSize' from 'HTMLCellProps'

The 'fontSize' prop is declared but not used in the component. Consider removing it to keep the interface clean.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7b81c3e and c00f3ee.

📒 Files selected for processing (5)
  • app/client/src/widgets/TableWidgetV2/component/Table.tsx (2 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/HTMLCell.tsx (1 hunks)
  • app/client/src/widgets/TableWidgetV2/constants.ts (1 hunks)
  • app/client/src/widgets/TableWidgetV2/widget/index.tsx (2 hunks)
  • app/client/src/widgets/TableWidgetV2/widget/propertyConfig/PanelConfig/Data.ts (2 hunks)
🔇 Additional comments (7)
app/client/src/widgets/TableWidgetV2/constants.ts (2)

149-149: Evaluate if HTML columns should be filterable

Consider whether HTML columns should be included in FilterableColumnTypes. If the HTML content contains plain text that users might want to filter on, it could be valuable to add it to the FilterableColumnTypes array.

Also applies to: 163-170


149-149: ⚠️ Potential issue

Verify HTML content sanitization implementation

Adding HTML column type support requires careful consideration of XSS vulnerabilities. Ensure that HTML content is properly sanitized before rendering.

app/client/src/widgets/TableWidgetV2/widget/propertyConfig/PanelConfig/Data.ts (2)

45-48: LGTM! HTML column type option added correctly.

The implementation follows the existing pattern and maintains alphabetical ordering.


45-48: Verify HTML content sanitization implementation.

When rendering HTML content in table cells, ensure proper sanitization is implemented in the HTMLCell component to prevent XSS attacks.

Also applies to: 180-180

app/client/src/widgets/TableWidgetV2/component/Table.tsx (1)

33-37: LGTM! Clean import organization.

Import statement is well-structured with proper type imports.

app/client/src/widgets/TableWidgetV2/widget/index.tsx (2)

142-142: LGTM!

Clean import of the HTMLCell component.


2521-2537: LGTM with suggestions for HTML sanitization.

The HTML column type implementation follows the established pattern and includes all necessary cell properties. However, ensure that the HTMLCell component implements proper HTML sanitization to prevent XSS attacks.

Comment on lines +87 to +91
const inteweaveCompatibleValue = useMemo(() => {
if (value === null || value === undefined) return "";

return String(value);
}, [value]);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in variable name 'inteweaveCompatibleValue'

The variable 'inteweaveCompatibleValue' seems to be misspelled. It should be 'interweaveCompatibleValue' to match the 'Interweave' library.

Apply this diff to correct the variable name:

- const inteweaveCompatibleValue = useMemo(() => {
+ const interweaveCompatibleValue = useMemo(() => {

Also, update all usages of this variable accordingly.

Committable suggestion skipped: line range outside the PR's diff.

Copy link

Deploy-Preview-URL: https://ce-37603.dp.appsmith.com

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Nov 27, 2024
…o rahulbarwal/Issue13681/-Feature]--Support-HTML-as-a-column-type-in-the-table-widget
This commit adds cell wrapping support to the Table widget with the following changes:

- Add allowCellWrapping property that controls text wrapping behavior in table cells
- Update cell styling to use break-spaces and word-break when wrapping is enabled
- Adjust cell height calculations to accommodate wrapped content
- Disable virtual scrolling when any column has cell wrapping enabled for better rendering
- Update inline cell editor height to be dynamic when wrapping is enabled

Key changes:
- TableStyledWrappers.tsx: Add conditional cell wrapping styles (lines 579-588)
- InlineCellEditor.tsx: Update height calculation for wrapped cells (lines 49-62)
- Table.tsx: Disable virtual scrolling when cell wrapping is enabled (lines 330-334)
- PlainTextCell.tsx: Add content height detection for wrapped cells (lines 102-107)

This improves content visibility in table cells by allowing text to wrap instead of being truncated with ellipsis, while maintaining performance optimizations where possible.
## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes #`Issue Number`  
_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=""

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]  
> If you modify the content in this section, you are likely to disrupt
the CI result for your PR.

<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12082842511.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37603.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-37603.dp.appsmith.com

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12083755845.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37603.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-37603.dp.appsmith.com

@github-actions github-actions bot removed the Stale label Nov 29, 2024
@rahulbarwal rahulbarwal requested a review from a team December 2, 2024 09:42
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@rahulbarwal rahulbarwal marked this pull request as draft December 2, 2024 09:43
Copy link

github-actions bot commented Dec 2, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12116632335.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37603.
recreate: .

@rahulbarwal rahulbarwal changed the title feat: HTML column type support in table feat:[POC] HTML column type support in table Dec 2, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
app/client/src/components/propertyControls/HTMLTableComputeValue.tsx (2)

5-7: Add JSDoc comments to document HTML support capabilities

The interface should include documentation about HTML rendering capabilities and any restrictions.

+/**
+ * Props for HTML compute control in table columns
+ * @property {string} defaultValue - Default HTML content for the column
+ */
export interface HTMLComputeTablePropertyControlProps extends ControlProps {
  defaultValue?: string;
}

9-25: Consider adding HTML content validation

The component accepts any string as HTML content without validation. Consider adding runtime checks for valid HTML structure.

class HTMLComputeTablePropertyControl extends ComputeTablePropertyControlV2 {
+ private validateHTML(content: string): boolean {
+   const parser = new DOMParser();
+   const doc = parser.parseFromString(content, 'text/html');
+   return !doc.querySelector('parsererror');
+ }

  render() {
+   if (this.props.defaultValue && !this.validateHTML(this.props.defaultValue)) {
+     console.warn('Invalid HTML content provided');
+   }
    return (
      <ComputeTablePropertyControlV2
        {...this.props}
        additionalControlData={{
          ...this.props.additionalControlData,
          isExpectingHTML: true,
        }}
      />
    );
  }
app/client/src/components/propertyControls/TableComputeValue.tsx (1)

16-16: Group related imports together

The normalizedMultilineValue import should be grouped with other utility imports.

-import { JSToString, normalizedMultilineValue, stringToJS } from "./utils";
+import {
+  JSToString,
+  normalizedMultilineValue,
+  stringToJS,
+} from "./utils";
app/client/src/components/propertyControls/index.ts (1)

Line range hint 142-177: Add HTMLComputeTablePropertyControl's props type to PropertyControlPropsType.

The props type for the new HTMLComputeTablePropertyControl is missing from the PropertyControlPropsType union. This could cause TypeScript compilation issues.

Add the type to the union:

export type PropertyControlPropsType =
  | ControlProps
  | InputControlProps
  | DropDownControlProps
+ | HTMLComputeTablePropertyControlProps
  // ... other types
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c00f3ee and cd9422d.

📒 Files selected for processing (4)
  • app/client/src/components/propertyControls/HTMLTableComputeValue.tsx (1 hunks)
  • app/client/src/components/propertyControls/TableComputeValue.tsx (2 hunks)
  • app/client/src/components/propertyControls/index.ts (2 hunks)
  • app/client/src/components/propertyControls/utils.ts (1 hunks)
🔇 Additional comments (1)
app/client/src/components/propertyControls/index.ts (1)

80-80: LGTM on the HTMLComputeTablePropertyControl integration.

The import and export additions follow the existing patterns and maintain alphabetical ordering.

Also applies to: 105-105

Comment on lines +41 to +43
export const normalizedMultilineValue = (value: string) => {
return value.replace(/'/g, '"').replace(/\n/g, "\\n");
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add HTML sanitization to prevent XSS attacks

The normalizedMultilineValue function handles string normalization but doesn't sanitize HTML content. This could expose the application to XSS vulnerabilities when rendering HTML in table cells.

Consider using DOMPurify or a similar library to sanitize HTML content:

export const normalizedMultilineValue = (value: string) => {
-  return value.replace(/'/g, '"').replace(/\n/g, "\\n");
+  return DOMPurify.sanitize(value.replace(/'/g, '"').replace(/\n/g, "\\n"));
};

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +185 to +192
// Handle multiline strings by replacing newlines with spaces
let stringToEvaluate = "";

if (this.props.additionalControlData?.isExpectingHTML) {
stringToEvaluate = stringToJS(normalizedMultilineValue(value));
} else {
stringToEvaluate = stringToJS(value);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for HTML string processing

The HTML string processing lacks error handling for malformed content.

    let stringToEvaluate = "";

    if (this.props.additionalControlData?.isExpectingHTML) {
+     try {
        stringToEvaluate = stringToJS(normalizedMultilineValue(value));
+     } catch (error) {
+       console.error('Failed to process HTML content:', error);
+       return value; // Fallback to original value
+     }
    } else {
      stringToEvaluate = stringToJS(value);
    }
📝 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
// Handle multiline strings by replacing newlines with spaces
let stringToEvaluate = "";
if (this.props.additionalControlData?.isExpectingHTML) {
stringToEvaluate = stringToJS(normalizedMultilineValue(value));
} else {
stringToEvaluate = stringToJS(value);
}
// Handle multiline strings by replacing newlines with spaces
let stringToEvaluate = "";
if (this.props.additionalControlData?.isExpectingHTML) {
try {
stringToEvaluate = stringToJS(normalizedMultilineValue(value));
} catch (error) {
console.error('Failed to process HTML content:', error);
return value; // Fallback to original value
}
} else {
stringToEvaluate = stringToJS(value);
}

Copy link

github-actions bot commented Dec 2, 2024

Deploy-Preview-URL: https://ce-37603.dp.appsmith.com

Copy link

github-actions bot commented Dec 9, 2024

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Dec 9, 2024
@rahulbarwal
Copy link
Contributor Author

not required any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request High This issue blocks a user from building or impacts a lot of users Stale Table Widget V2 Issues related to Table Widget V2 Table Widget Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support HTML as a column type in the table widget
1 participant