fix: allways try to show a sidebar

This commit is contained in:
sokumon 2025-11-13 15:54:35 +05:30
parent 072c15a88a
commit ad4c7a46ab
3 changed files with 37 additions and 17 deletions

View file

@ -202,6 +202,7 @@ frappe.router = {
return frappe.model.with_doctype(doctype_route.doctype).then(() => {
// doctype route
let meta = frappe.get_meta(doctype_route.doctype);
this.meta = meta;
if (route[1] && route[1] === "view" && route[2]) {
route = this.get_standard_route_for_list(
route,

View file

@ -18,6 +18,12 @@ frappe.ui.Sidebar = class Sidebar {
this.$sidebar = this.wrapper.find(".body-sidebar");
this.items = [];
this.setup_events();
this.sidebar_module_map = {
Core: "System",
Desk: "Build",
Custom: "Build",
Accounts: "Accounting",
};
}
prepare() {
@ -83,7 +89,7 @@ frappe.ui.Sidebar = class Sidebar {
setup_events() {
const me = this;
frappe.router.on("change", function (router) {
frappe.app.sidebar.set_workspace_sidebar();
frappe.app.sidebar.set_workspace_sidebar(router);
});
$(document).on("page-change", function () {
frappe.app.sidebar.toggle();
@ -131,7 +137,11 @@ frappe.ui.Sidebar = class Sidebar {
const that = this;
$(".item-anchor").each(function () {
let href = $(this).attr("href")?.split("?")[0];
if (href == decodeURIComponent(window.location.pathname)) {
const path = decodeURIComponent(window.location.pathname);
// Match only if path equals href or starts with it followed by "/" or end of string
const isActive = new RegExp(`^${href}(?:/|$)`).test(path);
if (href && isActive) {
match = true;
if (that.active_item) that.active_item.removeClass("active-sidebar");
that.active_item = $(this).parent();
@ -285,7 +295,7 @@ frappe.ui.Sidebar = class Sidebar {
}
}
set_workspace_sidebar() {
set_workspace_sidebar(router) {
let route = frappe.get_route();
if (frappe.get_route()[0] == "setup-wizard") return;
if (route[0] == "Workspaces") {
@ -300,19 +310,28 @@ frappe.ui.Sidebar = class Sidebar {
} else if (route[0] == "List" || route[0] == "Form") {
let doctype = route[1];
let sidebars = this.get_correct_workspace_sidebars(doctype);
if (this.workspace_title && sidebars.includes(this.workspace_title.toLowerCase())) {
frappe.app.sidebar.setup(this.workspace_title.toLowerCase());
if (sidebars.length == 0) {
let module_name = router.meta?.module;
if (module_name) {
frappe.app.sidebar.setup(this.sidebar_module_map[module_name] || module_name);
}
} else {
frappe.app.sidebar.setup(sidebars[0]);
if (
this.workspace_title &&
sidebars.includes(this.workspace_title.toLowerCase())
) {
frappe.app.sidebar.setup(this.workspace_title.toLowerCase());
} else {
frappe.app.sidebar.setup(sidebars[0]);
}
}
this.sidebar_shown;
} else if (route[0] == "query-report") {
let doctype = route[1];
let sidebars = this.get_correct_workspace_sidebars(doctype);
if (this.workspace_title && sidebars.includes(this.workspace_title.toLowerCase())) {
frappe.app.sidebar.setup(this.workspace_title.toLowerCase());
} else {
frappe.app.sidebar.setup(sidebars[0] || "Build");
frappe.app.sidebar.setup(sidebars[0]);
}
}
@ -330,8 +349,8 @@ frappe.ui.Sidebar = class Sidebar {
} else {
workspace_title = this.get_correct_workspace_sidebars(route);
}
let module_name = workspace_title ? workspace_title[0] : "Build";
frappe.app.sidebar.setup(module_name || this.workspace_title || "Build");
let module_name = workspace_title[0];
frappe.app.sidebar.setup(module_name || this.workspace_title);
}
get_correct_workspace_sidebars(link_to) {
@ -475,7 +494,7 @@ frappe.ui.Sidebar = class Sidebar {
fieldtype: "Select",
in_list_view: 1,
label: "Type",
options: "Link\nSection Break\nSpace\nSidebar Item Group",
options: "Link\nSection Break\nSpacer\nSidebar Item Group",
onchange: function () {
let type = this.get_value();
if (type == "Section Break") {
@ -703,7 +722,8 @@ frappe.ui.Sidebar = class Sidebar {
type: "POST",
method: "frappe.desk.doctype.workspace_sidebar.workspace_sidebar.add_sidebar_items",
args: {
sidebar_title: me.workspace_title,
sidebar_title:
me.workspace_title || frappe.app.sidebar.sidebar_header.workspace_title,
sidebar_items: me.new_sidebar_items,
},
callback: function (r) {

View file

@ -49,7 +49,7 @@ frappe.views.Workspace = class Workspace {
this.prepare_container();
this.sidebar = frappe.app.sidebar;
this.cached_pages = $.extend(true, {}, frappe.boot.sidebar_pages);
this.cached_pages = $.extend(true, {}, frappe.boot.workspaces);
this.has_access = frappe.boot.workspaces.has_access;
this.has_create_access = frappe.boot.workspaces.has_create_access;
this.setup();
@ -376,7 +376,7 @@ frappe.views.Workspace = class Workspace {
this.clear_page_actions();
await this.editor.readOnly.toggle();
this.is_read_only = true;
frappe.boot.sidebar_pages = this.cached_pages;
frappe.boot.workspaces = this.cached_pages;
this.reload();
frappe.show_alert({ message: __("Customizations Discarded"), indicator: "info" });
});
@ -567,10 +567,9 @@ frappe.views.Workspace = class Workspace {
});
}
if (r.message) {
frappe.boot.sidebar_pages = r.message.workspace_pages;
frappe.boot.workspaces = r.message.workspace_pages;
me.workspaces = frappe.boot.workspaces.pages;
me.setup_pages(frappe.boot.sidebar_pages.pages);
me.setup_pages(frappe.boot.workspaces.pages);
frappe.boot.workspace_sidebar_item = r.message.sidebar_items;
}
@ -754,7 +753,7 @@ frappe.views.Workspace = class Workspace {
delete this.pages[this._page.name];
this._page = null;
return this.get_pages().then((r) => {
frappe.boot.sidebar_pages = r;
frappe.boot.workspaces = r;
this.setup_pages(frappe.boot.workspaces.pages);
this.show();
if (this.undo) this.undo.readOnly = true;