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

Fixes azure endpoint addition and editing

George Vrancianu 8 лет назад
Родитель
Сommit
e168ae022d

+ 3 - 1
src/actions/ConnectionsActions/ConnectionsActions.js

@@ -128,6 +128,7 @@ ConnectionsActions.saveEndpoint.listen((data, secretRef, callback) => {
     method: "POST",
     data: payload
   }).then((response) => {
+    console.log("XXXXXXXX")
     ConnectionsActions.saveEndpoint.success(response, callback)
   }, ConnectionsActions.saveEndpoint.failed)
     .catch(ConnectionsActions.saveEndpoint.failed);
@@ -177,8 +178,9 @@ ConnectionsActions.saveEditEndpoint.listen((connection, data, callback = null) =
     method: "PUT",
     data: payload
   }).then((response) => {
+    console.log("CALLBACK", callback)
     if (typeof callback === "function") {
-      callback()
+      callback(response)
     }
     ConnectionsActions.saveEditEndpoint.success(response)
   }, ConnectionsActions.saveEditEndpoint.failed)

+ 36 - 22
src/components/AddCloudConnection/AddCloudConnection.js

@@ -68,19 +68,21 @@ class AddCloudConnection extends Reflux.Component {
       this.state.allClouds.forEach(item => {
         if (item.name === this.state.connection.type) {
           let credentials = this.state.connection.credentials
+          let newCredentials = {}
           for (let i in credentials) {
             if (typeof credentials[i] == "object") {
-              // credentials['login_type'] = i
-              credentials['user_credentials'] = {}
+              newCredentials['login_type'] = i
+              // credentials['user_credentials'] = {}
               for (let j in credentials[i]) {
-                credentials['user_credentials'][j] = credentials[i][j]
+                // credentials['user_credentials'][j] = credentials[i][j]
+                newCredentials[j] = credentials[i][j]
               }
             } else {
-              credentials[i] = credentials[i] + ""
+              newCredentials[i] = credentials[i] + ""
             }
           }
           this.setState({
-            currentCloudData: credentials,
+            currentCloudData: newCredentials,
             connectionName: this.state.connection.name,
             description: this.state.connection.description
           }, () => {
@@ -93,36 +95,22 @@ class AddCloudConnection extends Reflux.Component {
     }
   }
 
-  /**
-   * Handles change `name` property
-   * @param e
-   */
-  handleChangeName(e) {
-    this.setState({ connectionName: e.target.value })
-  }
-
-  /**
-   * Handles change `description` property
-   * @param e
-   */
-  handleChangeDescription(e) {
-    this.setState({ description: e.target.value })
-  }
-
   /**
    * Function called upon saving an endpoint - handles both new and edit operations
    */
   handleSave() {
     let valid = true
+    let requiredFields = this.state.requiredFields
 
     for (let i in this.state.currentCloudData) {
-      if (this.state.requiredFields.indexOf(i) > -1 && !this.state.currentCloudData[i]) {
+      if (requiredFields.indexOf(i) > -1 && !this.state.currentCloudData[i]) {
         valid = false
       }
     }
     if (this.state.connectionName.trim().length == 0) {
       valid = false
     }
+
     if (!valid) {
       NotificationActions.notify("Please fill all required fields", "error")
       this.setState({ cloudFormsSubmitted: true })
@@ -152,6 +140,11 @@ class AddCloudConnection extends Reflux.Component {
         }
       }
 
+      // Remove the login_type since it is not needed
+      if (this.state.currentCloud.name == "azure") {
+        delete credentials.login_type
+      }
+
       // If endpoint is new
       if (this.state.type == "new") {
         ConnectionsActions.newEndpoint({
@@ -187,6 +180,22 @@ class AddCloudConnection extends Reflux.Component {
     }
   }
 
+  /**
+   * Handles change `name` property
+   * @param e
+   */
+  handleChangeName(e) {
+    this.setState({ connectionName: e.target.value })
+  }
+
+  /**
+   * Handles change `description` property
+   * @param e
+   */
+  handleChangeDescription(e) {
+    this.setState({ description: e.target.value })
+  }
+
   /**
    * Handler to choose the cloud which the endpoint will be assigned to
    * @param cloud
@@ -356,6 +365,7 @@ class AddCloudConnection extends Reflux.Component {
       case "text":
         returnValue = (
           <div className={"form-group " + (this.isValid(field) ? "" : s.error)} key={"cloudField_" + field.name}>
+            <label>{field.label + (field.required ? " *" : "")}</label>
             <input
               type="text"
               placeholder={field.label + (field.required ? " *" : "")}
@@ -368,6 +378,7 @@ class AddCloudConnection extends Reflux.Component {
       case "password":
         returnValue = (
           <div className={"form-group " + (this.isValid(field) ? "" : s.error)} key={"cloudField_" + field.name}>
+            <label>{field.label + (field.required ? " *" : "")}</label>
             <input
               type="password"
               placeholder={field.label + (field.required ? " *" : "")}
@@ -380,6 +391,7 @@ class AddCloudConnection extends Reflux.Component {
       case "dropdown":
         returnValue = (
           <div className={"form-group " + (this.isValid(field) ? "" : s.error)} key={"cloudField_" + field.name}>
+            <label>{field.label + (field.required ? " *" : "")}</label>
             <Dropdown
               options={field.options}
               onChange={(e) => this.handleCloudFieldChange(e, field)}
@@ -443,6 +455,7 @@ class AddCloudConnection extends Reflux.Component {
         <div className={"form-group " + (this.state.cloudFormsSubmitted &&
           this.state.connectionName.trim().length == 0 ? s.error : "")}
         >
+          <label>Endpoint Name</label>
           <input
             type="text"
             placeholder="Endpoint Name *"
@@ -451,6 +464,7 @@ class AddCloudConnection extends Reflux.Component {
           />
         </div>
         <div className="form-group">
+          <label>Endpoint Description</label>
           <textarea
             placeholder="Endpoint Description"
             onChange={(e) => this.handleChangeDescription(e)}

+ 7 - 0
src/components/AddCloudConnection/AddCloudConnection.scss

@@ -40,6 +40,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
   padding: 48px 32px 32px;
   position: relative;
   :global(.form-group) {
+    &> label {
+      font-weight: 500;
+      font-size: 10px;
+      color: $task-gray-light;
+      letter-spacing: -0.33px;
+      text-transform: uppercase;
+    }
     margin-bottom: 16px;
     &:global(.switch-radio) {
       width: 100%;

+ 9 - 1
src/components/EndpointList/EndpointList.js

@@ -66,6 +66,7 @@ class EndpointList extends Reflux.Component {
 
     this.state = {
       showModal: false,
+      showValidationModal: false,
       connections: null
     }
 
@@ -101,8 +102,15 @@ class EndpointList extends Reflux.Component {
     this.setState({ showModal: false })
   }
 
+  validateConnection() {
+    this.setState({ showValidationModal: true })
+  }
+
+  closeValidationModal() {
+    this.setState({ showValidationModal: false })
+  }
+
   addHandle() {
-    this.setState({ showModal: false })
   }
 
   renderItem(item) {

+ 7 - 5
src/components/EndpointUsage/EndpointUsage.js

@@ -49,11 +49,13 @@ class EndpointUsage extends Reflux.Component {
       this.state.migrations.forEach(migration => {
         if (migration.destination_endpoint_id === this.state.connectionId ||
           migration.origin_endpoint_id === this.state.connectionId) {
-          if (migration.type == "migration") {
-            migrationCount++
-          } else {
-            replicaCount++
-          }
+          migrationCount++
+        }
+      })
+      this.state.replicas.forEach(replica => {
+        if (replica.destination_endpoint_id === this.state.connectionId ||
+          replica.origin_endpoint_id === this.state.connectionId) {
+          replicaCount++
         }
       })
       this.setState({ migrationCount: migrationCount, replicaCount: replicaCount })

+ 5 - 1
src/constants/CloudLabels.js

@@ -42,5 +42,9 @@ export const defaultLabels = {
   vm_size: "Vm size",
   location: "Location",
   resource_group: "Resource Group",
-  worker_size: "Worker Size"
+  worker_size: "Worker Size",
+  subscription_id: "Subscription ID",
+  tenant_id: "Tenant ID",
+  client_id: "Client ID",
+  client_secret: "Client Secret"
 }