Skip to content

feat: optimize HTML text extraction in TableWidgetV2#38153

Merged
rahulbarwal merged 6 commits intoreleasefrom
rahulbarwal/htmlcell/perf/enhancement
Dec 23, 2024
Merged

feat: optimize HTML text extraction in TableWidgetV2#38153
rahulbarwal merged 6 commits intoreleasefrom
rahulbarwal/htmlcell/perf/enhancement

Conversation

@rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Dec 13, 2024

Description

  • Enhanced the getTextFromHTML function with error handling to prevent failures when processing invalid HTML.
  • Introduced logic to conditionally extract HTML text only when necessary, improving performance.
  • Updated sorting and filtering mechanisms to utilize extracted HTML text, ensuring accurate comparisons and display.

Fixes #38275
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

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12443677014
Commit: b98e9a3
Cypress dashboard.
Tags: @tag.Table
Spec:


Sat, 21 Dec 2024 09:18:53 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for HTML content processing.
    • Optimized filtering to reduce unnecessary processing of HTML columns.
    • Improved sorting accuracy when handling HTML content.
  • Bug Fixes

    • Refined logic for extracting and managing HTML text to ensure proper filtering and sorting.

- Enhanced the getTextFromHTML function with error handling to prevent failures when processing invalid HTML.
- Introduced logic to conditionally extract HTML text only when necessary, improving performance.
- Updated sorting and filtering mechanisms to utilize extracted HTML text, ensuring accurate comparisons and display.
@rahulbarwal rahulbarwal self-assigned this Dec 13, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Walkthrough

The changes in the pull request enhance the derived.js file within the TableWidgetV2 component. Key updates include improved error handling in the getTextFromHTML function, optimizations to avoid unnecessary function calls, and refined logic for extracting and sorting HTML content. Additionally, the filtering logic has been adjusted to utilize extracted text, ensuring proper handling of HTML data. Minor adjustments were made to maintain consistency in omitted keys across functions.

Changes

File Path Change Summary
app/client/src/widgets/TableWidgetV2/widget/derived.js - Enhanced getTextFromHTML with error handling.
- Introduced optimization to check for HTML columns in filters.
- Added getKeyForExtractedTextFromHTML for unique key generation.
- Updated getFilteredTableData for improved filtering logic.
- Modified sorting in getOrderedTableColumns to use extracted HTML text.
- Minor adjustments for consistent omitted keys.

Possibly related PRs

Suggested labels

Table Widget, Widgets Product, Task

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007
  • jacquesikot

🎉 In the realm of code, where logic does flow,
Enhancements abound, making data aglow.
With filters refined and errors now tamed,
The table widget shines, its prowess proclaimed.
So here's to the changes, both clever and bright,
In the world of widgets, everything's right! 🌟


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

@github-actions github-actions bot added the Enhancement New feature or request label Dec 13, 2024
@rahulbarwal rahulbarwal added the Table Widget V2 Issues related to Table Widget V2 label Dec 13, 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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 88ec7c7 and cc93aa9.

📒 Files selected for processing (1)
  • app/client/src/widgets/TableWidgetV2/widget/derived.js (5 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/src/widgets/TableWidgetV2/widget/derived.js

[error] 540-543: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 544-547: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

🔇 Additional comments (3)
app/client/src/widgets/TableWidgetV2/widget/derived.js (3)

287-295: Good addition of error handling in getTextFromHTML

The try-catch block enhances robustness when processing invalid HTML content.


850-866: Efficiently processing HTML values with conditional checks

Optimizes performance by avoiding unnecessary calls to getTextFromHTML when not needed.


919-926: Verify existence of extracted HTML text keys

Ensure that the keys returned by getKeyForExtractedTextFromHTML exist in the data to prevent potential undefined values.

Please confirm that all possible HTML columns are accounted for and handled correctly.

@rahulbarwal rahulbarwal added the ok-to-test Required label for CI label Dec 13, 2024
- Optimized HTML text extraction logic to conditionally call getTextFromHTML, improving performance.
- Updated filtering and sorting mechanisms to account for HTML columns, ensuring accurate data handling.
- Removed redundant code related to HTML column checks, streamlining the implementation.
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: 0

🧹 Outside diff range and nitpick comments (2)
app/client/src/widgets/TableWidgetV2/widget/derived.js (2)

287-295: Consider using DOMParser for better performance

While the current implementation works, using DOMParser would be more efficient than creating a DOM element.

-      try {
-        const tempDiv = document.createElement("div");
-        tempDiv.innerHTML = html;
-        return tempDiv.textContent || tempDiv.innerText || "";
-      } catch (e) {
-        return "";
-      }
+      try {
+        const parser = new DOMParser();
+        const doc = parser.parseFromString(html, 'text/html');
+        return doc.body.textContent || "";
+      } catch (e) {
+        return "";
+      }

924-935: Consider extracting repeated HTML text retrieval logic

The HTML text retrieval logic is duplicated. Consider extracting it into a helper function.

+    const getHTMLColumnText = (row, column) => {
+      return row[getKeyForExtractedTextFromHTML(column)] ?? 
+             getTextFromHTML(row[column]);
+    };
+
     const originalColValue = isHTMLColumn
-      ? originalRow[
-          getKeyForExtractedTextFromHTML(props.filters[i].column)
-        ] ?? getTextFromHTML(originalRow[props.filters[i].column])
+      ? getHTMLColumnText(originalRow, props.filters[i].column)
       : originalRow[props.filters[i].column];
     const displayedColValue = isHTMLColumn
-      ? displayedRow[
-          getKeyForExtractedTextFromHTML(props.filters[i].column)
-        ] ?? getTextFromHTML(displayedRow[props.filters[i].column])
+      ? getHTMLColumnText(displayedRow, props.filters[i].column)
       : displayedRow[props.filters[i].column];
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc93aa9 and 6cc8438.

📒 Files selected for processing (1)
  • app/client/src/widgets/TableWidgetV2/widget/derived.js (5 hunks)
🔇 Additional comments (2)
app/client/src/widgets/TableWidgetV2/widget/derived.js (2)

298-320: LGTM! Well-implemented optimization

The optimization to avoid unnecessary HTML text extraction is well implemented with:

  • Clear conditions for when extraction is needed
  • Efficient caching mechanism using generated keys

550-566: LGTM! Properly scoped implementation

The HTML sorting logic is well-implemented with proper block scoping and efficient use of cached values.

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

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

@github-actions
Copy link

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

@rahulbarwal rahulbarwal added the Widgets & Accelerators Pod Issues related to widgets & Accelerators label Dec 18, 2024
- Changed the implementation of HTML column alias storage from an array to a Set for improved performance in filtering and sorting operations.
- Updated related filtering and sorting logic to utilize Set methods, enhancing efficiency.
- Added a new test case to validate that search functionality does not filter based on HTML attributes.
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

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

@github-actions
Copy link

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

- Updated the `getTextFromHTML` function to stringify JavaScript objects before processing, ensuring compatibility with HTML column handling.
- Added a new test case to validate search functionality when a JavaScript object is passed in the HTML column, confirming that the search works as expected.
@github-actions github-actions bot added Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Needs Triaging Needs attention from maintainers to triage Release Widgets Product This label groups issues related to widgets and removed Bug Something isn't working labels Dec 21, 2024
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 Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Release 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [HTML Column Type - Table] - Movies db - genres column - if we change type to HTML, all data is lost

3 participants