Przeglądaj źródła

Show 'Yes/No' as default values instead of 'true/false' for boolean fields CORWEB-68

Also fixes an issue where changing a boolean field sends 'Yes/No' to the server instead of 'true/false'.
smiclea 8 lat temu
rodzic
commit
2e638e761a

+ 8 - 2
src/components/WizardOptions/WizardOptions.js

@@ -124,7 +124,7 @@ class WizardOptions extends Reflux.Component {
   handleOptionsFieldChange(e, field) {
     let destinationEnvironment = this.state.destination_environment
     if (field.type == 'dropdown') {
-      destinationEnvironment[field.name] = e
+      destinationEnvironment[field.name] = e.value
     } else {
       destinationEnvironment[field.name] = e.target.value
     }
@@ -177,6 +177,12 @@ class WizardOptions extends Reflux.Component {
         )
         break;
       case "dropdown":
+        let value = this.state.destination_environment[field.name]
+
+        if (value) {
+          value = field.options && field.options.length && field.options.find(o => o.value === value).label
+        }
+
         returnValue = (
           <div
             className={"form-group " + extraClasses}
@@ -187,7 +193,7 @@ class WizardOptions extends Reflux.Component {
               options={field.options}
               onChange={(e) => this.handleOptionsFieldChange(e, field)}
               placeholder={field.label + (field.required ? " *" : "")}
-              value={this.state.destination_environment[field.name]}
+              value={value}
             />
           </div>
         )

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

@@ -323,12 +323,14 @@ class ConnectionsStore extends Reflux.Store
         switch (cloudData.properties[propName].type) {
           case "boolean":
             field.type = "dropdown"
+
+            // Values need to be strings, due to a limitation in react-dropdown
             field.options = [
-              // Values need to be strings, due to a limitation in react-dropdown
-              {label: "Yes", value: "true"},
-              {label: "No", value: "false"}
+              {label: 'Yes', value: 'true'}, 
+              {label: 'No', value: 'false'}
             ]
-            field.default = field.default && "true"
+
+            field.default = (field.default === 'true' || field.default === true) ? 'true' : 'false'
             break
 
           case "string":