Skip to content

WEB-976: Fix generated report downloads#3727

Open
SaaiAravindhRaja wants to merge 1 commit into
openMF:devfrom
SaaiAravindhRaja:WEB-976-fix-report-download
Open

WEB-976: Fix generated report downloads#3727
SaaiAravindhRaja wants to merge 1 commit into
openMF:devfrom
SaaiAravindhRaja:WEB-976-fix-report-download

Conversation

@SaaiAravindhRaja

@SaaiAravindhRaja SaaiAravindhRaja commented Jul 17, 2026

Copy link
Copy Markdown
Member

Description

  • fix generated XLS report downloads to use the real report filename instead of filename.xlsx
  • trigger downloads through a temporary document-attached anchor for consistent browser behavior
  • reuse the same download helper from both report export paths
  • keep existing spreadsheet formula-injection sanitization intact
  • add unit coverage for generated browser downloads and object URL cleanup

Related issues and discussion

Screenshots, if any

No layout changes.

Checklist

  • If you have multiple commits please combine them into one commit by squashing them.
  • Read and understood the contribution guidelines at web-app/.github/CONTRIBUTING.md.

Testing

  • ./node_modules/.bin/jest --config jest.config.ts src/app/core/utils/file-download.utils.spec.ts --runInBand --coverage=false
  • ./node_modules/.bin/eslint . && ./node_modules/.bin/stylelint "src/**/*.scss" && ./node_modules/.bin/prettier . --check && ./node_modules/.bin/htmlhint "src" --config .htmlhintrc
  • node --max-old-space-size=16384 ./node_modules/@angular/cli/bin/ng build --configuration production --output-hashing=none --output-path /tmp/mifos-web-app-build-check-*
  • semgrep scan --config p/default --error --quiet src/app/core/utils/file-download.utils.ts src/app/core/utils/file-download.utils.spec.ts src/app/reports/run-report/table-and-sms/table-and-sms.component.ts src/app/reports/run-report/run-report.component.ts
  • gitleaks git --log-opts origin/dev..HEAD --no-banner --redact
  • git diff --check origin/dev...HEAD

Summary by CodeRabbit

  • New Features

    • Added XLSX export support for report results with automatic file downloads.
    • Exported files now use consistent filenames and browser download behavior.
  • Bug Fixes

    • Improved download cleanup by removing temporary elements and releasing generated URLs after completion.
    • Added safer handling when export responses do not contain data.
  • Tests

    • Added automated coverage for download initiation, link configuration, and cleanup behavior.

@SaaiAravindhRaja
SaaiAravindhRaja requested a review from a team July 17, 2026 04:41
@mifos-cla-check

Copy link
Copy Markdown

👋 Hi @SaaiAravindhRaja — thank you for your pull request.

This PR is currently blocked because we do not have a Contributor License Agreement (CLA) on file for your GitHub account.

To get unblocked:

  1. Complete the form at https://mifos.org/about-us/financial-legal/mifos-contributor-agreement
  2. Complete the CLA signing process
  3. Once verified you will be added to the approved contributors list and this PR check will be cleared

@mifos-cla-check mifos-cla-check Bot added the cla-required CLA signature required before this PR can be merged label Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "pre_merge_checks"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

Adds a shared downloadBlob utility with cleanup and tests, then replaces duplicated XLSX download logic in both report export flows. One export method now awaits workbook generation and returns Promise<void>.

Changes

Report download flow

Layer / File(s) Summary
Blob download utility and coverage
src/app/core/utils/file-download.utils.ts, src/app/core/utils/file-download.utils.spec.ts
Adds downloadBlob to create, click, and asynchronously clean up a hidden download link, with Jest coverage for URL handling and DOM cleanup.
Report export integration
src/app/reports/run-report/run-report.component.ts, src/app/reports/run-report/table-and-sms/table-and-sms.component.ts
Replaces duplicated XLSX download code with downloadBlob; the table-and-SMS export now awaits workbook generation and returns Promise<void>.
Estimated code review effort: 2 (Simple) ~10 minutes

Possibly related PRs

Suggested reviewers: alberto-art3ch

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing generated report downloads.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/app/reports/run-report/run-report.component.ts (1)

526-533: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Await the exportToXLS Promise before clearing the processing state.

exportToXLS was updated to be an async method, but its returned Promise is not awaited here. As a result, this.isProcessing = false executes immediately before the Excel workbook generation completes. This prematurely removes the loading UI state while the file is still generating in the background.

🐛 Proposed fix
-        this.exportToXLS(reportName, res.data, displayedColumns);
-      } else {
-        this.alertService.alert({
-          type: this.translateService.instant('errors.report.type'),
-          message: this.translateService.instant('errors.report.generatedNoData', { reportName })
-        });
-      }
-      this.isProcessing = false;
+        this.exportToXLS(reportName, res.data, displayedColumns)
+          .catch((err) => console.error('Export failed:', err))
+          .finally(() => {
+            this.isProcessing = false;
+            this.cdr.markForCheck();
+          });
+      } else {
+        this.alertService.alert({
+          type: this.translateService.instant('errors.report.type'),
+          message: this.translateService.instant('errors.report.generatedNoData', { reportName })
+        });
+        this.isProcessing = false;
+        this.cdr.markForCheck();
+      }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/reports/run-report/run-report.component.ts` around lines 526 - 533,
Update the report-generation flow around exportToXLS so it awaits the async
exportToXLS Promise before setting isProcessing to false. Preserve the existing
no-data alert behavior and ensure the processing state remains active until
workbook generation completes.
🧹 Nitpick comments (1)
src/app/reports/run-report/table-and-sms/table-and-sms.component.ts (1)

224-235: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Refactor CSV download to use the shared downloadBlob utility.

Instead of encoding the CSV as a data URI and injecting an anchor element directly, use the new downloadBlob utility. This provides consistent download behavior, centralizes the logic, and avoids potential browser URL length limits associated with large data URIs.

♻️ Proposed refactor
   downloadCSV(fileName: string, delimiter: string) {
     const headers = this.displayedColumns;
-    let csv = this.csvData.map((object: any) => object.row.map((cell: any) => sanitizeCsvValue(cell)).join(delimiter));
-    csv.unshift(`data:text/csv;charset=utf-8,${headers.map(sanitizeCsvValue).join(delimiter)}`);
-    csv = csv.join('\r\n');
-    const link = document.createElement('a');
-    link.setAttribute('href', encodeURI(csv));
-    link.setAttribute('download', fileName);
-    document.body.appendChild(link);
-    link.click();
-    document.body.removeChild(link);
+    const csvLines = this.csvData.map((object: any) => object.row.map((cell: any) => sanitizeCsvValue(cell)).join(delimiter));
+    csvLines.unshift(headers.map(sanitizeCsvValue).join(delimiter));
+    const csvString = csvLines.join('\r\n');
+
+    const blob = new Blob([csvString], { type: 'text/csv;charset=utf-8;' });
+    downloadBlob(blob, fileName);
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/reports/run-report/table-and-sms/table-and-sms.component.ts` around
lines 224 - 235, Update the downloadCSV method to build the CSV text as it does
currently, then pass it to the shared downloadBlob utility with the appropriate
CSV content type and fileName. Remove the data-URI encoding and direct anchor
creation, click, and cleanup logic while preserving the existing headers,
delimiter, sanitization, and row formatting.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/app/reports/run-report/run-report.component.ts`:
- Around line 526-533: Update the report-generation flow around exportToXLS so
it awaits the async exportToXLS Promise before setting isProcessing to false.
Preserve the existing no-data alert behavior and ensure the processing state
remains active until workbook generation completes.

---

Nitpick comments:
In `@src/app/reports/run-report/table-and-sms/table-and-sms.component.ts`:
- Around line 224-235: Update the downloadCSV method to build the CSV text as it
does currently, then pass it to the shared downloadBlob utility with the
appropriate CSV content type and fileName. Remove the data-URI encoding and
direct anchor creation, click, and cleanup logic while preserving the existing
headers, delimiter, sanitization, and row formatting.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5c73d9ee-8a1b-4fff-8e52-4621e4402d8a

📥 Commits

Reviewing files that changed from the base of the PR and between e3cb18e and b8188eb.

📒 Files selected for processing (4)
  • src/app/core/utils/file-download.utils.spec.ts
  • src/app/core/utils/file-download.utils.ts
  • src/app/reports/run-report/run-report.component.ts
  • src/app/reports/run-report/table-and-sms/table-and-sms.component.ts

@IOhacker

Copy link
Copy Markdown
Contributor

@SaaiAravindhRaja could you please sign the CLA?

@SaaiAravindhRaja

Copy link
Copy Markdown
Member Author

hi! I have signed the CLA, not sure why it isn't updated here

@SaaiAravindhRaja

Copy link
Copy Markdown
Member Author

can I check if its https://mifos.org/about-us/financial-legal/mifos-contributor-agreement/ or if there's another link too? thanks!

@IOhacker

Copy link
Copy Markdown
Contributor

@DavidH-1 could you please help us?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-required CLA signature required before this PR can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants