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

Add flow support to a few more files

Sergiu Miclea 8 лет назад
Родитель
Сommit
3ad4d0d1f2

+ 2 - 0
src/components/styleUtils/Palette.js

@@ -12,6 +12,8 @@ You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+// @flow
+
 const Palette = {
   primary: '#0044CB',
   primaryLight: '#000EA9',

+ 6 - 4
src/components/styleUtils/StyleProps.js

@@ -12,6 +12,8 @@ You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+// @flow
+
 import { css } from 'styled-components'
 
 const StyleProps = {
@@ -41,24 +43,24 @@ const StyleProps = {
   },
 
   media: {
-    handheld: (...args) => css`
+    handheld: (...args: any) => css`
       @media (max-height: 760px) { 
         ${css(...args)}
       }
     `,
   },
 
-  exactWidth: width => css`
+  exactWidth: (width: string) => css`
     min-width: ${width};
     max-width: ${width};
   `,
 
-  exactHeight: height => css`
+  exactHeight: (height: string) => css`
     min-height: ${height};
     max-height: ${height};
   `,
 
-  exactSize: size => css`
+  exactSize: (size: string) => css`
     ${StyleProps.exactWidth(size)}
     ${StyleProps.exactHeight(size)}
   `,

+ 19 - 8
src/sources/WizardSource.js

@@ -12,11 +12,15 @@ You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+// @flow
+
 import cookie from 'js-cookie'
 
 import Api from '../utils/ApiCaller'
 import NotificationStore from '../stores/NotificationStore'
 import { servicesUrl, executionOptions } from '../config'
+import type { WizardData } from '../types/WizardData'
+import type { MainItem } from '../types/MainItem'
 
 class WizardSourceUtils {
   static getDestinationEnv(data) {
@@ -26,6 +30,7 @@ class WizardSourceUtils {
     if (data.options) {
       Object.keys(data.options).forEach(optionName => {
         if (specialOptions.find(o => o === optionName)
+          // $FlowIssue
           || data.options[optionName] === null || data.options[optionName] === undefined) {
           return
         }
@@ -36,7 +41,7 @@ class WizardSourceUtils {
     env.network_map = {}
     if (data.networks && data.networks.length) {
       data.networks.forEach(mapping => {
-        env.network_map[mapping.sourceNic.network_name] = mapping.targetNetwork.name
+        env.network_map[mapping.sourceNic.network_name] = mapping.targetNetwork.id
       })
     }
 
@@ -45,16 +50,16 @@ class WizardSourceUtils {
 }
 
 class WizardSource {
-  static create(type, data) {
+  static create(type: string, data: WizardData): Promise<MainItem> {
     return new Promise((resolve, reject) => {
       let projectId = cookie.get('projectId')
 
       let payload = {}
       payload[type] = {
-        origin_endpoint_id: data.source.id,
-        destination_endpoint_id: data.target.id,
+        origin_endpoint_id: data.source ? data.source.id : 'null',
+        destination_endpoint_id: data.target ? data.target.id : 'null',
         destination_environment: WizardSourceUtils.getDestinationEnv(data),
-        instances: data.selectedInstances.map(i => i.instance_name),
+        instances: data.selectedInstances ? data.selectedInstances.map(i => i.instance_name) : 'null',
         notes: '',
         security_groups: ['testgroup'],
       }
@@ -64,7 +69,7 @@ class WizardSource {
       }
 
       Api.sendAjaxRequest({
-        url: `${servicesUrl.coriolis}/${projectId}/${type}s`,
+        url: `${servicesUrl.coriolis}/${projectId || 'null'}/${type}s`,
         method: 'POST',
         data: payload,
       }).then(response => {
@@ -73,17 +78,23 @@ class WizardSource {
     })
   }
 
-  static createMultiple(type, data) {
+  static createMultiple(type: string, data: WizardData): Promise<MainItem[]> {
     return new Promise((resolve, reject) => {
       let items = []
       let count = 0
 
+      if (!data.selectedInstances) {
+        reject('No selected instances')
+        return
+      }
+
       data.selectedInstances.forEach(instance => {
         let newData = { ...data }
         newData.selectedInstances = [instance]
         WizardSource.create(type, newData).then(item => {
           count += 1
           items.push(item)
+          // $FlowIssue
           if (count === data.selectedInstances.length) {
             if (items.length > 0) {
               resolve(items)
@@ -102,7 +113,7 @@ class WizardSource {
     })
   }
 
-  static setPermalink(data) {
+  static setPermalink(data: WizardData) {
     let hashExp = /(#\/wizard\/.*?)(?:\?|$)/
 
     if (!hashExp.test(window.location.hash)) {

+ 1 - 0
src/types/Network.js

@@ -18,6 +18,7 @@ import type { Nic } from './Instance'
 
 export type Network = {
   name: string,
+  id: string,
 }
 
 export type NetworkMap = {