fix: add support for adding external urls as sidebar items

This commit is contained in:
sokumon 2025-10-28 02:47:28 +05:30
parent 51a8c48b61
commit 131d8615b7
6 changed files with 21 additions and 7 deletions

View file

@ -543,6 +543,7 @@ def get_sidebar_items():
"indent": si.indent,
"keep_closed": si.keep_closed,
"display_depends_on": si.display_depends_on,
"url": si.url,
}
if si.link_type == "Report":
report_type, ref_doctype = frappe.db.get_value(

View file

@ -13,6 +13,7 @@
"type",
"link_to",
"child",
"url",
"display_section",
"collapsible_column",
"collapsible",
@ -43,10 +44,10 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Link Type",
"options": "DocType\nPage\nReport\nWorkspace\nDashboard"
"options": "DocType\nPage\nReport\nWorkspace\nDashboard\nURL"
},
{
"depends_on": "eval: doc.type == 'Link' || doc.indent == 1",
"depends_on": "eval: doc.link_type != \"URL\" && doc.type == 'Link' || doc.indent == 1",
"fieldname": "link_to",
"fieldtype": "Dynamic Link",
"in_list_view": 1,
@ -119,13 +120,19 @@
"label": "Display Depends On (JS)",
"options": "JS",
"width": "30"
},
{
"depends_on": "eval: doc.link_type == \"URL\"",
"fieldname": "url",
"fieldtype": "Data",
"label": "URL"
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2025-10-27 23:53:14.138033",
"modified": "2025-10-28 02:05:07.887104",
"modified_by": "Administrator",
"module": "Desk",
"name": "Workspace Sidebar Item",

View file

@ -21,11 +21,12 @@ class WorkspaceSidebarItem(Document):
keep_closed: DF.Check
label: DF.Data | None
link_to: DF.DynamicLink | None
link_type: DF.Literal["DocType", "Page", "Report", "Workspace", "Dashboard"]
link_type: DF.Literal["DocType", "Page", "Report", "Workspace", "Dashboard", "URL"]
parent: DF.Data
parentfield: DF.Data
parenttype: DF.Data
type: DF.Literal["Link", "Section Break", "Spacer"]
url: DF.Data | None
# end: auto-generated types
pass

View file

@ -223,6 +223,11 @@ Tip: use lucide.svg in /icons for all downloaded icons
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="icon-layout-dashboard">
<rect width="7" height="9" x="3" y="3" rx="1" /> <rect width="7" height="5" x="14" y="3" rx="1" /> <rect width="7" height="9" x="14" y="12" rx="1" /> <rect width="7" height="5" x="3" y="16" rx="1" />
</symbol>
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="icon-graduation-cap">
<path d="M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z" /> <path d="M22 10v6" /> <path d="M6 12.5V16a6 3 0 0 0 12 0v-3.5" />
</symbol>
<symbol viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" id="icon-close-alt">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.78033 2.71967C3.48744 2.42678 3.01257 2.42678 2.71967 2.71967C2.42678 3.01256 2.42678 3.48744 2.71967 3.78033L6.94054 8.00119L2.71967 12.2221C2.42678 12.515 2.42678 12.9898 2.71967 13.2827C3.01257 13.5756 3.48744 13.5756 3.78033 13.2827L8.0012 9.06185L12.222 13.2826C12.5149 13.5755 12.9897 13.5755 13.2826 13.2826C13.5755 12.9897 13.5755 12.5148 13.2826 12.222L9.06186 8.00119L13.2826 3.78044C13.5755 3.48755 13.5755 3.01267 13.2826 2.71978C12.9897 2.42688 12.5149 2.42689 12.222 2.71978L8.0012 6.94054L3.78033 2.71967Z" fill="var(--icon-stroke)"/>
</symbol>

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB

View file

@ -17,7 +17,7 @@
{% } else { %}
<a
href="{{ path }}"
target="{%= item.type === "URL" ? "_blank" : "" %}"
target="{%= item.link_type === "URL" ? "_blank" : "" %}"
class="item-anchor"
title="{{ item.label }}"
>

View file

@ -30,14 +30,14 @@ frappe.ui.sidebar_item.TypeLink = class SidebarItem {
if (this.item.route) {
path = this.item.route;
}
} else if (this.item.link_type === "URL") {
path = this.item.url;
} else {
path = frappe.utils.generate_route({
type: this.item.link_type,
name: this.item.link_to,
});
}
} else if (this.item.type === "URL") {
path = this.item.external_link;
}
return path;
}