@cubejs-client/react 1.7.13 → 1.7.14

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.
Files changed (62) hide show
  1. package/dist/CubeContext.d.ts +35 -0
  2. package/dist/CubeContext.d.ts.map +1 -0
  3. package/dist/CubeProvider.d.ts +31 -0
  4. package/dist/CubeProvider.d.ts.map +1 -0
  5. package/dist/QueryBuilder.d.ts +135 -0
  6. package/dist/QueryBuilder.d.ts.map +1 -0
  7. package/dist/QueryRenderer.d.ts +34 -0
  8. package/dist/QueryRenderer.d.ts.map +1 -0
  9. package/dist/QueryRendererWithTotals.d.ts +4 -0
  10. package/dist/QueryRendererWithTotals.d.ts.map +1 -0
  11. package/dist/cubejs-client-react.cjs.js +248 -23
  12. package/dist/cubejs-client-react.cjs.js.map +1 -1
  13. package/dist/cubejs-client-react.esm.js +253 -31
  14. package/dist/cubejs-client-react.esm.js.map +1 -1
  15. package/dist/cubejs-client-react.umd.js +248 -23
  16. package/dist/cubejs-client-react.umd.js.map +1 -1
  17. package/dist/hooks/cube-fetch.d.ts +6 -0
  18. package/dist/hooks/cube-fetch.d.ts.map +1 -0
  19. package/dist/hooks/cube-meta.d.ts +4 -0
  20. package/dist/hooks/cube-meta.d.ts.map +1 -0
  21. package/dist/hooks/cube-query.d.ts +39 -0
  22. package/dist/hooks/cube-query.d.ts.map +1 -0
  23. package/dist/hooks/cube-sql.d.ts +12 -0
  24. package/dist/hooks/cube-sql.d.ts.map +1 -0
  25. package/dist/hooks/deep-compare-memoize.d.ts +2 -0
  26. package/dist/hooks/deep-compare-memoize.d.ts.map +1 -0
  27. package/dist/hooks/dry-run.d.ts +7 -0
  28. package/dist/hooks/dry-run.d.ts.map +1 -0
  29. package/dist/hooks/lazy-dry-run.d.ts +7 -0
  30. package/dist/hooks/lazy-dry-run.d.ts.map +1 -0
  31. package/dist/index.d.ts +21 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/types.d.ts +765 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/utils.d.ts +2 -0
  36. package/dist/utils.d.ts.map +1 -0
  37. package/package.json +14 -10
  38. package/src/CubeContext.ts +37 -0
  39. package/src/CubeProvider.tsx +42 -0
  40. package/src/{QueryBuilder.jsx → QueryBuilder.tsx} +238 -89
  41. package/src/{QueryRenderer.jsx → QueryRenderer.tsx} +39 -14
  42. package/src/QueryRendererWithTotals.tsx +24 -0
  43. package/src/hooks/cube-fetch.ts +98 -0
  44. package/src/hooks/cube-meta.ts +8 -0
  45. package/src/hooks/{cube-query.js → cube-query.ts} +90 -14
  46. package/src/hooks/cube-sql.ts +22 -0
  47. package/src/hooks/{deep-compare-memoize.js → deep-compare-memoize.ts} +2 -2
  48. package/src/hooks/dry-run.ts +17 -0
  49. package/src/hooks/lazy-dry-run.ts +24 -0
  50. package/src/index.ts +77 -0
  51. package/src/types.ts +837 -0
  52. package/src/{utils.js → utils.ts} +3 -3
  53. package/index.d.ts +0 -697
  54. package/src/CubeContext.js +0 -3
  55. package/src/CubeProvider.jsx +0 -14
  56. package/src/QueryRendererWithTotals.jsx +0 -20
  57. package/src/hooks/cube-fetch.js +0 -66
  58. package/src/hooks/cube-meta.js +0 -5
  59. package/src/hooks/cube-sql.js +0 -8
  60. package/src/hooks/dry-run.js +0 -8
  61. package/src/hooks/lazy-dry-run.js +0 -11
  62. package/src/index.js +0 -18
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import CubeContext from './CubeContext';
3
-
4
- export default function CubeProvider({ cubeApi, children, options = {} }) {
5
- return (
6
- <CubeContext.Provider value={{
7
- cubeApi,
8
- options
9
- }}
10
- >
11
- {children}
12
- </CubeContext.Provider>
13
- );
14
- }
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import QueryRenderer from './QueryRenderer.jsx';
3
-
4
- const QueryRendererWithTotals = ({ query, ...restProps }) => (
5
- <QueryRenderer
6
- queries={{
7
- totals: {
8
- ...query,
9
- dimensions: [],
10
- timeDimensions: query.timeDimensions
11
- ? query.timeDimensions.map(td => ({ ...td, granularity: null }))
12
- : undefined
13
- },
14
- main: query
15
- }}
16
- {...restProps}
17
- />
18
- );
19
-
20
- export default QueryRendererWithTotals;
@@ -1,66 +0,0 @@
1
- import { useContext, useEffect, useState, useRef } from 'react';
2
- import { isQueryPresent } from '@cubejs-client/core';
3
-
4
- import CubeContext from '../CubeContext';
5
- import useDeepCompareMemoize from './deep-compare-memoize';
6
-
7
- export function useCubeFetch(method, options = {}) {
8
- const context = useContext(CubeContext);
9
- const mutexRef = useRef({});
10
-
11
- const [response, setResponse] = useState({
12
- isLoading: false,
13
- response: null,
14
- });
15
- const [error, setError] = useState(null);
16
-
17
- const { skip = false } = options;
18
-
19
- async function load(loadOptions = {}, ignoreSkip = false) {
20
- const cubeApi = options.cubeApi || context?.cubeApi;
21
- const query = loadOptions.query || options.query;
22
-
23
- const queryCondition =
24
- method === 'meta' ? true : query && isQueryPresent(query);
25
-
26
- if (cubeApi && (ignoreSkip || !skip) && queryCondition) {
27
- setError(null);
28
- setResponse({
29
- isLoading: true,
30
- response: null,
31
- });
32
-
33
- const coreOptions = {
34
- mutexObj: mutexRef.current,
35
- mutexKey: method,
36
- ...(options.baseRequestId ? { baseRequestId: options.baseRequestId } : {})
37
- };
38
- const args = method === 'meta' ? [coreOptions] : [query, coreOptions];
39
-
40
- try {
41
- const response = await cubeApi[method](...args);
42
-
43
- setResponse({
44
- response,
45
- isLoading: false,
46
- });
47
- } catch (error) {
48
- setError(error);
49
- setResponse({
50
- isLoading: false,
51
- response: null,
52
- });
53
- }
54
- }
55
- }
56
-
57
- useEffect(() => {
58
- load();
59
- }, useDeepCompareMemoize([Object.keys(options.query?.order || {}), options, context]));
60
-
61
- return {
62
- ...response,
63
- error,
64
- refetch: (options) => load(options, true),
65
- };
66
- }
@@ -1,5 +0,0 @@
1
- import { useCubeFetch } from './cube-fetch';
2
-
3
- export function useCubeMeta(options = {}) {
4
- return useCubeFetch('meta', options);
5
- }
@@ -1,8 +0,0 @@
1
- import { useCubeFetch } from './cube-fetch';
2
-
3
- export function useCubeSql(query, options = {}) {
4
- return useCubeFetch('sql', {
5
- ...options,
6
- query
7
- });
8
- }
@@ -1,8 +0,0 @@
1
- import { useCubeFetch } from './cube-fetch';
2
-
3
- export function useDryRun(query, options = {}) {
4
- return useCubeFetch('dryRun', {
5
- ...options,
6
- query,
7
- });
8
- }
@@ -1,11 +0,0 @@
1
- import { useCubeFetch } from './cube-fetch';
2
-
3
- export function useLazyDryRun(query, options = {}) {
4
- const { refetch, ...result } = useCubeFetch('dryRun', {
5
- ...options,
6
- query,
7
- skip: true
8
- });
9
-
10
- return [refetch, result];
11
- }
package/src/index.js DELETED
@@ -1,18 +0,0 @@
1
- import QueryRenderer from './QueryRenderer.jsx';
2
- import QueryRendererWithTotals from './QueryRendererWithTotals.jsx';
3
- import QueryBuilder from './QueryBuilder.jsx';
4
- import CubeProvider from './CubeProvider.jsx';
5
- import CubeContext from './CubeContext';
6
-
7
- export * from './hooks/cube-sql';
8
- export * from './hooks/dry-run';
9
- export * from './hooks/lazy-dry-run';
10
- export * from './hooks/cube-query';
11
- export * from './hooks/cube-meta';
12
- export {
13
- QueryRenderer,
14
- QueryRendererWithTotals,
15
- QueryBuilder,
16
- CubeContext,
17
- CubeProvider,
18
- };