fix: render sidebar correctly

This commit is contained in:
sokumon 2025-08-21 00:03:47 +05:30
parent 0c580533b0
commit 2b031a170b
3 changed files with 38 additions and 11 deletions

View file

@ -152,7 +152,6 @@ def load_desktop_data(bootinfo):
bootinfo.desktop_icons = get_desktop_icons()
bootinfo.workspaces = get_workspace_sidebar_items()
bootinfo.workspace_sidebar_item = get_sidebar_items()
print(bootinfo.workspace_sidebar_item)
allowed_pages = [d.name for d in bootinfo.workspaces.get("pages")]
bootinfo.module_wise_workspaces = get_controller("Workspace").get_module_wise_workspaces()
bootinfo.dashboards = frappe.get_all("Dashboard")
@ -542,6 +541,14 @@ def get_sidebar_items():
"icon": si.icon,
"child": si.child,
}
if si.link_type == "Report":
report_type, ref_doctype = frappe.db.get_value(
"Report", si.link_to, ["report_type", "ref_doctype"]
)
workspace_sidebar["report"] = {
"report_type": report_type,
"ref_doctype": ref_doctype,
}
sidebar_items[desktop_icon].append(workspace_sidebar)
return sidebar_items

View file

@ -184,7 +184,9 @@ Tip: use lucide.svg in /icons for all downloaded icons
<symbol viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" id="icon-drag">
<circle cx="12" cy="5" r="1"/><circle cx="19" cy="5" r="1"/><circle cx="5" cy="5" r="1"/><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/><circle cx="12" cy="19" r="1"/><circle cx="19" cy="19" r="1"/><circle cx="5" cy="19" r="1"/>
</symbol>
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="icon-shield">
<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z" />
</symbol>
<symbol viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" id="icon-drag-sm">
<circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/>
</symbol>
@ -432,6 +434,10 @@ Tip: use lucide.svg in /icons for all downloaded icons
<circle cx="10.75" cy="6.25" r="0.5" fill="#4C5A67" />
</symbol>
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="icon-user">
<path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" /> <circle cx="12" cy="7" r="4" />
</symbol>
<symbol viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" id="icon-users">
<path d="M18 21a8 8 0 0 0-16 0" /> <circle cx="10" cy="8" r="5" /> <path d="M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3" />
</symbol>

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View file

@ -36,6 +36,7 @@ frappe.ui.Sidebar = class Sidebar {
}
setup(workspace_title) {
if (!this.setup_complete) {
this.workspace_title = workspace_title;
this.make_dom();
this.apps_switcher = new frappe.ui.SidebarHeader(this, workspace_title);
this.make_sidebar(workspace_title.toLowerCase());
@ -54,8 +55,6 @@ frappe.ui.Sidebar = class Sidebar {
this.wrapper.find(".overlay").on("click", () => {
this.close_sidebar();
});
this.apps_switcher = new frappe.ui.SidebarHeader(this);
this.apps_switcher.create_app_data_map();
}
set_hover() {
@ -72,7 +71,18 @@ frappe.ui.Sidebar = class Sidebar {
set_all_pages() {
this.sidebar_items = frappe.boot.workspace_sidebar_item;
}
async set_report_items() {
for (let f of this.workspace_sidebar_items) {
if (f.link_type === "Report") {
const { message } = await frappe.db.get_value("Report", f.link_to, [
"report_type",
"ref_doctype",
]);
f.report = message;
}
}
console.log(this.workspace_sidebar_items);
}
set_default_app() {
// sort apps based on # of workspaces
frappe.boot.app_data.sort((a, b) => (a.workspaces.length < b.workspaces.length ? 1 : -1));
@ -177,7 +187,6 @@ frappe.ui.Sidebar = class Sidebar {
this.wrapper.find(".standard-sidebar-section").remove();
}
this.workspace_sidebar_items = frappe.boot.workspace_sidebar_item[workspace_title];
let parent_pages = this.workspace_sidebar_items;
if (this.workspace_sidebar_items && this.workspace_sidebar_items.length > 0) {
this.workspace_sidebar_items.unshift({
label: "Home",
@ -194,7 +203,7 @@ frappe.ui.Sidebar = class Sidebar {
route: `/app/${workspace_title}`,
};
}
this.set_report_items();
// this.build_sidebar_section("All", parent_pages);
this.create_sidebar();
@ -209,6 +218,7 @@ frappe.ui.Sidebar = class Sidebar {
this.set_sidebar_state();
}
create_sidebar() {
this.set_report_items();
if (this.workspace_sidebar_items && this.workspace_sidebar_items.length > 0) {
let parent_links = this.workspace_sidebar_items.filter((f) => f.child !== 1);
parent_links.forEach((w) => {
@ -305,9 +315,14 @@ frappe.ui.Sidebar = class Sidebar {
if (item.type == "Section Break") {
let current_index = this.workspace_sidebar_items.indexOf(item);
let child_items = this.workspace_sidebar_items
.slice(current_index)
.filter((page) => page.child == 1);
let sidebar_items = this.workspace_sidebar_items.slice(current_index + 1);
let next_section_break = sidebar_items.findIndex((f) => f.type == "Section Break");
let child_items;
if (next_section_break == -1) {
child_items = sidebar_items;
} else {
child_items = sidebar_items.slice(0, next_section_break);
}
if (child_items.length > 0) {
let child_container = $item_container.find(".sidebar-child-item");
child_container.addClass("hidden");
@ -350,7 +365,6 @@ frappe.ui.Sidebar = class Sidebar {
path = item.route;
}
}
console.log(item);
return $(
frappe.render_template("sidebar_item", {
item: item,