1
+ /* global window */
1
2
import React , { Component } from 'react' ;
2
3
import cubejs from '@cubejs-client/core' ;
3
4
import { fetch } from 'whatwg-fetch' ;
@@ -16,27 +17,31 @@ class ExplorePage extends Component {
16
17
const result = await res . json ( ) ;
17
18
this . setState ( {
18
19
cubejsToken : result . cubejsToken ,
19
- apiUrl : result . apiUrl
20
+ apiUrl : result . apiUrl || window . location . href . split ( '#' ) [ 0 ] . replace ( / \/ $ / , '' )
20
21
} ) ;
21
22
}
22
23
23
24
cubejsApi ( ) {
24
- if ( ! this . cubejsApiInstance && this . state . cubejsToken ) {
25
- this . cubejsApiInstance = cubejs ( this . state . cubejsToken , {
26
- apiUrl : this . state . apiUrl + '/cubejs-api/v1'
25
+ const { cubejsToken, apiUrl } = this . state ;
26
+ if ( ! this . cubejsApiInstance && cubejsToken ) {
27
+ this . cubejsApiInstance = cubejs ( cubejsToken , {
28
+ apiUrl : `${ apiUrl } /cubejs-api/v1`
27
29
} ) ;
28
30
}
29
31
return this . cubejsApiInstance ;
30
32
}
31
33
32
34
render ( ) {
33
- return this . cubejsApi ( ) && ( < PlaygroundQueryBuilder
34
- query = { { } }
35
- cubejsApi = { this . cubejsApi ( ) }
36
- apiUrl = { this . state . apiUrl }
37
- cubejsToken = { this . state . cubejsToken }
38
- dashboardSource = { this . dashboardSource }
39
- /> ) || null ;
35
+ const { cubejsToken, apiUrl } = this . state ;
36
+ return this . cubejsApi ( ) && (
37
+ < PlaygroundQueryBuilder
38
+ query = { { } }
39
+ cubejsApi = { this . cubejsApi ( ) }
40
+ apiUrl = { apiUrl }
41
+ cubejsToken = { cubejsToken }
42
+ dashboardSource = { this . dashboardSource }
43
+ />
44
+ ) || null ;
40
45
}
41
46
}
42
47
0 commit comments