@cubejs-client/react 0.34.60 → 0.35.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cubejs-client-react.esm.js +103 -187
- package/dist/cubejs-client-react.esm.js.map +1 -1
- package/dist/cubejs-client-react.js +153 -359
- package/dist/cubejs-client-react.js.map +1 -1
- package/dist/cubejs-client-react.umd.js +223 -576
- package/dist/cubejs-client-react.umd.js.map +1 -1
- package/index.d.ts +22 -33
- package/package.json +3 -3
- package/src/CubeProvider.jsx +2 -9
- package/src/QueryBuilder.jsx +11 -11
- package/src/QueryRenderer.jsx +12 -12
- package/src/hooks/cube-fetch.js +1 -1
- package/src/hooks/cube-query.js +2 -8
package/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
declare module '@cubejs-client/react' {
|
|
11
11
|
import * as React from 'react';
|
|
12
12
|
import {
|
|
13
|
-
|
|
13
|
+
CubeApi,
|
|
14
14
|
Query,
|
|
15
15
|
ResultSet,
|
|
16
16
|
SqlQuery,
|
|
@@ -39,11 +39,7 @@ declare module '@cubejs-client/react' {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
type CubeProviderProps = {
|
|
42
|
-
cubeApi
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated Use `cubeApi` instead
|
|
45
|
-
*/
|
|
46
|
-
cubejsApi?: CubejsApi | null;
|
|
42
|
+
cubeApi: CubeApi | null;
|
|
47
43
|
options?: CubeProviderOptions;
|
|
48
44
|
children: React.ReactNode;
|
|
49
45
|
};
|
|
@@ -52,20 +48,20 @@ declare module '@cubejs-client/react' {
|
|
|
52
48
|
* Cube.js context provider
|
|
53
49
|
* ```js
|
|
54
50
|
* import React from 'react';
|
|
55
|
-
* import
|
|
51
|
+
* import cube from '@cubejs-client/core';
|
|
56
52
|
* import { CubeProvider } from '@cubejs-client/react';
|
|
57
53
|
*
|
|
58
54
|
* const API_URL = 'https://harsh-eel.aws-us-east-2.cubecloudapp.dev';
|
|
59
|
-
* const
|
|
55
|
+
* const CUBE_TOKEN =
|
|
60
56
|
* 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.* eyJpYXQiOjE1OTE3MDcxNDgsImV4cCI6MTU5NDI5OTE0OH0.* n5jGLQJ14igg6_Hri_Autx9qOIzVqp4oYxmX27V-4T4';
|
|
61
57
|
*
|
|
62
|
-
* const
|
|
58
|
+
* const cubeApi = cube(CUBE_TOKEN, {
|
|
63
59
|
* apiUrl: `${API_URL}/cubejs-api/v1`,
|
|
64
60
|
* });
|
|
65
61
|
*
|
|
66
62
|
* export default function App() {
|
|
67
63
|
* return (
|
|
68
|
-
* <CubeProvider
|
|
64
|
+
* <CubeProvider cubeApi={cubeApi}>
|
|
69
65
|
* //...
|
|
70
66
|
* </CubeProvider>
|
|
71
67
|
* )
|
|
@@ -77,26 +73,26 @@ declare module '@cubejs-client/react' {
|
|
|
77
73
|
export const CubeProvider: React.FC<CubeProviderProps>;
|
|
78
74
|
|
|
79
75
|
type CubeContextProps = {
|
|
80
|
-
|
|
76
|
+
cubeApi: CubeApi;
|
|
81
77
|
options?: CubeProviderOptions;
|
|
82
78
|
};
|
|
83
79
|
|
|
84
80
|
/**
|
|
85
|
-
* In case when you need direct access to `
|
|
81
|
+
* In case when you need direct access to `cubeApi` you can use `CubeContext` anywhere in your app
|
|
86
82
|
*
|
|
87
83
|
* ```js
|
|
88
84
|
* import React from 'react';
|
|
89
85
|
* import { CubeContext } from '@cubejs-client/react';
|
|
90
86
|
*
|
|
91
87
|
* export default function DisplayComponent() {
|
|
92
|
-
* const {
|
|
88
|
+
* const { cubeApi } = React.useContext(CubeContext);
|
|
93
89
|
* const [rawResults, setRawResults] = React.useState([]);
|
|
94
90
|
* const query = {
|
|
95
91
|
* ...
|
|
96
92
|
* };
|
|
97
93
|
*
|
|
98
94
|
* React.useEffect(() => {
|
|
99
|
-
*
|
|
95
|
+
* cubeApi.load(query).then((resultSet) => {
|
|
100
96
|
* setRawResults(resultSet.rawData());
|
|
101
97
|
* });
|
|
102
98
|
* }, [query]);
|
|
@@ -140,9 +136,9 @@ declare module '@cubejs-client/react' {
|
|
|
140
136
|
resetResultSetOnChange?: boolean;
|
|
141
137
|
updateOnlyOnStateChange?: boolean;
|
|
142
138
|
/**
|
|
143
|
-
* `
|
|
139
|
+
* `CubeApi` instance to use
|
|
144
140
|
*/
|
|
145
|
-
|
|
141
|
+
cubeApi?: CubeApi;
|
|
146
142
|
/**
|
|
147
143
|
* Output of this function will be rendered by the `QueryRenderer`
|
|
148
144
|
*/
|
|
@@ -170,9 +166,9 @@ declare module '@cubejs-client/react' {
|
|
|
170
166
|
|
|
171
167
|
type QueryBuilderProps = {
|
|
172
168
|
/**
|
|
173
|
-
* `
|
|
169
|
+
* `CubeApi` instance to use
|
|
174
170
|
*/
|
|
175
|
-
|
|
171
|
+
cubeApi?: CubeApi;
|
|
176
172
|
/**
|
|
177
173
|
* State for the QueryBuilder to start with. Pass in the value previously saved from onVizStateChanged to restore a session.
|
|
178
174
|
*/
|
|
@@ -358,12 +354,12 @@ declare module '@cubejs-client/react' {
|
|
|
358
354
|
* import ReactDOM from 'react-dom';
|
|
359
355
|
* import { Layout, Divider, Empty, Select } from 'antd';
|
|
360
356
|
* import { QueryBuilder } from '@cubejs-client/react';
|
|
361
|
-
* import
|
|
357
|
+
* import cube from '@cubejs-client/core';
|
|
362
358
|
* import 'antd/dist/antd.css';
|
|
363
359
|
*
|
|
364
360
|
* import ChartRenderer from './ChartRenderer';
|
|
365
361
|
*
|
|
366
|
-
* const
|
|
362
|
+
* const cubeApi = cube('YOUR-CUBE-API-TOKEN', {
|
|
367
363
|
* apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
368
364
|
* });
|
|
369
365
|
*
|
|
@@ -377,7 +373,7 @@ declare module '@cubejs-client/react' {
|
|
|
377
373
|
* },
|
|
378
374
|
* ],
|
|
379
375
|
* }}
|
|
380
|
-
*
|
|
376
|
+
* cubeApi={cubeApi}
|
|
381
377
|
* render={({ resultSet, measures, availableMeasures, updateMeasures }) => (
|
|
382
378
|
* <Layout.Content style={{ padding: '20px' }}>
|
|
383
379
|
* <Select
|
|
@@ -462,15 +458,9 @@ declare module '@cubejs-client/react' {
|
|
|
462
458
|
|
|
463
459
|
type UseCubeQueryOptions = {
|
|
464
460
|
/**
|
|
465
|
-
*
|
|
466
|
-
* A `CubejsApi` instance to use. Taken from the context if the param is not passed
|
|
467
|
-
*/
|
|
468
|
-
cubejsApi?: CubejsApi;
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* A `CubejsApi` instance to use. Taken from the context if the param is not passed
|
|
461
|
+
* A `CubeApi` instance to use. Taken from the context if the param is not passed
|
|
472
462
|
*/
|
|
473
|
-
cubeApi?:
|
|
463
|
+
cubeApi?: CubeApi;
|
|
474
464
|
/**
|
|
475
465
|
* Query execution will be skipped when `skip` is set to `true`. You can use this flag to avoid sending incomplete queries.
|
|
476
466
|
*/
|
|
@@ -503,8 +493,7 @@ declare module '@cubejs-client/react' {
|
|
|
503
493
|
*/
|
|
504
494
|
type CubeFetchOptions = {
|
|
505
495
|
skip?: boolean;
|
|
506
|
-
cubeApi?:
|
|
507
|
-
cubejsApi?: CubejsApi;
|
|
496
|
+
cubeApi?: CubeApi;
|
|
508
497
|
query?: Query;
|
|
509
498
|
};
|
|
510
499
|
|
|
@@ -566,7 +555,7 @@ declare module '@cubejs-client/react' {
|
|
|
566
555
|
* ```js
|
|
567
556
|
* <QueryBuilder
|
|
568
557
|
* // ...
|
|
569
|
-
*
|
|
558
|
+
* cubeApi={cubeApi}
|
|
570
559
|
* render={({
|
|
571
560
|
* // ...
|
|
572
561
|
* availableMeasures,
|
|
@@ -595,7 +584,7 @@ declare module '@cubejs-client/react' {
|
|
|
595
584
|
* ```js
|
|
596
585
|
* <QueryBuilder
|
|
597
586
|
* // ...
|
|
598
|
-
*
|
|
587
|
+
* cubeApi={cubeApi}
|
|
599
588
|
* render={({
|
|
600
589
|
* // ...
|
|
601
590
|
* measures,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubejs-client/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.23",
|
|
4
4
|
"author": "Cube Dev, Inc.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {},
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.1.2",
|
|
27
|
-
"@cubejs-client/core": "^0.
|
|
27
|
+
"@cubejs-client/core": "^0.35.23",
|
|
28
28
|
"core-js": "^3.6.5",
|
|
29
29
|
"ramda": "^0.27.2"
|
|
30
30
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": ">=16.10.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "50ddcfc277feb55a8781129e7b3a5579e00ea334"
|
|
46
46
|
}
|
package/src/CubeProvider.jsx
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import CubeContext from './CubeContext';
|
|
3
3
|
|
|
4
|
-
export default function CubeProvider({ cubeApi,
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
if (cubejsApi && !cubeApi) {
|
|
7
|
-
console.warn('"cubejsApi" is deprecated and will be removed in the following version. Use "cubeApi" instead.');
|
|
8
|
-
}
|
|
9
|
-
}, [cubeApi, cubejsApi]);
|
|
10
|
-
|
|
4
|
+
export default function CubeProvider({ cubeApi, children, options = {} }) {
|
|
11
5
|
return (
|
|
12
6
|
<CubeContext.Provider value={{
|
|
13
|
-
cubejsApi,
|
|
14
7
|
cubeApi,
|
|
15
8
|
options
|
|
16
9
|
}}
|
package/src/QueryBuilder.jsx
CHANGED
|
@@ -33,7 +33,7 @@ export default class QueryBuilder extends React.Component {
|
|
|
33
33
|
static contextType = CubeContext;
|
|
34
34
|
|
|
35
35
|
static defaultProps = {
|
|
36
|
-
|
|
36
|
+
cubeApi: null,
|
|
37
37
|
stateChangeHeuristics: null,
|
|
38
38
|
disableHeuristics: false,
|
|
39
39
|
render: null,
|
|
@@ -136,14 +136,14 @@ export default class QueryBuilder extends React.Component {
|
|
|
136
136
|
const { schemaVersion, onSchemaChange } = this.props;
|
|
137
137
|
const { meta } = this.state;
|
|
138
138
|
|
|
139
|
-
if (this.prevContext?.
|
|
139
|
+
if (this.prevContext?.cubeApi !== this.context?.cubeApi) {
|
|
140
140
|
this.prevContext = this.context;
|
|
141
141
|
await this.fetchMeta();
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
if (prevProps.schemaVersion !== schemaVersion) {
|
|
145
145
|
try {
|
|
146
|
-
const newMeta = await this.
|
|
146
|
+
const newMeta = await this.cubeApi().meta();
|
|
147
147
|
if (!equals(newMeta, meta) && typeof onSchemaChange === 'function') {
|
|
148
148
|
onSchemaChange({
|
|
149
149
|
schemaVersion,
|
|
@@ -160,7 +160,7 @@ export default class QueryBuilder extends React.Component {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
fetchMeta = async () => {
|
|
163
|
-
if (!this.
|
|
163
|
+
if (!this.cubeApi()) {
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -171,7 +171,7 @@ export default class QueryBuilder extends React.Component {
|
|
|
171
171
|
|
|
172
172
|
try {
|
|
173
173
|
this.setState({ isFetchingMeta: true });
|
|
174
|
-
meta = await this.
|
|
174
|
+
meta = await this.cubeApi().meta();
|
|
175
175
|
} catch (error) {
|
|
176
176
|
metaError = error.response?.plainError || error;
|
|
177
177
|
richMetaError = error;
|
|
@@ -194,10 +194,10 @@ export default class QueryBuilder extends React.Component {
|
|
|
194
194
|
);
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
const {
|
|
197
|
+
cubeApi() {
|
|
198
|
+
const { cubeApi } = this.props;
|
|
199
199
|
// eslint-disable-next-line react/destructuring-assignment
|
|
200
|
-
return
|
|
200
|
+
return cubeApi || (this.context && this.context.cubeApi);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
getMissingMembers(query, meta) {
|
|
@@ -522,7 +522,7 @@ export default class QueryBuilder extends React.Component {
|
|
|
522
522
|
|
|
523
523
|
if (shouldFetchDryRun && isQueryPresent(finalState.query) && finalState.missingMembers.length === 0) {
|
|
524
524
|
try {
|
|
525
|
-
const response = await this.
|
|
525
|
+
const response = await this.cubeApi().dryRun(finalState.query, {
|
|
526
526
|
mutexObj: this.mutexObj,
|
|
527
527
|
});
|
|
528
528
|
|
|
@@ -577,13 +577,13 @@ export default class QueryBuilder extends React.Component {
|
|
|
577
577
|
|
|
578
578
|
render() {
|
|
579
579
|
const { query } = this.state;
|
|
580
|
-
const {
|
|
580
|
+
const { cubeApi, render, wrapWithQueryRenderer } = this.props;
|
|
581
581
|
|
|
582
582
|
if (wrapWithQueryRenderer) {
|
|
583
583
|
return (
|
|
584
584
|
<QueryRenderer
|
|
585
585
|
query={query}
|
|
586
|
-
|
|
586
|
+
cubeApi={cubeApi}
|
|
587
587
|
resetResultSetOnChange={false}
|
|
588
588
|
render={(queryRendererProps) => {
|
|
589
589
|
if (render) {
|
package/src/QueryRenderer.jsx
CHANGED
|
@@ -8,7 +8,7 @@ export default class QueryRenderer extends React.Component {
|
|
|
8
8
|
static contextType = CubeContext;
|
|
9
9
|
|
|
10
10
|
static defaultProps = {
|
|
11
|
-
|
|
11
|
+
cubeApi: null,
|
|
12
12
|
query: null,
|
|
13
13
|
render: null,
|
|
14
14
|
queries: null,
|
|
@@ -40,7 +40,7 @@ export default class QueryRenderer extends React.Component {
|
|
|
40
40
|
|
|
41
41
|
shouldComponentUpdate(nextProps, nextState) {
|
|
42
42
|
const {
|
|
43
|
-
query, queries, render,
|
|
43
|
+
query, queries, render, cubeApi, loadSql, updateOnlyOnStateChange
|
|
44
44
|
} = this.props;
|
|
45
45
|
if (!updateOnlyOnStateChange) {
|
|
46
46
|
return true;
|
|
@@ -48,7 +48,7 @@ export default class QueryRenderer extends React.Component {
|
|
|
48
48
|
return !equals(nextProps.query, query)
|
|
49
49
|
|| !equals(nextProps.queries, queries)
|
|
50
50
|
|| ((nextProps.render == null || render == null) && nextProps.render !== render)
|
|
51
|
-
|| nextProps.
|
|
51
|
+
|| nextProps.cubeApi !== cubeApi
|
|
52
52
|
|| nextProps.loadSql !== loadSql
|
|
53
53
|
|| !equals(nextState, this.state)
|
|
54
54
|
|| nextProps.updateOnlyOnStateChange !== updateOnlyOnStateChange;
|
|
@@ -65,9 +65,9 @@ export default class QueryRenderer extends React.Component {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
cubeApi() {
|
|
69
69
|
// eslint-disable-next-line react/destructuring-assignment
|
|
70
|
-
return this.props.
|
|
70
|
+
return this.props.cubeApi || this.context && this.context.cubeApi;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
load(query) {
|
|
@@ -79,11 +79,11 @@ export default class QueryRenderer extends React.Component {
|
|
|
79
79
|
...(resetResultSetOnChange ? { resultSet: null } : {})
|
|
80
80
|
});
|
|
81
81
|
const { loadSql } = this.props;
|
|
82
|
-
const
|
|
82
|
+
const cubeApi = this.cubeApi();
|
|
83
83
|
|
|
84
84
|
if (query && isQueryPresent(query)) {
|
|
85
85
|
if (loadSql === 'only') {
|
|
86
|
-
|
|
86
|
+
cubeApi.sql(query, { mutexObj: this.mutexObj, mutexKey: 'sql' })
|
|
87
87
|
.then(sqlQuery => this.setState({ sqlQuery, error: null, isLoading: false }))
|
|
88
88
|
.catch(error => this.setState({
|
|
89
89
|
...(resetResultSetOnChange ? { resultSet: null } : {}),
|
|
@@ -92,8 +92,8 @@ export default class QueryRenderer extends React.Component {
|
|
|
92
92
|
}));
|
|
93
93
|
} else if (loadSql) {
|
|
94
94
|
Promise.all([
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
cubeApi.sql(query, { mutexObj: this.mutexObj, mutexKey: 'sql' }),
|
|
96
|
+
cubeApi.load(query, { mutexObj: this.mutexObj, mutexKey: 'query' })
|
|
97
97
|
]).then(([sqlQuery, resultSet]) => this.setState({
|
|
98
98
|
sqlQuery, resultSet, error: null, isLoading: false
|
|
99
99
|
}))
|
|
@@ -103,7 +103,7 @@ export default class QueryRenderer extends React.Component {
|
|
|
103
103
|
isLoading: false
|
|
104
104
|
}));
|
|
105
105
|
} else {
|
|
106
|
-
|
|
106
|
+
cubeApi.load(query, { mutexObj: this.mutexObj, mutexKey: 'query' })
|
|
107
107
|
.then(resultSet => this.setState({ resultSet, error: null, isLoading: false }))
|
|
108
108
|
.catch(error => this.setState({
|
|
109
109
|
...(resetResultSetOnChange ? { resultSet: null } : {}),
|
|
@@ -115,7 +115,7 @@ export default class QueryRenderer extends React.Component {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
loadQueries(queries) {
|
|
118
|
-
const
|
|
118
|
+
const cubeApi = this.cubeApi();
|
|
119
119
|
const { resetResultSetOnChange } = this.props;
|
|
120
120
|
this.setState({
|
|
121
121
|
isLoading: true,
|
|
@@ -124,7 +124,7 @@ export default class QueryRenderer extends React.Component {
|
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
const resultPromises = Promise.all(toPairs(queries).map(
|
|
127
|
-
([name, query]) =>
|
|
127
|
+
([name, query]) => cubeApi.load(query, { mutexObj: this.mutexObj, mutexKey: name }).then(r => [name, r])
|
|
128
128
|
));
|
|
129
129
|
|
|
130
130
|
resultPromises
|
package/src/hooks/cube-fetch.js
CHANGED
|
@@ -19,7 +19,7 @@ export function useCubeFetch(method, options = {}) {
|
|
|
19
19
|
const { skip = false } = options;
|
|
20
20
|
|
|
21
21
|
async function load(loadOptions = {}, ignoreSkip = false) {
|
|
22
|
-
const cubeApi = options.cubeApi ||
|
|
22
|
+
const cubeApi = options.cubeApi || context?.cubeApi;
|
|
23
23
|
const query = loadOptions.query || options.query;
|
|
24
24
|
|
|
25
25
|
const queryCondition = method === 'meta' ? true : query && isQueryPresent(query);
|
package/src/hooks/cube-query.js
CHANGED
|
@@ -18,16 +18,10 @@ export function useCubeQuery(query, options = {}) {
|
|
|
18
18
|
let subscribeRequest = null;
|
|
19
19
|
|
|
20
20
|
const progressCallback = ({ progressResponse }) => setProgress(progressResponse);
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
if (options.cubejsApi && !options.cubeApi) {
|
|
24
|
-
console.warn('"cubejsApi" is deprecated and will be removed in the following version. Use "cubeApi" instead.');
|
|
25
|
-
}
|
|
26
|
-
}, [options.cubeApi, options.cubejsApi]);
|
|
27
21
|
|
|
28
22
|
async function fetch() {
|
|
29
23
|
const { resetResultSetOnChange } = options;
|
|
30
|
-
const cubeApi = options.cubeApi ||
|
|
24
|
+
const cubeApi = options.cubeApi || context?.cubeApi;
|
|
31
25
|
|
|
32
26
|
if (!cubeApi) {
|
|
33
27
|
throw new Error('Cube API client is not provided');
|
|
@@ -68,7 +62,7 @@ export function useCubeQuery(query, options = {}) {
|
|
|
68
62
|
useEffect(() => {
|
|
69
63
|
const { skip = false, resetResultSetOnChange } = options;
|
|
70
64
|
|
|
71
|
-
const cubeApi = options.cubeApi ||
|
|
65
|
+
const cubeApi = options.cubeApi || context?.cubeApi;
|
|
72
66
|
|
|
73
67
|
if (!cubeApi) {
|
|
74
68
|
throw new Error('Cube API client is not provided');
|