]> git.proxmox.com Git - pve-manager.git/commitdiff
ui: join info: code cleanup and future proof
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 7 Nov 2021 19:57:37 +0000 (20:57 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 7 Nov 2021 19:57:39 +0000 (20:57 +0100)
we may want to return null or an empty object for the join info on a
node without a cluster in the future (i.e., PVE 8.0+), so get
compatible for that now already as it costs not much and as we can
now use es2020 we even can write the object access nicer..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
www/manager6/dc/Cluster.js

index 10834b66e0f411850f83408694b94db0e8fc9d48..865bf6bcd8dfeee7b2106734ca882d0bc1d99431 100644 (file)
@@ -64,7 +64,9 @@ Ext.define('PVE.ClusterAdministration', {
 
                onLoad: function(store, records, success, operation) {
                    let vm = this.getViewModel();
-                   if (!success || !records || !records[0].data) {
+
+                   let data = records?.[0]?.data;
+                   if (!success || !data || !data.nodelist?.length) {
                        let error = operation.getError();
                        let msg = Proxmox.Utils.getResponseErrorMessage(error);
                        if (msg !== 'node is not in a cluster, no join info available! (500)') {
@@ -81,14 +83,11 @@ Ext.define('PVE.ClusterAdministration', {
                        });
                        return;
                    }
-                   let data = records[0].data;
                    vm.set('totem', data.totem);
                    vm.set('isInCluster', !!data.totem.cluster_name);
                    vm.set('nodelist', data.nodelist);
 
-                   var nodeinfo = Ext.Array.findBy(data.nodelist, function(el) {
-                       return el.name === data.preferred_node;
-                   });
+                   let nodeinfo = data.nodelist.find(el => el.name === data.preferred_node);
 
                    let links = {};
                    let ring_addr = [];