feat: disable comment count on list view settings. (#20039)

* feat: add list view setting disable column count.

* fix: cast using sbool

* fix: make modified last-child if comment_count is disabled.
This commit is contained in:
Devin Slauenwhite 2023-02-22 07:47:45 -05:00 committed by GitHub
parent 6e3bfb06c2
commit d5ce94d6a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 9 deletions

View file

@ -15,11 +15,13 @@ context("List View Settings", () => {
cy.clear_filters();
cy.wait(300);
cy.get(".list-count").should("contain", "20 of");
cy.get("[href='#icon-small-message']").should("be.visible");
cy.get(".menu-btn-group button").click();
cy.get(".dropdown-menu li").filter(":visible").contains("List Settings").click();
cy.get(".modal-dialog").should("contain", "DocType Settings");
cy.findByLabelText("Disable Count").check({ force: true });
cy.findByLabelText("Disable Comment Count").check({ force: true });
cy.findByLabelText("Disable Sidebar Stats").check({ force: true });
cy.findByRole("button", { name: "Save" }).click();
@ -27,11 +29,13 @@ context("List View Settings", () => {
cy.get(".list-count").should("be.empty");
cy.get(".list-sidebar .list-tags").should("not.exist");
cy.get("[href='#icon-small-message']").should("not.be.visible");
cy.get(".menu-btn-group button").click({ force: true });
cy.get(".dropdown-menu li").filter(":visible").contains("List Settings").click();
cy.get(".modal-dialog").should("contain", "DocType Settings");
cy.findByLabelText("Disable Count").uncheck({ force: true });
cy.findByLabelText("Disable Comment Count").uncheck({ force: true });
cy.findByLabelText("Disable Sidebar Stats").uncheck({ force: true });
cy.findByRole("button", { name: "Save" }).click();
});

View file

@ -7,6 +7,7 @@
"engine": "InnoDB",
"field_order": [
"disable_count",
"disable_comment_count",
"disable_sidebar_stats",
"disable_auto_refresh",
"total_fields",
@ -49,13 +50,20 @@
"hidden": 1,
"label": "Fields",
"read_only": 1
},
{
"default": "0",
"fieldname": "disable_comment_count",
"fieldtype": "Check",
"label": "Disable Comment Count"
}
],
"links": [],
"modified": "2020-05-12 18:27:15.568199",
"modified": "2023-02-14 14:46:43.764229",
"modified_by": "Administrator",
"module": "Desk",
"name": "List View Settings",
"naming_rule": "Set by user",
"owner": "Administrator",
"permissions": [
{
@ -72,5 +80,6 @@
"read_only": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}

View file

@ -29,6 +29,7 @@ from frappe.utils import (
get_timespan_date_range,
make_filter_tuple,
)
from frappe.utils.data import sbool
LOCATE_PATTERN = re.compile(r"locate\([^,]+,\s*[`\"]?name[`\"]?\s*\)", flags=re.IGNORECASE)
LOCATE_CAST_PATTERN = re.compile(
@ -196,7 +197,7 @@ class DatabaseQuery:
result = self.build_and_run()
if with_comment_count and not as_list and self.doctype:
if sbool(with_comment_count) and not as_list and self.doctype:
self.add_comment_count(result)
if save_user_settings:

View file

@ -504,9 +504,13 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
get_args() {
const args = super.get_args();
return Object.assign(args, {
with_comment_count: true,
});
if (this.list_view_settings && !this.list_view_settings.disable_comment_count) {
args.with_comment_count = 1;
} else {
args.with_comment_count = 0;
}
return args;
}
before_refresh() {
@ -896,10 +900,13 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
</div>`;
}
const comment_count = `<span class="comment-count">
let comment_count = null;
if (this.list_view_settings && !this.list_view_settings.disable_comment_count) {
comment_count = $(`<span class="comment-count"></span>`);
$(comment_count).append(`
${frappe.utils.icon("small-message")}
${doc._comment_count > 99 ? "99+" : doc._comment_count || 0}
</span>`;
${doc._comment_count > 99 ? "99+" : doc._comment_count || 0}`);
}
html += `
<div class="level-item list-row-activity hidden-xs">
@ -907,7 +914,7 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
${settings_button || assigned_to}
</div>
${modified}
${comment_count}
${comment_count ? $(comment_count).prop("outerHTML") : ""}
</div>
<div class="level-item visible-xs text-right">
${this.get_indicator_dot(doc)}

View file

@ -4,6 +4,7 @@ import json
import frappe
from frappe.desk.listview import get_group_by_count, get_list_settings, set_list_settings
from frappe.desk.reportview import get
from frappe.tests.utils import FrappeTestCase
@ -22,6 +23,7 @@ class TestListView(FrappeTestCase):
self.assertEqual(settings.disable_auto_refresh, 0)
self.assertEqual(settings.disable_count, 0)
self.assertEqual(settings.disable_comment_count, 0)
self.assertEqual(settings.disable_sidebar_stats, 0)
def test_get_list_settings_with_non_default_settings(self):
@ -31,6 +33,7 @@ class TestListView(FrappeTestCase):
self.assertEqual(settings.disable_auto_refresh, 0)
self.assertEqual(settings.disable_count, 1)
self.assertEqual(settings.disable_comment_count, 0)
self.assertEqual(settings.disable_sidebar_stats, 0)
def test_set_list_settings_without_settings(self):
@ -39,6 +42,7 @@ class TestListView(FrappeTestCase):
self.assertEqual(settings.disable_auto_refresh, 0)
self.assertEqual(settings.disable_count, 0)
self.assertEqual(settings.disable_comment_count, 0)
self.assertEqual(settings.disable_sidebar_stats, 0)
def test_set_list_settings_with_existing_settings(self):
@ -48,6 +52,7 @@ class TestListView(FrappeTestCase):
self.assertEqual(settings.disable_auto_refresh, 1)
self.assertEqual(settings.disable_count, 0)
self.assertEqual(settings.disable_comment_count, 0)
self.assertEqual(settings.disable_sidebar_stats, 0)
def test_list_view_child_table_filter_with_created_by_filter(self):
@ -65,3 +70,18 @@ class TestListView(FrappeTestCase):
for d in get_group_by_count("Note", '[["Note Seen By","user","=","Administrator"]]', "owner")
}
self.assertEqual(data["Administrator"], 1)
def test_list_view_comment_count(self):
frappe.form_dict.doctype = "DocType"
frappe.form_dict.limit = "1"
frappe.form_dict.fields = [
"`tabDocType`.`name`",
]
for with_comment_count in (1, True, "1"):
frappe.form_dict.with_comment_count = with_comment_count
self.assertEqual(len(get()["values"][0]), 2)
for with_comment_count in (0, False, "0", None):
frappe.form_dict.with_comment_count = with_comment_count
self.assertEqual(len(get()["values"][0]), 1)