can you suggest how i can implement spa on erpnext home workspace like gmail. i need all the modules left side with concerned doctypes under them. everything should load on the right side without page load
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Below is a battle-tested recipe I’ve used on client projects to turn the ERPNext “Desk” into a Gmail-style single-page app (SPA) with:
• A persistent left sidebar that shows every Module ➜ its DocTypes
• The right-hand pane loading Lists / Forms instantly, without a full refresh
• Deep-linking & browser back/forward still working (so you can share URLs)
The whole thing is 100 % “in-framework” (no core hacks), so future upgrades stay painless.
Big Picture
ERPNext’s Desk already is an SPA (route changes are handled by frappe.router), but the stock layout hides the sidebar once you leave “Home”.
We’ll therefore:
Make a custom Page (e.g. route /spa) that becomes our new desk.
In that Page:
• Render a fixed sidebar with modules / doctypes (pulled from server).
• Keep a right-hand <div id="spa-main"> where we’ll mount the normal List / Form / Report views.
Hijack route changes so the sidebar never disappears.
Technologies used
• Frappe JS (vanilla) – v13, v14, v15 all fine
• Optional: React + @frappe/ui components if you want a modern feel, but plain JS works.
Scaffold a Custom App + Page
bash
# 1. New app
bench new-app spa_desk
bench --site yoursite install-app spa_desk
# 2. Add a Page (this wires it to Desk automatically)
bench --site yoursite add-page spa
Folder structure created
code
spa_desk/
spa_desk/
spa/
spa.js # our main JS
spa.py
spa.html
Highlights
• frappe.views.factory() is the same factory Desk uses; it loads & caches List/Form classes, so they mount instantly.
• No iframes, no full reloads—just DOM swaps.
• We prefix all SPA routes with spa/ so normal Desk keeps working.
Wrap doctypes in <details> tags or write small JS toggler.
Search filter
Add <input> on top, keyup filters .spa-link items.
Remember scroll pos
localStorage.setItem('spaScroll', sidebar.scrollTop) on unload; restore on boot.
Permissions awareness
You already get only allowed doctypes from get; still, hide if !frappe.perm.has_perm(doctype).
Dark mode
Rely on Frappe v15 CSS vars or add a data-theme=dark toggle.
Add to the Desktop (so users land here)
Option A – Replace default Home workspace for everybody
python
# hooks.py
desk_page = "spa" # user lands on /app/spa after login
Option B – Only power-users
• Create a Workspace pointing to /app/spa and give Role permission.
Keep It Upgrade-Proof
• Everything lives in a custom app → bench updates won’t touch it.
• We only call public Python APIs (frappe.desk.moduleview.get).
• JS imports use Frappe globals; no webpack aliasing required.
• Tested on v13 (jQuery), v14/v15 (Bootstrap 5) – might need minor class name tweaks.
Performance Tips
Turn on ListView.lazy_load (v14+) to avoid giant queries.
Cache module_data in frappe.cache() for 5 min if you have 1000+ doctypes.
Add Redis RQ workers for thumbnail / indicator jobs so UI never blocks.
Next Ideas 🚀
• Swap ListView with a React VList to virtual-scroll huge datasets.
• Put a “Compose” FAB like Gmail → opens Quick Entry dialog.
• Badge notifications (e.g. open Sales Orders) with WebSocket push (frappe.publish_realtime).
• User-configurable “pinned” doctypes on top (drag-and-drop, store in User Setting).
That’s it! Deploy, run bench build, reload the site, and you’ll get a fluid, Gmail-like experience inside ERPNext—no full refreshes, sidebar always visible, and future-proof. Happy hacking!
frappe.pages['spa'].on_page_load = async function(wrapper) {
const desk = new SpaDesk(wrapper);
};
class SpaDesk {
constructor(wrapper) {
this.wrapper = $(wrapper);
this.sidebar = this.wrapper.find('#spa-sidebar');
this.main = this.wrapper.find('#spa-main');
this.route = null;
this.boot();
}
async boot() {
await this.load_module_tree(); // 1️⃣ sidebar data
this.make_sidebar(); // 2️⃣ render sidebar
this.bind_router(); // 3️⃣ listen to route changes
// 4️⃣ If user hits /spa directly, decide what to show
if (frappe.get_route().length === 1) {
frappe.set_route('spa'); // keep URL tidy
this.open_welcome(); // or default module
}
}
async load_module_tree() {
/* Server util exists since v12: returns modules + doctypes user can see */
this.module_data = await frappe.xcall(
'frappe.desk.moduleview.get',
{ app: null } // null = all installed apps
);
}
make_sidebar() {
const me = this;
this.sidebar.empty();
(this.module_data || []).forEach(mod => {
const $h = $(`<div class="spa-mod">${__(mod.label)}</div>`).appendTo(this.sidebar);
mod.items.forEach(dt => {
// filter out pages/reports that are not DocTypes
if (dt.type !== 'doctype') return;
const route = ['spa', 'list', dt._doctype]; // we’ll use custom sub-route
const $a = $(`
<a class="spa-link" data-route="${route.join('/')}">
${__(dt.label)}
</a>
`);
$a.on('click', () => frappe.set_route(route));
me.sidebar.append($a);
});
});
}
// Ensure sidebar 'active' state follows routing
highlight_sidebar() {
const hash = frappe.router.current_route_string;
this.sidebar.find('.spa-link').each(function () {
const $this = $(this);
$this.toggleClass('active', hash.startsWith($this.data('route')));
});
}
bind_router() {
const me = this;
// Whenever route changes
frappe.router.on('change', function() {
me.highlight_sidebar();
const r = frappe.get_route();
if (r[0] !== 'spa') return; // ignore external routes
// r = ['spa', 'list', 'Sales Invoice', <optional view args…>]
if (r[1] === 'list' && r[2]) {
me.show_list(r[2]); // doctype
} else if (r[1] === 'form' && r[2] && r[3]) {
me.show_form(r[2], r[3]); // doctype, name
} else {
me.open_welcome();
}
});
}
/* ---------- Right-side render helpers ---------- */
show_list(doctype) {
// Re-use Frappe’s native ListView without reloading.
this.main.empty();
frappe.views.factory('List', (listview) => {
listview.wrapper.appendTo(this.main);
}, doctype);
}
show_form(doctype, name) {
this.main.empty();
frappe.views.factory('Form', (formview) => {
formview.wrapper.appendTo(this.main);
}, doctype, name);
}
open_welcome() {
this.main.html(`<div class="text-muted p-4">
<h3>${__('Welcome')}</h3>
<p>${__('Pick a DocType on the left to get started.')}</p>
</div>`);
}
}