@cubejs-client/react 0.34.46 → 0.35.0
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 +27 -40
- package/dist/cubejs-client-react.esm.js.map +1 -1
- package/dist/cubejs-client-react.js +28 -41
- package/dist/cubejs-client-react.js.map +1 -1
- package/dist/cubejs-client-react.umd.js +31 -42
- package/dist/cubejs-client-react.umd.js.map +1 -1
- package/index.d.ts +22 -29
- 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,7 +39,7 @@ declare module '@cubejs-client/react' {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
type CubeProviderProps = {
|
|
42
|
-
|
|
42
|
+
cubeApi: CubeApi | null;
|
|
43
43
|
options?: CubeProviderOptions;
|
|
44
44
|
children: React.ReactNode;
|
|
45
45
|
};
|
|
@@ -48,20 +48,20 @@ declare module '@cubejs-client/react' {
|
|
|
48
48
|
* Cube.js context provider
|
|
49
49
|
* ```js
|
|
50
50
|
* import React from 'react';
|
|
51
|
-
* import
|
|
51
|
+
* import cube from '@cubejs-client/core';
|
|
52
52
|
* import { CubeProvider } from '@cubejs-client/react';
|
|
53
53
|
*
|
|
54
54
|
* const API_URL = 'https://harsh-eel.aws-us-east-2.cubecloudapp.dev';
|
|
55
|
-
* const
|
|
55
|
+
* const CUBE_TOKEN =
|
|
56
56
|
* 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.* eyJpYXQiOjE1OTE3MDcxNDgsImV4cCI6MTU5NDI5OTE0OH0.* n5jGLQJ14igg6_Hri_Autx9qOIzVqp4oYxmX27V-4T4';
|
|
57
57
|
*
|
|
58
|
-
* const
|
|
58
|
+
* const cubeApi = cube(CUBE_TOKEN, {
|
|
59
59
|
* apiUrl: `${API_URL}/cubejs-api/v1`,
|
|
60
60
|
* });
|
|
61
61
|
*
|
|
62
62
|
* export default function App() {
|
|
63
63
|
* return (
|
|
64
|
-
* <CubeProvider
|
|
64
|
+
* <CubeProvider cubeApi={cubeApi}>
|
|
65
65
|
* //...
|
|
66
66
|
* </CubeProvider>
|
|
67
67
|
* )
|
|
@@ -73,26 +73,26 @@ declare module '@cubejs-client/react' {
|
|
|
73
73
|
export const CubeProvider: React.FC<CubeProviderProps>;
|
|
74
74
|
|
|
75
75
|
type CubeContextProps = {
|
|
76
|
-
|
|
76
|
+
cubeApi: CubeApi;
|
|
77
77
|
options?: CubeProviderOptions;
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
* 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
|
|
82
82
|
*
|
|
83
83
|
* ```js
|
|
84
84
|
* import React from 'react';
|
|
85
85
|
* import { CubeContext } from '@cubejs-client/react';
|
|
86
86
|
*
|
|
87
87
|
* export default function DisplayComponent() {
|
|
88
|
-
* const {
|
|
88
|
+
* const { cubeApi } = React.useContext(CubeContext);
|
|
89
89
|
* const [rawResults, setRawResults] = React.useState([]);
|
|
90
90
|
* const query = {
|
|
91
91
|
* ...
|
|
92
92
|
* };
|
|
93
93
|
*
|
|
94
94
|
* React.useEffect(() => {
|
|
95
|
-
*
|
|
95
|
+
* cubeApi.load(query).then((resultSet) => {
|
|
96
96
|
* setRawResults(resultSet.rawData());
|
|
97
97
|
* });
|
|
98
98
|
* }, [query]);
|
|
@@ -136,9 +136,9 @@ declare module '@cubejs-client/react' {
|
|
|
136
136
|
resetResultSetOnChange?: boolean;
|
|
137
137
|
updateOnlyOnStateChange?: boolean;
|
|
138
138
|
/**
|
|
139
|
-
* `
|
|
139
|
+
* `CubeApi` instance to use
|
|
140
140
|
*/
|
|
141
|
-
|
|
141
|
+
cubeApi?: CubeApi;
|
|
142
142
|
/**
|
|
143
143
|
* Output of this function will be rendered by the `QueryRenderer`
|
|
144
144
|
*/
|
|
@@ -166,9 +166,9 @@ declare module '@cubejs-client/react' {
|
|
|
166
166
|
|
|
167
167
|
type QueryBuilderProps = {
|
|
168
168
|
/**
|
|
169
|
-
* `
|
|
169
|
+
* `CubeApi` instance to use
|
|
170
170
|
*/
|
|
171
|
-
|
|
171
|
+
cubeApi?: CubeApi;
|
|
172
172
|
/**
|
|
173
173
|
* State for the QueryBuilder to start with. Pass in the value previously saved from onVizStateChanged to restore a session.
|
|
174
174
|
*/
|
|
@@ -354,12 +354,12 @@ declare module '@cubejs-client/react' {
|
|
|
354
354
|
* import ReactDOM from 'react-dom';
|
|
355
355
|
* import { Layout, Divider, Empty, Select } from 'antd';
|
|
356
356
|
* import { QueryBuilder } from '@cubejs-client/react';
|
|
357
|
-
* import
|
|
357
|
+
* import cube from '@cubejs-client/core';
|
|
358
358
|
* import 'antd/dist/antd.css';
|
|
359
359
|
*
|
|
360
360
|
* import ChartRenderer from './ChartRenderer';
|
|
361
361
|
*
|
|
362
|
-
* const
|
|
362
|
+
* const cubeApi = cube('YOUR-CUBE-API-TOKEN', {
|
|
363
363
|
* apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
364
364
|
* });
|
|
365
365
|
*
|
|
@@ -373,7 +373,7 @@ declare module '@cubejs-client/react' {
|
|
|
373
373
|
* },
|
|
374
374
|
* ],
|
|
375
375
|
* }}
|
|
376
|
-
*
|
|
376
|
+
* cubeApi={cubeApi}
|
|
377
377
|
* render={({ resultSet, measures, availableMeasures, updateMeasures }) => (
|
|
378
378
|
* <Layout.Content style={{ padding: '20px' }}>
|
|
379
379
|
* <Select
|
|
@@ -458,15 +458,9 @@ declare module '@cubejs-client/react' {
|
|
|
458
458
|
|
|
459
459
|
type UseCubeQueryOptions = {
|
|
460
460
|
/**
|
|
461
|
-
*
|
|
462
|
-
* 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
|
|
463
462
|
*/
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* A `CubejsApi` instance to use. Taken from the context if the param is not passed
|
|
468
|
-
*/
|
|
469
|
-
cubeApi?: CubejsApi;
|
|
463
|
+
cubeApi?: CubeApi;
|
|
470
464
|
/**
|
|
471
465
|
* Query execution will be skipped when `skip` is set to `true`. You can use this flag to avoid sending incomplete queries.
|
|
472
466
|
*/
|
|
@@ -499,8 +493,7 @@ declare module '@cubejs-client/react' {
|
|
|
499
493
|
*/
|
|
500
494
|
type CubeFetchOptions = {
|
|
501
495
|
skip?: boolean;
|
|
502
|
-
cubeApi?:
|
|
503
|
-
cubejsApi?: CubejsApi;
|
|
496
|
+
cubeApi?: CubeApi;
|
|
504
497
|
query?: Query;
|
|
505
498
|
};
|
|
506
499
|
|
|
@@ -562,7 +555,7 @@ declare module '@cubejs-client/react' {
|
|
|
562
555
|
* ```js
|
|
563
556
|
* <QueryBuilder
|
|
564
557
|
* // ...
|
|
565
|
-
*
|
|
558
|
+
* cubeApi={cubeApi}
|
|
566
559
|
* render={({
|
|
567
560
|
* // ...
|
|
568
561
|
* availableMeasures,
|
|
@@ -591,7 +584,7 @@ declare module '@cubejs-client/react' {
|
|
|
591
584
|
* ```js
|
|
592
585
|
* <QueryBuilder
|
|
593
586
|
* // ...
|
|
594
|
-
*
|
|
587
|
+
* cubeApi={cubeApi}
|
|
595
588
|
* render={({
|
|
596
589
|
* // ...
|
|
597
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.0",
|
|
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.0",
|
|
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": "75bc6c3d96392b7823e714d17ac85ab435e55b05"
|
|
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');
|