Skip to content

Commit

Permalink
fix: dont render very large reports, offer export instead
Browse files Browse the repository at this point in the history
(cherry picked from commit 65fb8dc)
  • Loading branch information
ankush authored and mergify[bot] committed Mar 13, 2024
1 parent 8eb1b24 commit 3f0760c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion frappe/desk/query_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def build_xlsx_data(data, visible_idx, include_indentation, include_filters=Fals
datetime.timedelta,
)

if len(visible_idx) == len(data.result):
if len(visible_idx) == len(data.result) or not visible_idx:
# It's not possible to have same length and different content.
ignore_visible_idx = True
else:
Expand Down
38 changes: 26 additions & 12 deletions frappe/public/js/frappe/views/reports/query_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,15 +761,19 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {

add_prepared_report_buttons(doc) {
if (doc) {
this.page.add_inner_button(__("Download Report"), function () {
window.open(
frappe.urllib.get_full_url(
"/api/method/frappe.core.doctype.prepared_report.prepared_report.download_attachment?" +
"dn=" +
encodeURIComponent(doc.name)
)
);
});
this.page.add_inner_button(
__("Download Report"),
function () {
window.open(
frappe.urllib.get_full_url(
"/api/method/frappe.core.doctype.prepared_report.prepared_report.download_attachment?" +
"dn=" +
encodeURIComponent(doc.name)
)
);
},
__("Actions")
);

let pretty_diff = frappe.datetime.comment_when(doc.report_end_time);
const days_old = frappe.datetime.get_day_diff(
Expand Down Expand Up @@ -953,6 +957,16 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
let data = this.data;
let columns = this.columns.filter((col) => !col.hidden);

if (data.length > 100000) {
let msg = __(
"This report contains {0} rows and is too big to display in browser, you can {1} this report instead.",
[cstr(format_number(data.length, null, 0)).bold(), __("export").bold()]
);

this.toggle_message(true, `${frappe.utils.icon("solid-warning")} ${msg}`);
return;
}

if (this.raw_data.add_total_row && !this.report_settings.tree) {
data = data.slice();
data.splice(-1, 1);
Expand Down Expand Up @@ -1523,15 +1537,15 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
])
);

const visible_idx = this.datatable.bodyRenderer.visibleRowIndices;
if (visible_idx.length + 1 === this.data.length) {
const visible_idx = this.datatable?.bodyRenderer.visibleRowIndices || [];
if (visible_idx.length + 1 === this.data?.length) {
visible_idx.push(visible_idx.length);
}

const args = {
cmd: "frappe.desk.query_report.export_query",
report_name: this.report_name,
custom_columns: this.custom_columns.length ? this.custom_columns : [],
custom_columns: this.custom_columns?.length ? this.custom_columns : [],
file_format_type: file_format,
filters: filters,
applied_filters: applied_filters,
Expand Down

0 comments on commit 3f0760c

Please sign in to comment.