Merge pull request #36755 from sokumon/add-to-workspace

fix(ux): create workspace
This commit is contained in:
Soham Kulkarni 2026-02-17 21:07:42 +05:30 committed by GitHub
commit 2eb1af09cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 106 additions and 15 deletions

View file

@ -147,11 +147,11 @@
"fieldname": "bg_color",
"fieldtype": "Select",
"label": "Background Color",
"options": "blue\ngray"
"options": "gray\nblue"
}
],
"links": [],
"modified": "2026-01-27 18:17:48.667070",
"modified": "2026-02-04 13:59:30.578370",
"modified_by": "Administrator",
"module": "Desk",
"name": "Desktop Icon",

View file

@ -24,7 +24,7 @@ class DesktopIcon(Document):
from frappe.types import DF
app: DF.Autocomplete | None
bg_color: DF.Literal["blue", "gray"]
bg_color: DF.Literal["gray", "blue"]
hidden: DF.Check
icon_image: DF.Attach | None
icon_type: DF.Literal["Link", "Folder", "App"]
@ -320,3 +320,24 @@ def create_user_icons(user, data):
frappe.cache.hset("_user_settings", f"{'Desktop Icon'}::{user}", json.dumps(user_settings))
return json.dumps(user_settings)
return data
@frappe.whitelist()
def add_workspace_to_desktop(workspace: str):
sidebar = frappe.new_doc("Workspace Sidebar")
sidebar_item = frappe.new_doc("Workspace Sidebar Item")
sidebar_item.label = workspace
sidebar_item.type = "Link"
sidebar_item.link_to = workspace
sidebar_item.link_type = "Workspace"
sidebar.title = workspace
sidebar.append("items", sidebar_item)
sidebar.save()
new_icon = frappe.new_doc("Desktop Icon")
new_icon.label = workspace
new_icon.icon_type = "Link"
new_icon.link_to = workspace
new_icon.link_type = "Workspace Sidebar"
new_icon.insert()
return {"icon": new_icon.as_dict()}

View file

@ -4,6 +4,7 @@
import json
import frappe
from frappe.desk.doctype.desktop_icon.desktop_icon import add_workspace_to_desktop
from frappe.model.document import Document
@ -24,7 +25,7 @@ class DesktopLayout(Document):
@frappe.whitelist()
def save_layout(user, layout, new_icons):
def save_layout(user: str, layout: str, new_icons: str):
if not user:
user = frappe.session.user
layout = json.loads(layout)
@ -42,6 +43,13 @@ def save_layout(user, layout, new_icons):
desktop_layout.save()
for icon in new_icons:
workspace = icon.get("workspace")
if workspace:
new_workspace = frappe.new_doc("Workspace")
new_workspace.update(workspace)
new_workspace.title = new_workspace.label
new_workspace.save()
return add_workspace_to_desktop(new_workspace.name)
desktop_icon = frappe.new_doc("Desktop Icon")
desktop_icon.update(icon)
desktop_icon.owner = frappe.session.user

View file

@ -8,7 +8,7 @@ frappe.ui.form.on("Workspace", {
refresh: function (frm) {
frm.enable_save();
frm.trigger("add_to_desktop");
let url = `/desk/${
frm.doc.public
? frappe.router.slug(frm.doc.title)
@ -44,6 +44,26 @@ frappe.ui.form.on("Workspace", {
frm.layout.show_message(message);
},
add_to_desktop: function (frm) {
if (frappe.app.sidebar.get_workspace_sidebars(frm.doc.title).length === 0) {
frm.add_custom_button(__("Add to Desktop"), function () {
frappe.call({
method: "frappe.desk.doctype.desktop_icon.desktop_icon.add_workspace_to_desktop",
args: {
workspace: frm.doc.name,
},
callback: function (r) {
if (r.message.status) {
frappe.toast({
message: __("Workspace added to desktop"),
indicator: "green",
});
}
},
});
});
}
},
disable_form: function (frm) {
frm.fields
.filter((field) => field.has_input)

View file

@ -125,10 +125,19 @@ class Workspace(Document):
self.name = doc.name = doc.label = doc.title
def on_trash(self):
if not self.module:
self.delete_sidebar()
self.delete_desktop_icon()
if self.public and not is_workspace_manager():
frappe.throw(_("You need to be Workspace Manager to delete a public workspace."))
self.delete_from_my_workspaces()
def delete_desktop_icon(self):
frappe.delete_doc_if_exists("Desktop Icon", self.title)
def delete_sidebar(self):
frappe.delete_doc_if_exists("Workspace Sidebar", self.title)
def delete_from_my_workspaces(self):
if self.public:
return

View file

@ -30,6 +30,9 @@ frappe.pages["desktop"].on_page_load = function (wrapper) {
// setup();
};
frappe.pages["desktop"].on_page_show = function (wrapper) {
frappe.pages["desktop"].desktop_page.update();
};
function get_workspaces_from_app_name(app_name) {
const app = frappe.boot.app_data.filter((a) => {
return a.app_title === app_name;
@ -361,23 +364,53 @@ class DesktopPage {
let grid = $($(".desktop-container .icons").get(0));
this.add_new_icon = `<div class="desktop-icon desktop-edit-mode add-new-icon" title="Add New Icon">
${frappe.utils.icon("plus", "lg")}
New Icon
<div>Workspace</div>
</div>`;
grid.append(this.add_new_icon);
$(".add-new-icon").on("click", function () {
frappe.ui.form.make_quick_entry(
"Desktop Icon",
function (icon) {
let d = new frappe.ui.Dialog({
title: "New Workspace",
fields: [
{
label: "Label",
fieldname: "label",
fieldtype: "Data",
},
{
label: "Public",
fieldname: "public",
fieldtype: "Check",
},
],
primary_action_label: "Create",
primary_action: function (values) {
let icon = frappe.model.get_new_doc("Desktop Icon");
icon.workspace = {
label: values.label,
public: values.public,
};
icon.link_type = "Workspace Sidebar";
icon.label = values.label;
frappe.new_desktop_icons.push(icon);
frappe.new_icons.push(icon);
frappe.pages["desktop"].desktop_page.update();
d.hide();
},
"",
"",
null,
true,
true
);
});
d.show();
// frappe.ui.form.make_quick_entry(
// "Desktop Icon",
// function (icon) {
// frappe.new_desktop_icons.push(icon);
// frappe.new_icons.push(icon);
// frappe.pages["desktop"].desktop_page.update();
// },
// "",
// "",
// null,
// true,
// true
// );
});
}
setup_edit_buttons() {