@cubejs-client/react 0.34.2 → 0.34.19
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 +23 -10
- package/dist/cubejs-client-react.esm.js.map +1 -1
- package/dist/cubejs-client-react.js +25 -12
- package/dist/cubejs-client-react.js.map +1 -1
- package/dist/cubejs-client-react.umd.js +30 -12
- package/dist/cubejs-client-react.umd.js.map +1 -1
- package/index.d.ts +7 -0
- package/package.json +3 -3
- package/src/CubeProvider.jsx +9 -2
- package/src/hooks/cube-fetch.js +3 -3
- package/src/hooks/cube-query.js +12 -6
package/index.d.ts
CHANGED
|
@@ -457,9 +457,15 @@ declare module '@cubejs-client/react' {
|
|
|
457
457
|
|
|
458
458
|
type UseCubeQueryOptions = {
|
|
459
459
|
/**
|
|
460
|
+
* @deprecated Use the `cubeApi` option
|
|
460
461
|
* A `CubejsApi` instance to use. Taken from the context if the param is not passed
|
|
461
462
|
*/
|
|
462
463
|
cubejsApi?: CubejsApi;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* A `CubejsApi` instance to use. Taken from the context if the param is not passed
|
|
467
|
+
*/
|
|
468
|
+
cubeApi?: CubejsApi;
|
|
463
469
|
/**
|
|
464
470
|
* Query execution will be skipped when `skip` is set to `true`. You can use this flag to avoid sending incomplete queries.
|
|
465
471
|
*/
|
|
@@ -491,6 +497,7 @@ declare module '@cubejs-client/react' {
|
|
|
491
497
|
*/
|
|
492
498
|
type CubeFetchOptions = {
|
|
493
499
|
skip?: boolean;
|
|
500
|
+
cubeApi?: CubejsApi;
|
|
494
501
|
cubejsApi?: CubejsApi;
|
|
495
502
|
query?: Query;
|
|
496
503
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubejs-client/react",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.19",
|
|
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.34.
|
|
27
|
+
"@cubejs-client/core": "^0.34.19",
|
|
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": "1ed327dcd703686b4f723cb96a7298655eba186d"
|
|
46
46
|
}
|
package/src/CubeProvider.jsx
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import CubeContext from './CubeContext';
|
|
3
3
|
|
|
4
|
-
export default function CubeProvider({ cubejsApi, children, options = {} }) {
|
|
4
|
+
export default function CubeProvider({ cubeApi, cubejsApi, children, options = {} }) {
|
|
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
|
+
|
|
5
11
|
return (
|
|
6
12
|
<CubeContext.Provider value={{
|
|
7
13
|
cubejsApi,
|
|
14
|
+
cubeApi,
|
|
8
15
|
options
|
|
9
16
|
}}
|
|
10
17
|
>
|
package/src/hooks/cube-fetch.js
CHANGED
|
@@ -19,12 +19,12 @@ export function useCubeFetch(method, options = {}) {
|
|
|
19
19
|
const { skip = false } = options;
|
|
20
20
|
|
|
21
21
|
async function load(loadOptions = {}, ignoreSkip = false) {
|
|
22
|
-
const
|
|
22
|
+
const cubeApi = options.cubeApi || options.cubejsApi || context?.cubeApi || context?.cubejsApi;
|
|
23
23
|
const query = loadOptions.query || options.query;
|
|
24
24
|
|
|
25
25
|
const queryCondition = method === 'meta' ? true : query && isQueryPresent(query);
|
|
26
26
|
|
|
27
|
-
if (
|
|
27
|
+
if (cubeApi && (ignoreSkip || !skip) && queryCondition) {
|
|
28
28
|
setError(null);
|
|
29
29
|
setResponse({
|
|
30
30
|
isLoading: true,
|
|
@@ -38,7 +38,7 @@ export function useCubeFetch(method, options = {}) {
|
|
|
38
38
|
const args = method === 'meta' ? [coreOptions] : [query, coreOptions];
|
|
39
39
|
|
|
40
40
|
try {
|
|
41
|
-
const response = await
|
|
41
|
+
const response = await cubeApi[method](...args);
|
|
42
42
|
|
|
43
43
|
if (isMounted()) {
|
|
44
44
|
setResponse({
|
package/src/hooks/cube-query.js
CHANGED
|
@@ -18,12 +18,18 @@ 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]);
|
|
21
27
|
|
|
22
28
|
async function fetch() {
|
|
23
29
|
const { resetResultSetOnChange } = options;
|
|
24
|
-
const
|
|
30
|
+
const cubeApi = options.cubeApi || options.cubejsApi || context?.cubeApi || context?.cubejsApi;
|
|
25
31
|
|
|
26
|
-
if (!
|
|
32
|
+
if (!cubeApi) {
|
|
27
33
|
throw new Error('Cube API client is not provided');
|
|
28
34
|
}
|
|
29
35
|
|
|
@@ -35,7 +41,7 @@ export function useCubeQuery(query, options = {}) {
|
|
|
35
41
|
setLoading(true);
|
|
36
42
|
|
|
37
43
|
try {
|
|
38
|
-
const response = await
|
|
44
|
+
const response = await cubeApi.load(query, {
|
|
39
45
|
mutexObj: mutexRef.current,
|
|
40
46
|
mutexKey: 'query',
|
|
41
47
|
progressCallback,
|
|
@@ -62,9 +68,9 @@ export function useCubeQuery(query, options = {}) {
|
|
|
62
68
|
useEffect(() => {
|
|
63
69
|
const { skip = false, resetResultSetOnChange } = options;
|
|
64
70
|
|
|
65
|
-
const
|
|
71
|
+
const cubeApi = options.cubeApi || options.cubejsApi || context?.cubeApi || context?.cubejsApi;
|
|
66
72
|
|
|
67
|
-
if (!
|
|
73
|
+
if (!cubeApi) {
|
|
68
74
|
throw new Error('Cube API client is not provided');
|
|
69
75
|
}
|
|
70
76
|
|
|
@@ -87,7 +93,7 @@ export function useCubeQuery(query, options = {}) {
|
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
if (options.subscribe) {
|
|
90
|
-
subscribeRequest =
|
|
96
|
+
subscribeRequest = cubeApi.subscribe(
|
|
91
97
|
query,
|
|
92
98
|
{
|
|
93
99
|
mutexObj: mutexRef.current,
|