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

Cleans up code mocks, simplifies if statements, removes unused imports and variables CORWEB-26

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

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

@@ -177,7 +177,6 @@ ConnectionsActions.saveEditEndpoint.listen((connection, data, callback = null) =
     method: "PUT",
     data: payload
   }).then((response) => {
-    console.log("CALLBACK", callback)
     if (typeof callback === "function") {
       callback(response)
     }

+ 2 - 9
src/actions/MigrationActions/MigrationActions.js

@@ -52,10 +52,7 @@ MigrationActions.loadMigrations.listen(() => {
 
 MigrationActions.loadMigrations.shouldEmit = () => {
   let projectId = Reflux.GlobalState.userStore.currentUser.project.id
-  if (typeof projectId === "undefined") {
-    return false
-  }
-  return true
+  return typeof projectId !== "undefined";
 }
 
 MigrationActions.loadReplicas.listen(() => {
@@ -70,11 +67,7 @@ MigrationActions.loadReplicas.listen(() => {
 
 MigrationActions.loadReplicas.shouldEmit = () => {
   let projectId = Reflux.GlobalState.userStore.currentUser.project.id
-  if (typeof projectId === "undefined") {
-    return false
-  }
-
-  return true
+  return typeof projectId !== "undefined";
 }
 
 MigrationActions.loadMigration.listen((migration) => {

+ 1 - 5
src/components/AddCloudConnection/AddCloudConnection.js

@@ -337,11 +337,7 @@ class AddCloudConnection extends Reflux.Component {
   isValid(field) {
     if (field.required && this.state.cloudFormsSubmitted) {
       if (this.state.currentCloudData[field.name]) {
-        if (this.state.currentCloudData[field.name] && this.state.currentCloudData[field.name].length == 0) {
-          return false
-        } else {
-          return true
-        }
+        return !(this.state.currentCloudData[field.name] && this.state.currentCloudData[field.name].length == 0);
       } else {
         return false
       }

+ 3 - 3
src/components/ApiCaller/ApiCaller.js

@@ -16,7 +16,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 /* eslint-disable */
 
-import React, { Component } from 'react';
+import React from 'react';
 import NotificationActions from '../../actions/NotificationActions';
 import Location from '../../core/Location';
 
@@ -45,12 +45,12 @@ class ApiCaller {
       let headers = Object.assign({}, this.defaultHeaders)
 
       if (options.headers) {
-        for (var key in options.headers) {
+        for (let key in options.headers) {
           headers[key] = options.headers[key]
         }
       }
 
-      for (name in headers) {
+      for (let name in headers) {
         request.setRequestHeader(name, headers[name])
       }
 

+ 1 - 5
src/components/EditProfile/EditProfile.js

@@ -100,11 +100,7 @@ class EditProfile extends Component {
 
   isValid(field) {
     if (field.required && this.state.formSubmitted) {
-      if (this.state.currentCloudData[field.name].length == 0) {
-        return false
-      } else {
-        return true
-      }
+      return this.state.currentCloudData[field.name].length != 0;
     } else {
       return true
     }

+ 0 - 1
src/components/TextBox/TextBox.js

@@ -17,7 +17,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /* eslint-disable */
 
 import React, { Component, PropTypes } from 'react';
-import withStyles from 'isomorphic-style-loader/lib/withStyles';
 import s from './TextBox.scss';
 
 class TextBox extends Component {

+ 1 - 5
src/components/WizardOptions/WizardOptions.js

@@ -91,11 +91,7 @@ class WizardOptions extends Reflux.Component {
       if (!this.state.destination_environment[field.name]) {
         return false
       } else {
-        if (this.state.destination_environment[field.name].trim().length == 0) {
-          return false
-        } else {
-          return true
-        }
+        return this.state.destination_environment[field.name].trim().length != 0;
       }
     } else {
       return true

+ 5 - 44
src/stores/ConnectionsStore/ConnectionsStore.js

@@ -18,10 +18,9 @@
  */
 
 
-import React, { Component, PropTypes } from 'react';
+import React from 'react';
 import Reflux from 'reflux';
 import ConnectionsActions from '../../actions/ConnectionsActions';
-import WizardActions from '../../actions/WizardActions';
 import MigrationActions from '../../actions/MigrationActions';
 import { defaultLabels } from '../../constants/CloudLabels';
 import Api from '../../components/ApiCaller'
@@ -29,41 +28,6 @@ import {servicesUrl, providerType} from '../../config';
 
 class ConnectionsStore extends Reflux.Store
 {
-  connections = [
-    {
-      id: "vSphere-Cluster",
-      name: "vSphere-Cluster",
-      description: "",
-      created: new Date(),
-      cloudName: "vmware",
-      secretUrl: null,
-      credentials: {
-
-      }
-    },
-    {
-      id: "vSphere-Cluster2",
-      name: "vSphere-Cluster2",
-      description: "",
-      created: new Date(),
-      cloudName: "vmware",
-      secretUrl: null,
-      credentials: {
-
-      }
-    },
-    {
-      id: "azure-Cluster",
-      name: "Azure-Cluster",
-      description: "",
-      created: new Date(),
-      cloudName: "azure",
-      secretUrl: null,
-      credentials: {
-
-      }
-    }
-  ]
 
   constructor()
   {
@@ -84,7 +48,7 @@ class ConnectionsStore extends Reflux.Store
     let clouds = []
     if (response.data.providers) {
       let providers = response.data.providers
-      for (var provider in providers) {
+      for (let provider in providers) {
         let cloud = {
           name: provider,
           credentialSelected: null,
@@ -139,7 +103,7 @@ class ConnectionsStore extends Reflux.Store
 
   onUpdateProvider(provider) {
     let allClouds = this.state.allClouds
-    for (var i in allClouds) {
+    for (let i in allClouds) {
       if (allClouds[i].name == provider.name) {
         allClouds[i] = provider
       }
@@ -152,7 +116,7 @@ class ConnectionsStore extends Reflux.Store
       return false
     } else {
       let allClouds = this.state.allClouds
-      for (var i in allClouds) {
+      for (let i in allClouds) {
         allClouds[i].credentials = []
         this.state.connections.forEach(connection => {
           if (connection.type == allClouds[i].name) {
@@ -296,9 +260,6 @@ class ConnectionsStore extends Reflux.Store
     }
 
     if (providerName == "azure" && type == "connection") {
-      let subscriptionId = {
-        subscription_id: cloudData.properties.subscription_id
-      }
       let userCredentialFields = {
         properties: { subscription_id: cloudData.properties.subscription_id },
         required: cloudData.properties.user_credentials.required
@@ -340,7 +301,7 @@ class ConnectionsStore extends Reflux.Store
     } else {
       let fields = []
       let sortedFields = [{}, {}]
-      for (var propName in cloudData.properties) {
+      for (let propName in cloudData.properties) {
         let field = {
           name: propName,
           label: defaultLabels[propName] ? defaultLabels[propName] : propName