Browse Source

Improve fields sorting if field is required CORWEB-62

Fix regression when cloud data is not of type 'connection'
Sergiu Miclea 8 years ago
parent
commit
838d834263
1 changed files with 13 additions and 10 deletions
  1. 13 10
      src/stores/ConnectionsStore/ConnectionsStore.js

+ 13 - 10
src/stores/ConnectionsStore/ConnectionsStore.js

@@ -301,6 +301,9 @@ class ConnectionsStore extends Reflux.Store
           }
           }
           break
           break
           case "object":
           case "object":
+            if (type !== 'connection') {
+              break
+            }
             field.value = field.name
             field.value = field.name
             field.default = true
             field.default = true
             field.fields = this.processCloud(cloudData.properties[propName])
             field.fields = this.processCloud(cloudData.properties[propName])
@@ -323,23 +326,24 @@ class ConnectionsStore extends Reflux.Store
     }
     }
 
 
     let sortPriority = {username: 1, password: 2}
     let sortPriority = {username: 1, password: 2}
-    fields.sort(function(a, b) {
+    fields.sort((a, b) => {
       if (sortPriority[a.name] && sortPriority[b.name]) {
       if (sortPriority[a.name] && sortPriority[b.name]) {
         return sortPriority[a.name] - sortPriority[b.name];
         return sortPriority[a.name] - sortPriority[b.name];
-      } else if (sortPriority[a.name]) {
+      }
+      if (sortPriority[a.name] || (a.required && !b.required)) {
         return -1
         return -1
-      } else if (sortPriority[b.name]) {
+      }
+      if (sortPriority[b.name] || (!a.required && b.required)) {
         return 1
         return 1
-      } else {
-        return 0
       }
       }
-    });
+      return 0
+    })
 
 
     // If a hierarchical structure has been generated, 
     // If a hierarchical structure has been generated, 
     // group all top level nodes (fields of type object) in a 'login_type' switch (basically multpiple login types are now supported),
     // group all top level nodes (fields of type object) in a 'login_type' switch (basically multpiple login types are now supported),
     // put all non-nodes (fields not of type object) as children of top level nodes
     // put all non-nodes (fields not of type object) as children of top level nodes
     let objectFields = fields.filter(field => field.dataType === 'object')
     let objectFields = fields.filter(field => field.dataType === 'object')
-    if (objectFields.length > 1) {
+    if (type === 'connection' && objectFields.length > 1) {
       let otherFields = fields.filter(field => field.dataType !== 'object' && field.name !== 'secret_ref')
       let otherFields = fields.filter(field => field.dataType !== 'object' && field.name !== 'secret_ref')
       let loginRadioField = {
       let loginRadioField = {
         type: "switch-radio",
         type: "switch-radio",
@@ -356,10 +360,9 @@ class ConnectionsStore extends Reflux.Store
       })
       })
 
 
       return [loginRadioField]
       return [loginRadioField]
-    } else {
-      return fields
     }
     }
-    
+
+    return fields
   }
   }
 }
 }