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

Remove cookie dependencies from all 'Source' files

Project ID is no longer retrieved from cookies in all 'Source' files,
instead it is retrieved from the API Caller class, which now handles the
retrieval of project ID from cookies. This allows having one place where
cookie retrieval and validation happens.

Includes an update to a unit test.
Sergiu Miclea 7 лет назад
Родитель
Сommit
6e7c6c1b60

+ 5 - 1
src/components/organisms/DetailsPageHeader/DetailsPageHeader.jsx

@@ -42,7 +42,7 @@ const Logo = styled.a`
   background: url('${logoImage}') no-repeat;
   cursor: pointer;
 `
-const UserDropdownStyled = styled(UserDropdown) `
+const UserDropdownStyled = styled(UserDropdown)`
   margin-left: 16px;
 `
 const Menu = styled.div`
@@ -57,10 +57,14 @@ const User = styled.div`
 type Props = {
   user?: ?UserType,
   onUserItemClick: (userItem: { label: string, value: string }) => void,
+  testMode?: boolean,
 }
 @observer
 export class DetailsPageHeader extends React.Component<Props> {
   componentDidMount() {
+    if (this.props.testMode) {
+      return
+    }
     notificationStore.loadNotifications()
   }
 

+ 13 - 3
src/components/organisms/DetailsPageHeader/test.jsx

@@ -18,16 +18,26 @@ import React from 'react'
 import { shallow } from 'enzyme'
 import sinon from 'sinon'
 import TW from '../../../utils/TestWrapper'
+import type { User } from '../../../types/User'
 import { DetailsPageHeader } from '.'
 
-const wrap = props => new TW(shallow(
-  // $FlowIgnore
-  <DetailsPageHeader notificationStore={{}} {...props} />
+type Props = {
+  user?: ?User,
+}
+
+const wrap = (props: Props) => new TW(shallow(
+  <DetailsPageHeader
+    onUserItemClick={() => { }}
+    testMode
+    {...props}
+  />
 ), 'dpHeader')
 
 let user = {
   name: 'User name',
   email: 'email@email.com',
+  id: 'user',
+  project: { id: '', name: '' },
 }
 
 describe('DetailsPageHeader Component', () => {

+ 1 - 4
src/sources/AssessmentSource.js

@@ -14,8 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 
-import cookie from 'js-cookie'
-
 import type { MigrationInfo } from '../types/Assessment'
 import type { MainItem } from '../types/MainItem'
 import Api from '../utils/ApiCaller'
@@ -38,7 +36,6 @@ class AssessmentSourceUtils {
 
 class AssessmentSource {
   static migrate(data: MigrationInfo): Promise<MainItem> {
-    let projectId = cookie.get('projectId')
     let useReplicaField = data.options.find(o => o.name === 'use_replica')
     let type = useReplicaField && useReplicaField.value ? 'replica' : 'migration'
     let payload = {}
@@ -61,7 +58,7 @@ class AssessmentSource {
     })
 
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/${type}s`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/${type}s`,
       method: 'POST',
       data: payload,
     }).then(response => {

+ 16 - 26
src/sources/EndpointSource.js

@@ -14,7 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 
-import cookie from 'js-cookie'
 import moment from 'moment'
 
 import Api from '../utils/ApiCaller'
@@ -39,27 +38,21 @@ let getBarbicanPayload = data => {
 
 class EdnpointSource {
   static getEndpoints(): Promise<Endpoint[]> {
-    let projectId = cookie.get('projectId')
-    if (projectId) {
-      return Api.get(`${servicesUrl.coriolis}/${projectId}/endpoints`).then(response => {
-        let connections = []
-        if (response.data.endpoints.length) {
-          response.data.endpoints.forEach(endpoint => {
-            connections.push(endpoint)
-          })
-        }
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/endpoints`).then(response => {
+      let connections = []
+      if (response.data.endpoints.length) {
+        response.data.endpoints.forEach(endpoint => {
+          connections.push(endpoint)
+        })
+      }
 
-        connections.sort((c1, c2) => moment(c2.created_at).diff(moment(c1.created_at)))
-        return connections
-      })
-    }
-    return Promise.reject('No Project ID!')
+      connections.sort((c1, c2) => moment(c2.created_at).diff(moment(c1.created_at)))
+      return connections
+    })
   }
   static delete(endpoint: Endpoint): Promise<string> {
-    let projectId: any = cookie.get('projectId')
-
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId}/endpoints/${endpoint.id}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}`,
       method: 'DELETE',
     }).then(() => {
       if (endpoint.connection_info && endpoint.connection_info.secret_ref) {
@@ -107,9 +100,8 @@ class EdnpointSource {
   }
 
   static validate(endpoint: Endpoint): Promise<Validation> {
-    let projectId = cookie.get('projectId')
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints/${endpoint.id}/actions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}/actions`,
       method: 'POST',
       data: { 'validate-connection': null },
     }).then(response => {
@@ -118,7 +110,6 @@ class EdnpointSource {
   }
 
   static update(endpoint: Endpoint): Promise<Endpoint> {
-    let projectId = cookie.get('projectId')
     let parsedEndpoint = SchemaParser.fieldsToPayload(endpoint)
 
     if (parsedEndpoint.connection_info && parsedEndpoint.connection_info.secret_ref) {
@@ -147,7 +138,7 @@ class EdnpointSource {
           },
         }
         return Api.send({
-          url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints/${endpoint.id}`,
+          url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}`,
           method: 'PUT',
           data: newPayload,
         })
@@ -171,7 +162,7 @@ class EdnpointSource {
     }
 
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints/${endpoint.id}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}`,
       method: 'PUT',
       data: { endpoint: parsedEndpoint },
     }).then(response => {
@@ -181,7 +172,6 @@ class EdnpointSource {
 
   static add(endpoint: Endpoint, skipSchemaParser: boolean = false): Promise<Endpoint> {
     let parsedEndpoint = skipSchemaParser ? { ...endpoint } : SchemaParser.fieldsToPayload(endpoint)
-    let projectId = cookie.get('projectId')
     let newEndpoint: any = {}
     let connectionInfo = {}
     if (useSecret) {
@@ -200,7 +190,7 @@ class EdnpointSource {
           },
         }
         return Api.send({
-          url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints`,
+          url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints`,
           method: 'POST',
           data: newPayload,
         })
@@ -224,7 +214,7 @@ class EdnpointSource {
     }
 
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints`,
       method: 'POST',
       data: { endpoint: parsedEndpoint },
     }).then(response => {

+ 2 - 7
src/sources/InstanceSource.js

@@ -14,8 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 
-import cookie from 'js-cookie'
-
 import Api from '../utils/ApiCaller'
 import type { Instance } from '../types/Instance'
 
@@ -30,8 +28,7 @@ class InstanceSource {
       this.lastEndpointId = endpointId
     }
 
-    let projectId = cookie.get('projectId')
-    let url = `${servicesUrl.coriolis}/${projectId || 'null'}/endpoints/${endpointId}/instances`
+    let url = `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpointId}/instances`
     let symbol = '?'
 
     if (!skipLimit) {
@@ -54,10 +51,8 @@ class InstanceSource {
   }
 
   static loadInstanceDetails(endpointId: string, instanceName: string, reqId: number): Promise<{ instance: Instance, reqId: number }> {
-    let projectId = cookie.get('projectId') || 'undefined'
-
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId}/endpoints/${endpointId}/instances/${btoa(instanceName)}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpointId}/instances/${btoa(instanceName)}`,
       cancelId: `instanceDetail-${reqId}`,
     }).then(response => {
       return { instance: response.data.instance, reqId }

+ 5 - 13
src/sources/MigrationSource.js

@@ -14,7 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 
-import cookie from 'js-cookie'
 import moment from 'moment'
 
 import Api from '../utils/ApiCaller'
@@ -51,8 +50,7 @@ class MigrationSourceUtils {
 
 class MigrationSource {
   static getMigrations(): Promise<MainItem[]> {
-    let projectId = cookie.get('projectId') || 'null'
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/migrations/detail`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/migrations/detail`).then(response => {
       let migrations = response.data.migrations
       MigrationSourceUtils.sortMigrations(migrations)
       return migrations
@@ -60,9 +58,7 @@ class MigrationSource {
   }
 
   static getMigration(migrationId: string): Promise<MainItem> {
-    let projectId = cookie.get('projectId') || 'null'
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/migrations/${migrationId}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/migrations/${migrationId}`).then(response => {
       let migration = response.data.migration
       MigrationSourceUtils.sortTaskUpdates(migration)
       return migration
@@ -70,25 +66,21 @@ class MigrationSource {
   }
 
   static cancel(migrationId: string): Promise<string> {
-    let projectId = cookie.get('projectId') || 'null'
-
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId}/migrations/${migrationId}/actions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/migrations/${migrationId}/actions`,
       method: 'POST',
       data: { cancel: null },
     }).then(() => migrationId)
   }
 
   static delete(migrationId: string): Promise<string> {
-    let projectId = cookie.get('projectId')
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/migrations/${migrationId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/migrations/${migrationId}`,
       method: 'DELETE',
     }).then(() => migrationId)
   }
 
   static migrateReplica(replicaId: string, options: Field[]): Promise<MainItem> {
-    let projectId = cookie.get('projectId')
     let payload = {
       migration: {
         replica_id: replicaId,
@@ -99,7 +91,7 @@ class MigrationSource {
     })
 
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/migrations`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/migrations`,
       method: 'POST',
       data: payload,
     }).then(response => response.data.migration)

+ 1 - 4
src/sources/NetworkSource.js

@@ -14,8 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 
-import cookie from 'js-cookie'
-
 import Api from '../utils/ApiCaller'
 import type { Network } from '../types/Network'
 
@@ -23,8 +21,7 @@ import { servicesUrl } from '../config'
 
 class NetworkSource {
   static loadNetworks(enpointId: string, environment: ?{ [string]: mixed }): Promise<Network[]> {
-    let projectId = cookie.get('projectId')
-    let url = `${servicesUrl.coriolis}/${projectId || 'null'}/endpoints/${enpointId}/networks`
+    let url = `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${enpointId}/networks`
     if (environment) {
       url = `${url}?env=${btoa(JSON.stringify(environment))}`
     }

+ 1 - 0
src/sources/NotificationSource.js

@@ -16,6 +16,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import type { NotificationItem } from '../types/NotificationItem'
 
+
 class NotificationSource {
   static notify(message: string, level?: $PropertyType<NotificationItem, 'level'>, options?: $PropertyType<NotificationItem, 'options'>): Promise<NotificationItem> {
     let notifications = JSON.parse(localStorage.getItem('notifications') || '[]')

+ 4 - 12
src/sources/ProviderSource.js

@@ -14,8 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 
-import cookie from 'js-cookie'
-
 import Api from '../utils/ApiCaller'
 import { servicesUrl, providerTypes } from '../config'
 import { SchemaParser } from './Schemas'
@@ -25,9 +23,7 @@ import type { DestinationOption } from '../types/Endpoint'
 
 class ProviderSource {
   static getConnectionInfoSchema(providerName: string): Promise<Field[]> {
-    let projectId = cookie.get('projectId')
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/providers/${providerName}/schemas/${providerTypes.CONNECTION}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/providers/${providerName}/schemas/${providerTypes.CONNECTION}`).then(response => {
       let schema = response.data.schemas.connection_info_schema
       schema = SchemaParser.connectionSchemaToFields(providerName, schema)
       return schema
@@ -35,17 +31,14 @@ class ProviderSource {
   }
 
   static loadProviders(): Promise<Providers> {
-    let projectId = cookie.get('projectId')
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/providers`)
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/providers`)
       .then(response => response.data.providers)
   }
 
   static loadOptionsSchema(providerName: string, schemaType: string): Promise<Field[]> {
-    let projectId = cookie.get('projectId')
     let schemaTypeInt = schemaType === 'migration' ? providerTypes.TARGET_MIGRATION : providerTypes.TARGET_REPLICA
 
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/providers/${providerName}/schemas/${schemaTypeInt}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/providers/${providerName}/schemas/${schemaTypeInt}`).then(response => {
       let schema = response.data.schemas.destination_environment_schema
       let fields = SchemaParser.optionsSchemaToFields(providerName, schema)
       return fields
@@ -53,13 +46,12 @@ class ProviderSource {
   }
 
   static getDestinationOptions(endpointId: string, envData: ?{ [string]: mixed }): Promise<DestinationOption[]> {
-    let projectId = cookie.get('projectId')
     let envString = ''
     if (envData) {
       envString = `?env=${btoa(JSON.stringify(envData))}`
     }
 
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/endpoints/${endpointId}/destination-options${envString}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpointId}/destination-options${envString}`).then(response => {
       let options = response.data.destination_options
       return options
     })

+ 8 - 23
src/sources/ReplicaSource.js

@@ -14,7 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 
-import cookie from 'js-cookie'
 import moment from 'moment'
 
 import Api from '../utils/ApiCaller'
@@ -85,8 +84,7 @@ class ReplicaSourceUtils {
 
 class ReplicaSource {
   static getReplicas(): Promise<MainItem[]> {
-    let projectId = cookie.get('projectId') || 'undefined'
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/replicas/detail`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/replicas/detail`).then(response => {
       let replicas = response.data.replicas
       replicas = ReplicaSourceUtils.filterDeletedExecutionsInReplicas(replicas)
       ReplicaSourceUtils.sortReplicas(replicas)
@@ -95,8 +93,7 @@ class ReplicaSource {
   }
 
   static getReplicaExecutions(replicaId: string): Promise<Execution[]> {
-    let projectId = cookie.get('projectId') || 'undefined'
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/replicas/${replicaId}/executions/detail`).then((response) => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/executions/detail`).then((response) => {
       let executions = response.data.executions
       ReplicaSourceUtils.sortExecutionsAndTaskUpdates(executions)
 
@@ -105,9 +102,7 @@ class ReplicaSource {
   }
 
   static getReplica(replicaId: string): Promise<MainItem> {
-    let projectId = cookie.get('projectId') || 'undefined'
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/replicas/${replicaId}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}`).then(response => {
       let replica = response.data.replica
       replica.executions = ReplicaSourceUtils.filterDeletedExecutions(replica.executions)
       ReplicaSourceUtils.sortExecutions(replica.executions)
@@ -122,10 +117,8 @@ class ReplicaSource {
         payload.execution[f.name] = f.value || false
       })
     }
-    let projectId = cookie.get('projectId') || 'undefined'
-
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId}/replicas/${replicaId}/executions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/executions`,
       method: 'POST',
       data: payload,
     }).then((response) => {
@@ -136,38 +129,30 @@ class ReplicaSource {
   }
 
   static cancelExecution(replicaId: string, executionId: string): Promise<string> {
-    let projectId = cookie.get('projectId')
-
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/executions/${executionId}/actions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/executions/${executionId}/actions`,
       method: 'POST',
       data: { cancel: null },
     }).then(() => replicaId)
   }
 
   static deleteExecution(replicaId: string, executionId: string): Promise<string> {
-    let projectId = cookie.get('projectId')
-
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/executions/${executionId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/executions/${executionId}`,
       method: 'DELETE',
     }).then(() => replicaId)
   }
 
   static delete(replicaId: string): Promise<string> {
-    let projectId = cookie.get('projectId')
-
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}`,
       method: 'DELETE',
     }).then(() => replicaId)
   }
 
   static deleteDisks(replicaId: string): Promise<Execution> {
-    let projectId = cookie.get('projectId')
-
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/actions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/actions`,
       method: 'POST',
       data: { 'delete-disks': null },
     }).then(response => response.data.execution)

+ 5 - 12
src/sources/ScheduleSource.js

@@ -14,7 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 
-import cookie from 'js-cookie'
 import moment from 'moment'
 
 import Api from '../utils/ApiCaller'
@@ -24,7 +23,6 @@ import type { Schedule } from '../types/Schedule'
 
 class ScheduleSource {
   static scheduleSinge(replicaId: string, scheduleData: Schedule): Promise<Schedule> {
-    let projectId = cookie.get('projectId')
     let payload = {
       schedule: {},
       expiration_date: null,
@@ -47,7 +45,7 @@ class ScheduleSource {
     }
 
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules`,
       method: 'POST',
       data: payload,
     }).then(response => response.data.schedule)
@@ -60,9 +58,7 @@ class ScheduleSource {
   }
 
   static getSchedules(replicaId: string): Promise<Schedule[]> {
-    let projectId = cookie.get('projectId')
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules`).then(response => {
       let schedules = [...response.data.schedules]
       schedules.forEach(s => {
         if (s.expiration_date) {
@@ -78,7 +74,6 @@ class ScheduleSource {
   }
 
   static addSchedule(replicaId: string, schedule: Schedule): Promise<Schedule> {
-    let projectId = cookie.get('projectId')
     let payload = {
       schedule: { hour: 0, minute: 0 },
       enabled: false,
@@ -88,16 +83,15 @@ class ScheduleSource {
     }
 
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules`,
       method: 'POST',
       data: payload,
     }).then(response => response.data.schedule)
   }
 
   static removeSchedule(replicaId: string, scheduleId: string): Promise<void> {
-    let projectId = cookie.get('projectId')
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules/${scheduleId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules/${scheduleId}`,
       method: 'DELETE',
     }).then(() => { })
   }
@@ -109,7 +103,6 @@ class ScheduleSource {
     scheduleOldData: ?Schedule,
     unsavedData: ?Schedule
   ): Promise<Schedule> {
-    let projectId = cookie.get('projectId')
     let payload = {}
     if (scheduleData.enabled !== null && scheduleData.enabled !== undefined) {
       payload.enabled = scheduleData.enabled
@@ -136,7 +129,7 @@ class ScheduleSource {
     }
 
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules/${scheduleId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules/${scheduleId}`,
       method: 'PUT',
       data: payload,
     }).then(response => {

+ 1 - 5
src/sources/WizardSource.js

@@ -14,8 +14,6 @@ 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 { OptionsSchemaPlugin } from '../plugins/endpoint'
@@ -26,8 +24,6 @@ import type { MainItem } from '../types/MainItem'
 
 class WizardSource {
   static create(type: string, data: WizardData): Promise<MainItem> {
-    let projectId = cookie.get('projectId')
-
     const parser = data.target ? OptionsSchemaPlugin[data.target.type] || OptionsSchemaPlugin.default : OptionsSchemaPlugin.default
     let payload = {}
     payload[type] = {
@@ -43,7 +39,7 @@ class WizardSource {
     }
 
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/${type}s`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/${type}s`,
       method: 'POST',
       data: payload,
     }).then(response => response.data[type])

+ 5 - 0
src/utils/ApiCaller.js

@@ -16,6 +16,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import axios from 'axios'
 import type { AxiosXHRConfig, $AxiosXHR } from 'axios'
+import cookie from 'js-cookie'
 
 import notificationStore from '../stores/NotificationStore'
 
@@ -49,6 +50,10 @@ class ApiCaller {
     axios.defaults.headers.common['Content-Type'] = 'application/json'
   }
 
+  get projectId(): string {
+    return cookie.get('projectId') || 'undefined'
+  }
+
   cancelRequests(cancelRequestId: string) {
     const filteredCancelables = cancelables.filter(r => r.requestId === cancelRequestId)
     filteredCancelables.forEach(c => {