Skip to content

Commit

Permalink
refactor: avoid duplicate render_count for report view
Browse files Browse the repository at this point in the history
Only difference is element
  • Loading branch information
ankush committed Mar 12, 2024
1 parent 1fa7cc7 commit 698ef95
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/list_paging.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ context("List Paging", () => {
cy.get(".list-paging-area .list-count").should("contain.text", "500 of");
cy.get(".list-paging-area .btn-more").click();

cy.get(".list-paging-area .list-count").should("contain.text", "1000 of");
cy.get(".list-paging-area .list-count").should("contain.text", "1,000 of");
});
});
28 changes: 16 additions & 12 deletions frappe/public/js/frappe/list/list_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {

freeze() {
if (this.list_view_settings && !this.list_view_settings.disable_count) {
this.$result
.find(".list-count")
.html(`<span>${__("Refreshing", null, "Document count in list view")}...</span>`);
this.get_count_element().html(
`<span>${__("Refreshing", null, "Document count in list view")}...</span>`
);
}
}

Expand Down Expand Up @@ -619,29 +619,33 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
render_count() {
if (this.list_view_settings.disable_count) return;

this.get_count_str().then((str) => {
let me = this;
let count_element = this.$result.find(".list-count");
count_element.html(`<span>${str}</span>`);
let me = this;
let $count = this.get_count_element();
this.get_count_str().then((count) => {
$count.html(`<span>${count}</span>`);
if (this.count_upper_bound) {
count_element.attr(
$count.attr(
"title",
__(
"The count shown is an estimated count. Click here to see the accurate count."
)
);
count_element.tooltip({ delay: { show: 600, hide: 100 }, trigger: "hover" });
count_element.on("click", () => {
$count.tooltip({ delay: { show: 600, hide: 100 }, trigger: "hover" });
$count.on("click", () => {
me.count_upper_bound = 0;
count_element.off("click");
count_element.tooltip("disable");
$count.off("click");
$count.tooltip("disable");
me.freeze();
me.render_count();
});
}
});
}

get_count_element() {
return this.$result.find(".list-count");
}

get_header_html() {
if (!this.columns) {
return;
Expand Down
1 change: 1 addition & 0 deletions frappe/public/js/frappe/views/file/file_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ frappe.views.FileView = class FileView extends frappe.views.ListView {
} else {
super.render();
this.render_header();
this.render_count();
}
}

Expand Down
15 changes: 5 additions & 10 deletions frappe/public/js/frappe/views/reports/report_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,14 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
this.setup_datatable(this.data);
}

render_count() {
if (this.list_view_settings?.disable_count) {
return;
}
let $list_count = this.$paging_area.find(".list-count");
if (!$list_count.length) {
$list_count = $("<span>")
get_count_element() {
let $count = this.$paging_area.find(".list-count");
if (!$count.length) {
$count = $("<span>")
.addClass("text-muted list-count")
.prependTo(this.$paging_area.find(".level-right"));
}
this.get_count_str().then((str) => {
$list_count.text(str);
});
return $count;
}

on_update(data) {
Expand Down

0 comments on commit 698ef95

Please sign in to comment.