Просмотр исходного кода

Add support for default values from endpoint schemas

Alessandro Pilotti 8 лет назад
Родитель
Сommit
c0babfa986

+ 3 - 8
src/components/AddCloudConnection/AddCloudConnection.js

@@ -252,15 +252,10 @@ class AddCloudConnection extends Reflux.Component {
 
     cloud.endpoint.fields.forEach(field => {
       if (typeof currentCloudData[field.name] == "undefined") {
-        if (field.type == "dropdown") {
-          let defaultOption = field.options.find(function isDefaultOption(option) { return option.default; })
-          if (defaultOption) {
-            currentCloudData[field.name] = defaultOption.value;
-          } else {
-            currentCloudData[field.name] = null;
-          }
+        if (typeof field.defaultValue === 'undefined') {
+          currentCloudData[field.name] = "";
         } else {
-          currentCloudData[field.name] = ""
+          currentCloudData[field.name] = field.defaultValue.toString();
         }
       }
       if (field.required) {

+ 4 - 4
src/stores/ConnectionsStore/ConnectionsStore.js

@@ -354,8 +354,8 @@ class ConnectionsStore extends Reflux.Store
             field.type = "dropdown"
             field.options = [
               // Values need to be strings, due to a limitation in react-dropdown
-              {label: "Yes", value: "true", default: cloudData.properties[propName].default == true},
-              {label: "No", value: "false", default: cloudData.properties[propName].default == false}
+              {label: "Yes", value: "true"},
+              {label: "No", value: "false"}
             ]
 
             break
@@ -372,8 +372,7 @@ class ConnectionsStore extends Reflux.Store
                 // Values need to be strings, due to a limitation in react-dropdown
                 field.options.push({
                     label: i.toString(),
-                    value: i.toString(),
-                    default: cloudData.properties[propName].default === i
+                    value: i.toString()
                   },
                 )
               }
@@ -383,6 +382,7 @@ class ConnectionsStore extends Reflux.Store
             break
         }
 
+        field.defaultValue = cloudData.properties[propName].default;
         field.dataType = cloudData.properties[propName].type;
 
         if (field.name == 'username') {