fix(UX): workspace breadcrumbs based on history (#20529)

* fix(UX): Resolve breadcrumb conflicts from history

Same report can be part of 2 workspace, in which case use breadcrumbs
from last workspace.

* fix: make sure last workspace belongs to same module at least
This commit is contained in:
Ankush Menat 2023-04-12 10:56:05 +05:30 committed by GitHub
parent 2623391e8f
commit c5f36a4979
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 20 deletions

View file

@ -130,7 +130,7 @@ def load_desktop_data(bootinfo):
from frappe.desk.desktop import get_workspace_sidebar_items
bootinfo.allowed_workspaces = get_workspace_sidebar_items().get("pages")
bootinfo.module_page_map = get_controller("Workspace").get_module_page_map()
bootinfo.module_wise_workspaces = get_controller("Workspace").get_module_wise_workspaces()
bootinfo.dashboards = frappe.get_all("Dashboard")

View file

@ -1,6 +1,7 @@
# Copyright (c) 2020, Frappe Technologies and contributors
# License: MIT. See LICENSE
from collections import defaultdict
from json import loads
import frappe
@ -49,12 +50,22 @@ class Workspace(Document):
delete_folder(self.module, "Workspace", self.title)
@staticmethod
def get_module_page_map():
pages = frappe.get_all(
"Workspace", fields=["name", "module"], filters={"for_user": ""}, as_list=1
def get_module_wise_workspaces():
workspaces = frappe.get_all(
"Workspace",
fields=["name", "module"],
filters={"for_user": "", "public": 1},
order_by="creation",
)
return {page[1]: page[0] for page in pages if page[1]}
module_workspaces = defaultdict(list)
for workspace in workspaces:
if not workspace.module:
continue
module_workspaces[workspace.module].append(workspace.name)
return module_workspaces
def get_link_groups(self):
cards = []

View file

@ -82,25 +82,33 @@ frappe.breadcrumbs = {
this.$breadcrumbs.append(html);
},
get last_route() {
return frappe.route_history.slice(-2)[0];
},
set_workspace_breadcrumb(breadcrumbs) {
// get preferred module for breadcrumbs, based on sent via module
// get preferred module for breadcrumbs, based on history and module
if (!breadcrumbs.workspace) {
this.set_workspace(breadcrumbs);
}
if (breadcrumbs.workspace) {
if (
!breadcrumbs.module_info.blocked &&
frappe.visible_modules.includes(breadcrumbs.module_info.module)
) {
$(
`<li><a href="/app/${frappe.router.slug(breadcrumbs.workspace)}">${__(
breadcrumbs.workspace
)}</a></li>`
).appendTo(this.$breadcrumbs);
}
if (!breadcrumbs.workspace) {
return;
}
if (
breadcrumbs.module_info &&
(breadcrumbs.module_info.blocked ||
!frappe.visible_modules.includes(breadcrumbs.module_info.module))
) {
return;
}
$(
`<li><a href="/app/${frappe.router.slug(breadcrumbs.workspace)}">${__(
breadcrumbs.workspace
)}</a></li>`
).appendTo(this.$breadcrumbs);
},
set_workspace(breadcrumbs) {
@ -117,6 +125,19 @@ frappe.breadcrumbs = {
breadcrumbs.module = this.preferred[breadcrumbs.doctype];
}
// guess from last route
if (this.last_route?.[0] == "Workspaces") {
let last_workspace = this.last_route[1];
if (
breadcrumbs.module &&
frappe.boot.module_wise_workspaces[breadcrumbs.module]?.includes(last_workspace)
) {
breadcrumbs.workspace = last_workspace;
return;
}
}
if (breadcrumbs.module) {
if (this.module_map[breadcrumbs.module]) {
breadcrumbs.module = this.module_map[breadcrumbs.module];
@ -125,8 +146,11 @@ frappe.breadcrumbs = {
breadcrumbs.module_info = frappe.get_module(breadcrumbs.module);
// set workspace
if (breadcrumbs.module_info && frappe.boot.module_page_map[breadcrumbs.module]) {
breadcrumbs.workspace = frappe.boot.module_page_map[breadcrumbs.module];
if (
breadcrumbs.module_info &&
frappe.boot.module_wise_workspaces[breadcrumbs.module]
) {
breadcrumbs.workspace = frappe.boot.module_wise_workspaces[breadcrumbs.module][0];
}
}
},