Skip to content

Commit b7f006b

Browse files
committed
fix(organizational-chart): show empty state when no data is available
Fixes #3940
1 parent 41ad15f commit b7f006b

File tree

4 files changed

+118
-16
lines changed

4 files changed

+118
-16
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import "./hierarchy_chart/hierarchy_chart_desktop.js";
22
import "./hierarchy_chart/hierarchy_chart_mobile.js";
33
import "./templates/node_card.html";
4+
import "./templates/hierarchy_empty_state.html";

hrms/public/js/hierarchy_chart/hierarchy_chart_desktop.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,12 @@ hrms.HierarchyChart = class {
1212
this.method = method;
1313
this.doctype = doctype;
1414

15-
this.setup_page_style();
1615
this.page.main.addClass("frappe-card");
1716

1817
this.nodes = {};
1918
this.setup_node_class();
2019
}
2120

22-
setup_page_style() {
23-
this.page.main.css({
24-
"min-height": "300px",
25-
"max-height": "700px",
26-
overflow: "auto",
27-
position: "relative",
28-
});
29-
}
30-
3121
setup_node_class() {
3222
let me = this;
3323
this.Node = class {
@@ -228,6 +218,15 @@ hrms.HierarchyChart = class {
228218
})
229219
.then((r) => {
230220
if (r.message.length) {
221+
me.page.body.find("#hierarchy-empty-root").remove();
222+
223+
me.page.main.css({
224+
"min-height": "300px",
225+
"max-height": "700px",
226+
overflow: "auto",
227+
position: "relative",
228+
});
229+
231230
let expand_node;
232231
let node;
233232

@@ -255,6 +254,39 @@ hrms.HierarchyChart = class {
255254
if (!expanded_view) {
256255
me.expand_node(expand_node);
257256
}
257+
} else {
258+
me.page.body.find("#hierarchy-empty-root").remove();
259+
const empty_html = frappe.render_template("hierarchy_empty_state", {
260+
doctype: me.doctype,
261+
company: me.company,
262+
can_create: frappe.model.can_create("Employee"),
263+
device_type: "desktop",
264+
});
265+
266+
$("#hierarchy-chart-wrapper").remove();
267+
me.page.body.append(empty_html);
268+
269+
me.page.main.css({
270+
"min-height": "100%",
271+
"max-height": "100%",
272+
});
273+
274+
(function () {
275+
const root = document.getElementById("hierarchy-empty-root");
276+
if (!root) return;
277+
try {
278+
const rect = root.getBoundingClientRect();
279+
const windowHeight = window.innerHeight;
280+
const height = Math.max(300, Math.floor(windowHeight - rect.top - 20));
281+
root.style.height = height + "px";
282+
root.style.overflow = "auto";
283+
root.style.position = "relative";
284+
} catch (e) {}
285+
})();
286+
me.page.body.find("#add-doc-btn").on("click", () => {
287+
frappe.route_options = { company: me.company };
288+
frappe.new_doc(me.doctype);
289+
});
258290
}
259291
});
260292
}

hrms/public/js/hierarchy_chart/hierarchy_chart_mobile.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ hrms.HierarchyChartMobile = class {
1111
this.method = method;
1212
this.doctype = doctype;
1313

14-
this.page.main.css({
15-
"min-height": "300px",
16-
"max-height": "600px",
17-
overflow: "auto",
18-
position: "relative",
19-
});
2014
this.page.main.addClass("frappe-card");
2115

2216
this.nodes = {};
@@ -155,6 +149,15 @@ hrms.HierarchyChartMobile = class {
155149
})
156150
.then((r) => {
157151
if (r.message.length) {
152+
me.page.body.find("#hierarchy-empty-root").remove();
153+
154+
me.page.main.css({
155+
"min-height": "300px",
156+
"max-height": "600px",
157+
overflow: "auto",
158+
position: "relative",
159+
});
160+
158161
let root_level = me.$hierarchy.find(".root-level");
159162
root_level.empty();
160163

@@ -171,6 +174,40 @@ hrms.HierarchyChartMobile = class {
171174
is_root: true,
172175
});
173176
});
177+
} else {
178+
me.page.body.find("#hierarchy-empty-root").remove();
179+
me.page.main.css({
180+
"min-height": "100%",
181+
"max-height": "100%",
182+
overflow: "auto",
183+
position: "relative",
184+
});
185+
186+
const empty = frappe.render_template("hierarchy_empty_state", {
187+
doctype: me.doctype,
188+
company: me.company,
189+
can_create: frappe.model.can_create(me.doctype),
190+
device_type: "mobile",
191+
});
192+
193+
me.page.main.append(empty);
194+
195+
(function () {
196+
const root = document.getElementById("hierarchy-empty-root");
197+
if (!root) return;
198+
try {
199+
const rect = root.getBoundingClientRect();
200+
const windowHeight = window.innerHeight;
201+
const height = Math.max(300, Math.floor(windowHeight - rect.top - 20));
202+
root.style.height = height + "px";
203+
root.style.overflow = "auto";
204+
root.style.position = "relative";
205+
} catch (e) {}
206+
})();
207+
me.page.body.find("#add-doc-btn").on("click", () => {
208+
frappe.route_options = { company: me.company };
209+
frappe.new_doc(me.doctype);
210+
});
174211
}
175212
});
176213
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
<div id="hierarchy-empty-root" class="text-muted flex flex-1 items-center justify-center align-center text-center">
3+
<div class="">
4+
<div class="empty-apps-state">
5+
<svg class="icon icon-xl" style="stroke: var(--text-light);">
6+
<use href="#icon-small-file"></use>
7+
</svg>
8+
<div class="mt-4 mb-2">
9+
{{ __("You haven't created a {0} for {1} yet.", [__(doctype), __(company)]) }}
10+
</div>
11+
12+
{% if can_create %}
13+
{% if device_type == "desktop" %}
14+
<button
15+
class="btn btn-default btn-sm btn-new-doc hidden-xs"
16+
id="add-doc-btn"
17+
>
18+
{{ __("Create a new {0}", [__(doctype)]) }}
19+
</button>
20+
{% else %}
21+
<button
22+
class="btn btn-primary btn-new-doc visible-xs"
23+
id="add-doc-btn"
24+
>
25+
{{ __("Create {0}", [__(doctype)]) }}
26+
</button>
27+
{% endif %}
28+
{% endif %}
29+
30+
</div>
31+
</div>
32+
</div>

0 commit comments

Comments
 (0)