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: Enable download as excel feature on table widget. #39427

Merged

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Feb 25, 2025

Description

Add SheetJS for Excel export in Table widget

  • Optimize Excel export in Table widget with dynamic import

Fixes #38995
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/13518191583
Commit: 050fe04
Cypress dashboard.
Tags: @tag.Table
Spec:


Tue, 25 Feb 2025 10:21:46 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced an option for exporting table data as Excel files, enhancing data handling capabilities.
    • Added a new dependency for improved spreadsheet manipulation.
  • Refactor

    • Streamlined the export process to ensure a smoother and more efficient download experience with improved error handling.
    • Simplified data handling logic by removing unnecessary interfaces.

@rahulbarwal rahulbarwal self-assigned this Feb 25, 2025
@rahulbarwal rahulbarwal requested review from AmanAgarwal041 and jacquesikot and removed request for KelvinOm February 25, 2025 06:29
Copy link
Contributor

coderabbitai bot commented Feb 25, 2025

Walkthrough

This pull request introduces the new dependency "sheetjs": "^2.0.0" in the package.json file to support spreadsheet-related functionality. Additionally, the Excel download functionality in the table widget has been refactored in Download.tsx to dynamically import the xlsx library, replacing the previous zipcelx based implementation. The changes also simplify type handling by removing the DataCellProps interface and enhancing error management during the download process.

Changes

File(s) Change Summary
app/client/package.json Added new dependency "sheetjs": "^2.0.0".
app/client/src/widgets/TableWidgetV2/.../Download.tsx Refactored Excel download functionality to use dynamic imports for xlsx; removed DataCellProps interface; updated download options & error handling.
app/client/src/widgets/TableWidgetV2/.../index.tsx Added new prop widgetId: string; to ActionsPropsType interface, allowing TableDataDownload to receive the widget ID.

Possibly Related PRs

Suggested Labels

Task, Release

Suggested Reviewers

  • ApekshaBhosale
  • jacquesikot
  • sagar-qa007

Poem

In code we weave, with sheets held high,
Dynamic imports let our features fly.
Excel files bloom with a graceful art,
Each data cell plays its vital part.
Cheers to the code that makes spreadsheets sing!
🚀✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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 Bug Something isn't working Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production Query & Widgets Pod All issues related to Query, JS, Eval, and Widgets 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 Feb 25, 2025
@rahulbarwal rahulbarwal requested a review from vsvamsi1 February 25, 2025 06:29
@github-actions github-actions bot added Enhancement New feature or request and removed Bug Something isn't working labels Feb 25, 2025
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@rahulbarwal rahulbarwal added the ok-to-test Required label for CI label Feb 25, 2025
Copy link

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

@github-actions github-actions bot added Bug Something isn't working and removed Bug Something isn't working labels Feb 25, 2025
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

🧹 Nitpick comments (3)
app/client/src/widgets/TableWidgetV2/component/header/actions/Download.tsx (3)

1-1: Confirm usage of @appsmith/ads-old.

Double-check if referencing @appsmith/ads-old is intentional or if a newer package should be used.


88-91: Fix the spelling of "dowloadOptions".

The array name contains a typo; consider renaming it to downloadOptions for clarity.

-const dowloadOptions: DownloadOptionProps[] = [
+const downloadOptions: DownloadOptionProps[] = [

144-193: Handle export errors gracefully.

While console logging is acceptable for debugging, consider showing a user-facing alert or toast on failure. This helps users notice export issues.

 catch (error) {
   console.error("Error loading Excel export functionality:", error);
+  // For example
+  // showToast("Failed to download data as Excel. Please try again.");
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f5b5df8 and f47e702.

⛔ Files ignored due to path filters (1)
  • app/client/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • app/client/package.json (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/header/actions/Download.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (3)
app/client/package.json (1)

219-219: Watch out for potential duplication.

You have added "sheetjs": "^2.0.0" while also referencing "xlsx" at line 399. Consider whether both are needed or if one suffices, to avoid redundant dependencies.

app/client/src/widgets/TableWidgetV2/component/header/actions/Download.tsx (2)

4-4: No immediate concerns.

Using Blueprint's Popover here looks straightforward.


9-11: Good approach using React.memo.

Employing memo for this component is a sound performance optimization.

Copy link

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

@github-actions github-actions bot added the Bug Something isn't working label Feb 25, 2025
@github-actions github-actions bot removed the Bug Something isn't working label Feb 25, 2025
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

🧹 Nitpick comments (3)
app/client/src/widgets/TableWidgetV2/component/header/actions/Download.tsx (3)

86-95: Fix typo in variable name.

The variable name has a typo: dowloadOptions should be downloadOptions.

-const dowloadOptions: DownloadOptionProps[] = [
+const downloadOptions: DownloadOptionProps[] = [

Don't forget to update the reference on line 250 as well.


143-197: Excel download implementation looks robust.

Good implementation with dynamic import, proper error handling, and type conversion. A few suggestions:

  1. Add state management during download similar to CSV download (selectMenu state updates)
  2. Consider using a more descriptive sheet name than "Sheet1"
-  const downloadTableDataAsExcel = async () => {
+  const downloadTableDataAsExcel = async () => {
+    selectMenu(true);
     try {
       // Dynamically import xlsx only when needed
       const XLSX = await import("xlsx");
       const tableData: Array<Array<unknown>> = [];

       const headers = props.columns
         .filter((column: ReactTableColumnProps) => {
           return column.metaProperties && !column.metaProperties.isHidden;
         })
         .map((column: ReactTableColumnProps) => column.Header);

       tableData.push(headers);

       for (let row = 0; row < props.data.length; row++) {
         const data = props.data[row];
         const tableRow: Array<unknown> = [];

         props.columns.forEach((column) => {
           if (column.metaProperties && !column.metaProperties.isHidden) {
             const value = data[column.alias];

             if (
               column.columnProperties?.columnType === "number" &&
               typeof value === "string"
             ) {
               tableRow.push(Number(value) || 0);
             } else {
               tableRow.push(value);
             }
           }
         });

         tableData.push(tableRow);
       }

       // Create workbook and worksheet using the dynamically imported XLSX
       const ws = XLSX.utils.aoa_to_sheet(tableData);
       const wb = XLSX.utils.book_new();

-      XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
+      XLSX.utils.book_append_sheet(wb, ws, props.widgetName);

       // Generate and download file
       XLSX.writeFile(wb, `${props.widgetName}.xlsx`);
     } catch (error) {
       AppsmithConsole.error({
         text: `Error loading Excel export functionality: ${error}`,
         source: {
           id: props.widgetId,
           name: props.widgetName,
           type: ENTITY_TYPE.WIDGET,
         },
       });
+    } finally {
+      selectMenu(false);
     }
   };

250-250: Update variable reference.

If you rename the dowloadOptions variable as suggested, update this reference as well.

-          {dowloadOptions.map((item: DownloadOptionProps, index: number) => {
+          {downloadOptions.map((item: DownloadOptionProps, index: number) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f47e702 and 050fe04.

📒 Files selected for processing (2)
  • app/client/src/widgets/TableWidgetV2/component/header/actions/Download.tsx (4 hunks)
  • app/client/src/widgets/TableWidgetV2/component/header/actions/index.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (2)
app/client/src/widgets/TableWidgetV2/component/header/actions/index.tsx (1)

171-171: Changes look good - passing widgetId to TableDataDownload.

The addition of the widgetId prop to TableDataDownload is correct and aligns with the interface changes in Download.tsx.

app/client/src/widgets/TableWidgetV2/component/header/actions/Download.tsx (1)

76-76: Property addition looks good.

The widgetId property has been correctly added to the TableDataDownloadProps interface to match the new prop being passed.

@rahulbarwal rahulbarwal merged commit 7f300d6 into release Feb 25, 2025
45 checks passed
@rahulbarwal rahulbarwal deleted the rahulbarwal/issue38995/Bug-download-as-excel-SHEETJS branch February 25, 2025 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Query & Widgets Pod All issues related to Query, JS, Eval, and Widgets 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]: download as excel feature in table not working when column type is set as number.
2 participants