From 9a18ac9947604dec186c6e995122d2ed4de54ef4 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Tue, 4 Jun 2024 09:12:05 +0200 Subject: [PATCH] [IMP] queue_job: Display warning before displaying big dependency graphs --- queue_job/static/src/js/queue_job_fields.js | 21 +++++++++++++++++++ .../static/src/scss/queue_job_fields.scss | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/queue_job/static/src/js/queue_job_fields.js b/queue_job/static/src/js/queue_job_fields.js index 5aaec229d3..413878c1a0 100644 --- a/queue_job/static/src/js/queue_job_fields.js +++ b/queue_job/static/src/js/queue_job_fields.js @@ -16,6 +16,7 @@ odoo.define("queue_job.fields", function (require) { init: function () { this._super.apply(this, arguments); this.network = null; + this.forceRender = false; this.tabListenerInstalled = false; }, start: function () { @@ -88,6 +89,26 @@ odoo.define("queue_job.fields", function (require) { }); }); + if (nodes.length * edges.length > 5000 && !this.forceRender) { + const warningDiv = document.createElement("div"); + warningDiv.className = "alert alert-warning"; + warningDiv.innerText = ( + `This graph is big (${nodes.length} nodes, ` + + `${edges.length} edges), it may take a while to display.` + ); + const button = document.createElement("button"); + button.innerText = "Display anyway"; + button.className = "btn btn-secondary"; + button.onclick = function () { + self.forceRender = true; + warningDiv.parentNode.removeChild(warningDiv); + self._render(); + }; + warningDiv.appendChild(button); + this.$el.append(warningDiv); + return + } + var data = { // eslint-disable-next-line no-undef nodes: new vis.DataSet(nodes), diff --git a/queue_job/static/src/scss/queue_job_fields.scss b/queue_job/static/src/scss/queue_job_fields.scss index 150469a384..64cb6465cf 100644 --- a/queue_job/static/src/scss/queue_job_fields.scss +++ b/queue_job/static/src/scss/queue_job_fields.scss @@ -2,4 +2,11 @@ width: 600px; height: 400px; border: 1px solid lightgray; + .alert { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + } }