@cubejs-client/react 1.7.13 → 1.7.15
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/CubeContext.d.ts +35 -0
- package/dist/CubeContext.d.ts.map +1 -0
- package/dist/CubeProvider.d.ts +31 -0
- package/dist/CubeProvider.d.ts.map +1 -0
- package/dist/QueryBuilder.d.ts +135 -0
- package/dist/QueryBuilder.d.ts.map +1 -0
- package/dist/QueryRenderer.d.ts +34 -0
- package/dist/QueryRenderer.d.ts.map +1 -0
- package/dist/QueryRendererWithTotals.d.ts +4 -0
- package/dist/QueryRendererWithTotals.d.ts.map +1 -0
- package/dist/cubejs-client-react.cjs.js +248 -23
- package/dist/cubejs-client-react.cjs.js.map +1 -1
- package/dist/cubejs-client-react.esm.js +253 -31
- package/dist/cubejs-client-react.esm.js.map +1 -1
- package/dist/cubejs-client-react.umd.js +248 -23
- package/dist/cubejs-client-react.umd.js.map +1 -1
- package/dist/hooks/cube-fetch.d.ts +6 -0
- package/dist/hooks/cube-fetch.d.ts.map +1 -0
- package/dist/hooks/cube-meta.d.ts +4 -0
- package/dist/hooks/cube-meta.d.ts.map +1 -0
- package/dist/hooks/cube-query.d.ts +39 -0
- package/dist/hooks/cube-query.d.ts.map +1 -0
- package/dist/hooks/cube-sql.d.ts +12 -0
- package/dist/hooks/cube-sql.d.ts.map +1 -0
- package/dist/hooks/deep-compare-memoize.d.ts +2 -0
- package/dist/hooks/deep-compare-memoize.d.ts.map +1 -0
- package/dist/hooks/dry-run.d.ts +7 -0
- package/dist/hooks/dry-run.d.ts.map +1 -0
- package/dist/hooks/lazy-dry-run.d.ts +7 -0
- package/dist/hooks/lazy-dry-run.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +765 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +14 -10
- package/src/CubeContext.ts +37 -0
- package/src/CubeProvider.tsx +42 -0
- package/src/{QueryBuilder.jsx → QueryBuilder.tsx} +238 -89
- package/src/{QueryRenderer.jsx → QueryRenderer.tsx} +39 -14
- package/src/QueryRendererWithTotals.tsx +24 -0
- package/src/hooks/cube-fetch.ts +98 -0
- package/src/hooks/cube-meta.ts +8 -0
- package/src/hooks/{cube-query.js → cube-query.ts} +90 -14
- package/src/hooks/cube-sql.ts +22 -0
- package/src/hooks/{deep-compare-memoize.js → deep-compare-memoize.ts} +2 -2
- package/src/hooks/dry-run.ts +17 -0
- package/src/hooks/lazy-dry-run.ts +24 -0
- package/src/index.ts +77 -0
- package/src/types.ts +837 -0
- package/src/{utils.js → utils.ts} +3 -3
- package/index.d.ts +0 -697
- package/src/CubeContext.js +0 -3
- package/src/CubeProvider.jsx +0 -14
- package/src/QueryRendererWithTotals.jsx +0 -20
- package/src/hooks/cube-fetch.js +0 -66
- package/src/hooks/cube-meta.js +0 -5
- package/src/hooks/cube-sql.js +0 -8
- package/src/hooks/dry-run.js +0 -8
- package/src/hooks/lazy-dry-run.js +0 -11
- package/src/index.js +0 -18
|
@@ -363,13 +363,59 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
/**
|
|
367
|
+
* In case when you need direct access to `cubeApi` you can use `CubeContext` anywhere in your app
|
|
368
|
+
*
|
|
369
|
+
* ```js
|
|
370
|
+
* import React from 'react';
|
|
371
|
+
* import { CubeContext } from '@cubejs-client/react';
|
|
372
|
+
*
|
|
373
|
+
* export default function DisplayComponent() {
|
|
374
|
+
* const { cubeApi } = React.useContext(CubeContext);
|
|
375
|
+
* const [rawResults, setRawResults] = React.useState([]);
|
|
376
|
+
* const query = {
|
|
377
|
+
* ...
|
|
378
|
+
* };
|
|
379
|
+
*
|
|
380
|
+
* React.useEffect(() => {
|
|
381
|
+
* cubeApi.load(query).then((resultSet) => {
|
|
382
|
+
* setRawResults(resultSet.rawData());
|
|
383
|
+
* });
|
|
384
|
+
* }, [query]);
|
|
385
|
+
*
|
|
386
|
+
* return (
|
|
387
|
+
* <>
|
|
388
|
+
* {rawResults.map(row => (
|
|
389
|
+
* ...
|
|
390
|
+
* ))}
|
|
391
|
+
* </>
|
|
392
|
+
* )
|
|
393
|
+
* }
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
// The context has no default value: `cubeApi` is only available under a
|
|
397
|
+
// `CubeProvider`, and consumers guard against a missing context.
|
|
366
398
|
var CubeContext = /*#__PURE__*/React.createContext(null);
|
|
367
399
|
|
|
400
|
+
/**
|
|
401
|
+
* `<QueryRenderer />` a react component that accepts a query, fetches the given query, and uses the render prop to render the resulting data
|
|
402
|
+
* @stickyTypes QueryRendererProps, QueryRendererRenderProps
|
|
403
|
+
* @noInheritDoc
|
|
404
|
+
*/
|
|
368
405
|
var QueryRenderer = /*#__PURE__*/function (_React$Component) {
|
|
369
406
|
function QueryRenderer(props) {
|
|
370
407
|
var _this;
|
|
371
408
|
_classCallCheck(this, QueryRenderer);
|
|
372
409
|
_this = _callSuper(this, QueryRenderer, [props]);
|
|
410
|
+
// These sit after the lifecycle methods because `react/sort-comp` sorts
|
|
411
|
+
// TypeScript field declarations into `everything-else`, which the configured
|
|
412
|
+
// order puts after `lifecycle`. Runtime is unaffected: field initializers run
|
|
413
|
+
// right after `super()`, so the constructor's assignments still win.
|
|
414
|
+
//
|
|
415
|
+
// `this.context` is not re-declared: React types it as `any`, and a field
|
|
416
|
+
// declaration would be emitted at runtime and shadow the context React
|
|
417
|
+
// assigns.
|
|
418
|
+
_defineProperty(_this, "mutexObj", void 0);
|
|
373
419
|
_this.state = {};
|
|
374
420
|
_this.mutexObj = {};
|
|
375
421
|
return _this;
|
|
@@ -566,6 +612,8 @@ var QueryRenderer = /*#__PURE__*/function (_React$Component) {
|
|
|
566
612
|
sqlQuery: sqlQuery
|
|
567
613
|
};
|
|
568
614
|
if (render) {
|
|
615
|
+
// The prop is declared as returning `void` for backwards compatibility,
|
|
616
|
+
// while what it returns is what gets rendered
|
|
569
617
|
return render(loadState);
|
|
570
618
|
}
|
|
571
619
|
return null;
|
|
@@ -597,6 +645,7 @@ var QueryRendererWithTotals = function QueryRendererWithTotals(_ref) {
|
|
|
597
645
|
restProps = _objectWithoutProperties(_ref, _excluded$1);
|
|
598
646
|
return /*#__PURE__*/React__default["default"].createElement(QueryRenderer, _extends({
|
|
599
647
|
queries: {
|
|
648
|
+
// `granularity: null` is sent to the API on purpose to get totals
|
|
600
649
|
totals: _objectSpread2(_objectSpread2({}, query), {}, {
|
|
601
650
|
dimensions: [],
|
|
602
651
|
timeDimensions: query.timeDimensions ? query.timeDimensions.map(function (td) {
|
|
@@ -657,13 +706,89 @@ var granularities = [{
|
|
|
657
706
|
name: 'year',
|
|
658
707
|
title: 'Year'
|
|
659
708
|
}];
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* `<QueryBuilder />` is used to build interactive analytics query builders. It abstracts state management and API calls to Cube.js Backend. It uses render prop technique and doesn’t render anything itself, but calls the render function instead.
|
|
712
|
+
*
|
|
713
|
+
* **Example**
|
|
714
|
+
*
|
|
715
|
+
* [Open in CodeSandbox](https://codesandbox.io/s/z6r7qj8wm)
|
|
716
|
+
* ```js
|
|
717
|
+
* import React from 'react';
|
|
718
|
+
* import ReactDOM from 'react-dom';
|
|
719
|
+
* import { Layout, Divider, Empty, Select } from 'antd';
|
|
720
|
+
* import { QueryBuilder } from '@cubejs-client/react';
|
|
721
|
+
* import cube from '@cubejs-client/core';
|
|
722
|
+
* import 'antd/dist/antd.css';
|
|
723
|
+
*
|
|
724
|
+
* import ChartRenderer from './ChartRenderer';
|
|
725
|
+
*
|
|
726
|
+
* const cubeApi = cube('YOUR-CUBE-API-TOKEN', {
|
|
727
|
+
* apiUrl: 'http://localhost:4000/cubejs-api/v1',
|
|
728
|
+
* });
|
|
729
|
+
*
|
|
730
|
+
* const App = () => (
|
|
731
|
+
* <QueryBuilder
|
|
732
|
+
* query={{
|
|
733
|
+
* timeDimensions: [
|
|
734
|
+
* {
|
|
735
|
+
* dimension: 'LineItems.createdAt',
|
|
736
|
+
* granularity: 'month',
|
|
737
|
+
* },
|
|
738
|
+
* ],
|
|
739
|
+
* }}
|
|
740
|
+
* cubeApi={cubeApi}
|
|
741
|
+
* render={({ resultSet, measures, availableMeasures, updateMeasures }) => (
|
|
742
|
+
* <Layout.Content style={{ padding: '20px' }}>
|
|
743
|
+
* <Select
|
|
744
|
+
* mode="multiple"
|
|
745
|
+
* style={{ width: '100%' }}
|
|
746
|
+
* placeholder="Please select"
|
|
747
|
+
* onSelect={(measure) => updateMeasures.add(measure)}
|
|
748
|
+
* onDeselect={(measure) => updateMeasures.remove(measure)}
|
|
749
|
+
* >
|
|
750
|
+
* {availableMeasures.map((measure) => (
|
|
751
|
+
* <Select.Option key={measure.name} value={measure}>
|
|
752
|
+
* {measure.title}
|
|
753
|
+
* </Select.Option>
|
|
754
|
+
* ))}
|
|
755
|
+
* </Select>
|
|
756
|
+
* <Divider />
|
|
757
|
+
* {measures.length > 0 ? (
|
|
758
|
+
* <ChartRenderer resultSet={resultSet} />
|
|
759
|
+
* ) : (
|
|
760
|
+
* <Empty description="Select measure or dimension to get started" />
|
|
761
|
+
* )}
|
|
762
|
+
* </Layout.Content>
|
|
763
|
+
* )}
|
|
764
|
+
* />
|
|
765
|
+
* );
|
|
766
|
+
*
|
|
767
|
+
* const rootElement = document.getElementById("root");
|
|
768
|
+
* ReactDOM.render(<App />, rootElement);
|
|
769
|
+
* ```
|
|
770
|
+
* @stickyTypes QueryBuilderProps, QueryBuilderRenderProps, QueryBuilderState
|
|
771
|
+
* @noInheritDoc
|
|
772
|
+
* @order 2
|
|
773
|
+
*/
|
|
660
774
|
var QueryBuilder = /*#__PURE__*/function (_React$Component) {
|
|
661
775
|
function QueryBuilder(props) {
|
|
662
776
|
var _this;
|
|
663
777
|
_classCallCheck(this, QueryBuilder);
|
|
664
778
|
_this = _callSuper(this, QueryBuilder, [props]);
|
|
779
|
+
// These sit after the lifecycle methods because `react/sort-comp` sorts
|
|
780
|
+
// TypeScript field declarations into `everything-else`, which the configured
|
|
781
|
+
// order puts after `lifecycle`. Runtime is unaffected: field initializers run
|
|
782
|
+
// right after `super()`, so the constructor's assignments still win.
|
|
783
|
+
//
|
|
784
|
+
// `this.context` is not re-declared: React types it as `any`, and a field
|
|
785
|
+
// declaration would be emitted at runtime and shadow the context React
|
|
786
|
+
// assigns.
|
|
787
|
+
_defineProperty(_this, "mutexObj", void 0);
|
|
788
|
+
_defineProperty(_this, "orderMembersOrderKeys", void 0);
|
|
789
|
+
_defineProperty(_this, "prevContext", void 0);
|
|
665
790
|
_defineProperty(_this, "fetchMeta", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
666
|
-
var meta, metaError, richMetaError, metaErrorStack,
|
|
791
|
+
var meta, metaError, richMetaError, metaErrorStack, _requestError$respons, _requestError$respons2, requestError, _t;
|
|
667
792
|
return _regenerator().w(function (_context) {
|
|
668
793
|
while (1) switch (_context.p = _context.n) {
|
|
669
794
|
case 0:
|
|
@@ -689,9 +814,10 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
|
|
|
689
814
|
case 4:
|
|
690
815
|
_context.p = 4;
|
|
691
816
|
_t = _context.v;
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
817
|
+
requestError = _t;
|
|
818
|
+
metaError = ((_requestError$respons = requestError.response) === null || _requestError$respons === void 0 ? void 0 : _requestError$respons.plainError) || requestError;
|
|
819
|
+
richMetaError = requestError;
|
|
820
|
+
metaErrorStack = ((_requestError$respons2 = requestError.response) === null || _requestError$respons2 === void 0 || (_requestError$respons2 = _requestError$respons2.stack) === null || _requestError$respons2 === void 0 ? void 0 : _requestError$respons2.replace(requestError.message || '', '')) || '';
|
|
695
821
|
case 5:
|
|
696
822
|
_this.setState({
|
|
697
823
|
meta: meta,
|
|
@@ -942,6 +1068,9 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
|
|
|
942
1068
|
var indexedMeasures = ramda.indexBy(ramda.prop('cubeName'), availableMembers.measures);
|
|
943
1069
|
var indexedDimensions = ramda.indexBy(ramda.prop('cubeName'), availableMembers.dimensions);
|
|
944
1070
|
var cubeNames = ramda.uniq([].concat(_toConsumableArray(Object.keys(indexedMeasures)), _toConsumableArray(Object.keys(indexedDimensions)))).sort();
|
|
1071
|
+
|
|
1072
|
+
// Measures and dimensions of a cube are merged into one member list, which
|
|
1073
|
+
// the declared type describes as either one or the other
|
|
945
1074
|
availableFilterMembers = cubeNames.map(function (name) {
|
|
946
1075
|
var _indexedMeasures$name, _indexedDimensions$na;
|
|
947
1076
|
var cube = indexedMeasures[name] || indexedDimensions[name];
|
|
@@ -994,6 +1123,8 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
|
|
|
994
1123
|
chartType: chartType,
|
|
995
1124
|
measures: measures,
|
|
996
1125
|
dimensions: dimensions,
|
|
1126
|
+
// The declared granularity options require a `name`, which the
|
|
1127
|
+
// "w/o grouping" option leaves out
|
|
997
1128
|
timeDimensions: timeDimensions,
|
|
998
1129
|
segments: segments,
|
|
999
1130
|
filters: filters,
|
|
@@ -1098,7 +1229,7 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
|
|
|
1098
1229
|
value: function () {
|
|
1099
1230
|
var _updateVizState = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(state) {
|
|
1100
1231
|
var _this4 = this;
|
|
1101
|
-
var _this$props2, setQuery, setVizState, _this$state2, stateQuery, statePivotConfig, chartType, meta, finalState, vizStateSent, handleVizStateChange, runSetters, shouldFetchDryRun, response,
|
|
1232
|
+
var _this$props2, setQuery, setVizState, _this$state2, stateQuery, statePivotConfig, chartType, meta, finalState, vizStateSent, handleVizStateChange, runSetters, shouldFetchDryRun, response, _requestError$respons3, requestError, _t3;
|
|
1102
1233
|
return _regenerator().w(function (_context5) {
|
|
1103
1234
|
while (1) switch (_context5.p = _context5.n) {
|
|
1104
1235
|
case 0:
|
|
@@ -1176,9 +1307,10 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
|
|
|
1176
1307
|
case 3:
|
|
1177
1308
|
_context5.p = 3;
|
|
1178
1309
|
_t3 = _context5.v;
|
|
1310
|
+
requestError = _t3;
|
|
1179
1311
|
this.setState({
|
|
1180
|
-
queryError: new Error(((
|
|
1181
|
-
richQueryError: new Error(
|
|
1312
|
+
queryError: new Error(((_requestError$respons3 = requestError.response) === null || _requestError$respons3 === void 0 ? void 0 : _requestError$respons3.plainError) || requestError.message),
|
|
1313
|
+
richQueryError: new Error(requestError.message || requestError.toString())
|
|
1182
1314
|
});
|
|
1183
1315
|
case 4:
|
|
1184
1316
|
this.setState(finalState, function () {
|
|
@@ -1321,7 +1453,33 @@ _defineProperty(QueryBuilder, "defaultProps", {
|
|
|
1321
1453
|
setVizState: null
|
|
1322
1454
|
});
|
|
1323
1455
|
|
|
1324
|
-
|
|
1456
|
+
/**
|
|
1457
|
+
* Cube.js context provider
|
|
1458
|
+
* ```js
|
|
1459
|
+
* import React from 'react';
|
|
1460
|
+
* import cube from '@cubejs-client/core';
|
|
1461
|
+
* import { CubeProvider } from '@cubejs-client/react';
|
|
1462
|
+
*
|
|
1463
|
+
* const API_URL = 'https://harsh-eel.aws-us-east-2.cubecloudapp.dev';
|
|
1464
|
+
* const CUBE_TOKEN =
|
|
1465
|
+
* 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.* eyJpYXQiOjE1OTE3MDcxNDgsImV4cCI6MTU5NDI5OTE0OH0.* n5jGLQJ14igg6_Hri_Autx9qOIzVqp4oYxmX27V-4T4';
|
|
1466
|
+
*
|
|
1467
|
+
* const cubeApi = cube(CUBE_TOKEN, {
|
|
1468
|
+
* apiUrl: `${API_URL}/cubejs-api/v1`,
|
|
1469
|
+
* });
|
|
1470
|
+
*
|
|
1471
|
+
* export default function App() {
|
|
1472
|
+
* return (
|
|
1473
|
+
* <CubeProvider cubeApi={cubeApi}>
|
|
1474
|
+
* //...
|
|
1475
|
+
* </CubeProvider>
|
|
1476
|
+
* )
|
|
1477
|
+
* }
|
|
1478
|
+
* ```
|
|
1479
|
+
* @stickyTypes
|
|
1480
|
+
* @order 10
|
|
1481
|
+
*/
|
|
1482
|
+
var CubeProvider = function CubeProvider(_ref) {
|
|
1325
1483
|
var cubeApi = _ref.cubeApi,
|
|
1326
1484
|
children = _ref.children,
|
|
1327
1485
|
_ref$options = _ref.options,
|
|
@@ -1332,7 +1490,7 @@ function CubeProvider(_ref) {
|
|
|
1332
1490
|
options: options
|
|
1333
1491
|
}
|
|
1334
1492
|
}, children);
|
|
1335
|
-
}
|
|
1493
|
+
};
|
|
1336
1494
|
|
|
1337
1495
|
function useDeepCompareMemoize(value) {
|
|
1338
1496
|
var ref = React.useRef([]);
|
|
@@ -1342,6 +1500,10 @@ function useDeepCompareMemoize(value) {
|
|
|
1342
1500
|
return ref.current;
|
|
1343
1501
|
}
|
|
1344
1502
|
|
|
1503
|
+
/**
|
|
1504
|
+
* @hidden
|
|
1505
|
+
*/
|
|
1506
|
+
|
|
1345
1507
|
function useCubeFetch(method) {
|
|
1346
1508
|
var _options$query;
|
|
1347
1509
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -1369,10 +1531,12 @@ function useCubeFetch(method) {
|
|
|
1369
1531
|
ignoreSkip,
|
|
1370
1532
|
cubeApi,
|
|
1371
1533
|
query,
|
|
1534
|
+
onlyViews,
|
|
1372
1535
|
queryCondition,
|
|
1373
1536
|
coreOptions,
|
|
1374
1537
|
args,
|
|
1375
|
-
|
|
1538
|
+
fetchMethod,
|
|
1539
|
+
fetchResponse,
|
|
1376
1540
|
_args = arguments,
|
|
1377
1541
|
_t;
|
|
1378
1542
|
return _regenerator().w(function (_context) {
|
|
@@ -1382,6 +1546,7 @@ function useCubeFetch(method) {
|
|
|
1382
1546
|
ignoreSkip = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
|
|
1383
1547
|
cubeApi = options.cubeApi || (context === null || context === void 0 ? void 0 : context.cubeApi);
|
|
1384
1548
|
query = loadOptions.query || options.query;
|
|
1549
|
+
onlyViews = 'onlyViews' in loadOptions ? loadOptions.onlyViews : options.onlyViews;
|
|
1385
1550
|
queryCondition = method === 'meta' ? true : query && core.isQueryPresent(query);
|
|
1386
1551
|
if (!(cubeApi && (ignoreSkip || !skip) && queryCondition)) {
|
|
1387
1552
|
_context.n = 4;
|
|
@@ -1392,20 +1557,24 @@ function useCubeFetch(method) {
|
|
|
1392
1557
|
isLoading: true,
|
|
1393
1558
|
response: null
|
|
1394
1559
|
});
|
|
1395
|
-
coreOptions = _objectSpread2({
|
|
1560
|
+
coreOptions = _objectSpread2(_objectSpread2({
|
|
1396
1561
|
mutexObj: mutexRef.current,
|
|
1397
1562
|
mutexKey: method
|
|
1398
1563
|
}, options.baseRequestId ? {
|
|
1399
1564
|
baseRequestId: options.baseRequestId
|
|
1565
|
+
} : {}), method === 'meta' && onlyViews ? {
|
|
1566
|
+
onlyViews: true
|
|
1400
1567
|
} : {});
|
|
1401
|
-
args = method === 'meta' ? [coreOptions] : [query, coreOptions];
|
|
1568
|
+
args = method === 'meta' ? [coreOptions] : [query, coreOptions]; // `method` picks between overloaded `CubeApi` methods, so the call is
|
|
1569
|
+
// dispatched dynamically while keeping `cubeApi` as the receiver
|
|
1570
|
+
fetchMethod = cubeApi[method];
|
|
1402
1571
|
_context.p = 1;
|
|
1403
1572
|
_context.n = 2;
|
|
1404
|
-
return
|
|
1573
|
+
return fetchMethod.apply(cubeApi, args);
|
|
1405
1574
|
case 2:
|
|
1406
|
-
|
|
1575
|
+
fetchResponse = _context.v;
|
|
1407
1576
|
setResponse({
|
|
1408
|
-
response:
|
|
1577
|
+
response: fetchResponse,
|
|
1409
1578
|
isLoading: false
|
|
1410
1579
|
});
|
|
1411
1580
|
_context.n = 4;
|
|
@@ -1427,15 +1596,24 @@ function useCubeFetch(method) {
|
|
|
1427
1596
|
}
|
|
1428
1597
|
React.useEffect(function () {
|
|
1429
1598
|
load();
|
|
1599
|
+
// `order` is read off a single query; an array of queries does not carry it
|
|
1430
1600
|
}, useDeepCompareMemoize([Object.keys(((_options$query = options.query) === null || _options$query === void 0 ? void 0 : _options$query.order) || {}), options, context]));
|
|
1431
1601
|
return _objectSpread2(_objectSpread2({}, response), {}, {
|
|
1432
1602
|
error: error,
|
|
1433
|
-
refetch: function refetch(
|
|
1434
|
-
return load(
|
|
1603
|
+
refetch: function refetch(refetchOptions) {
|
|
1604
|
+
return load(refetchOptions, true);
|
|
1435
1605
|
}
|
|
1436
1606
|
});
|
|
1437
1607
|
}
|
|
1438
1608
|
|
|
1609
|
+
/**
|
|
1610
|
+
* The hook resolves with a `SqlQuery`, while its `response` stays declared as a
|
|
1611
|
+
* dry-run response for backwards compatibility — `UseCubeSqlResult` spells the
|
|
1612
|
+
* real shape. `refetch` is declared, as it is on `useDryRun` and `useCubeMeta`,
|
|
1613
|
+
* because all three return the same object.
|
|
1614
|
+
*
|
|
1615
|
+
* @hidden
|
|
1616
|
+
*/
|
|
1439
1617
|
function useCubeSql(query) {
|
|
1440
1618
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1441
1619
|
return useCubeFetch('sql', _objectSpread2(_objectSpread2({}, options), {}, {
|
|
@@ -1443,6 +1621,9 @@ function useCubeSql(query) {
|
|
|
1443
1621
|
}));
|
|
1444
1622
|
}
|
|
1445
1623
|
|
|
1624
|
+
/**
|
|
1625
|
+
* @hidden
|
|
1626
|
+
*/
|
|
1446
1627
|
function useDryRun(query) {
|
|
1447
1628
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1448
1629
|
return useCubeFetch('dryRun', _objectSpread2(_objectSpread2({}, options), {}, {
|
|
@@ -1451,6 +1632,9 @@ function useDryRun(query) {
|
|
|
1451
1632
|
}
|
|
1452
1633
|
|
|
1453
1634
|
var _excluded = ["refetch"];
|
|
1635
|
+
/**
|
|
1636
|
+
* @hidden
|
|
1637
|
+
*/
|
|
1454
1638
|
function useLazyDryRun(query) {
|
|
1455
1639
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1456
1640
|
var _useCubeFetch = useCubeFetch('dryRun', _objectSpread2(_objectSpread2({}, options), {}, {
|
|
@@ -1462,6 +1646,42 @@ function useLazyDryRun(query) {
|
|
|
1462
1646
|
return [refetch, result];
|
|
1463
1647
|
}
|
|
1464
1648
|
|
|
1649
|
+
/**
|
|
1650
|
+
* A React hook for executing Cube.js queries
|
|
1651
|
+
* ```js
|
|
1652
|
+
* import React from 'react';
|
|
1653
|
+
* import { Table } from 'antd';
|
|
1654
|
+
* import { useCubeQuery } from '@cubejs-client/react';
|
|
1655
|
+
*
|
|
1656
|
+
* export default function App() {
|
|
1657
|
+
* const { resultSet, isLoading, error, progress } = useCubeQuery({
|
|
1658
|
+
* measures: ['Orders.count'],
|
|
1659
|
+
* dimensions: ['Orders.createdAt.month'],
|
|
1660
|
+
* });
|
|
1661
|
+
*
|
|
1662
|
+
* if (isLoading) {
|
|
1663
|
+
* return <div>{progress?.stage || 'Loading...'}</div>;
|
|
1664
|
+
* }
|
|
1665
|
+
*
|
|
1666
|
+
* if (error) {
|
|
1667
|
+
* return <div>{error.toString()}</div>;
|
|
1668
|
+
* }
|
|
1669
|
+
*
|
|
1670
|
+
* if (!resultSet) {
|
|
1671
|
+
* return null;
|
|
1672
|
+
* }
|
|
1673
|
+
*
|
|
1674
|
+
* const dataSource = resultSet.tablePivot();
|
|
1675
|
+
* const columns = resultSet.tableColumns();
|
|
1676
|
+
*
|
|
1677
|
+
* return <Table columns={columns} dataSource={dataSource} />;
|
|
1678
|
+
* }
|
|
1679
|
+
*
|
|
1680
|
+
* ```
|
|
1681
|
+
* @order 1
|
|
1682
|
+
* @stickyTypes
|
|
1683
|
+
*/
|
|
1684
|
+
|
|
1465
1685
|
function useCubeQuery(query) {
|
|
1466
1686
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1467
1687
|
var mutexRef = React.useRef({});
|
|
@@ -1487,9 +1707,10 @@ function useCubeQuery(query) {
|
|
|
1487
1707
|
setError = _useState0[1];
|
|
1488
1708
|
var context = React.useContext(CubeContext);
|
|
1489
1709
|
var subscribeRequest = null;
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1710
|
+
|
|
1711
|
+
// `progressResponse` is not part of the public `ProgressResult` API
|
|
1712
|
+
var progressCallback = function progressCallback(progressResult) {
|
|
1713
|
+
return setProgress(progressResult.progressResponse);
|
|
1493
1714
|
};
|
|
1494
1715
|
function fetch() {
|
|
1495
1716
|
return _fetch.apply(this, arguments);
|
|
@@ -1557,7 +1778,7 @@ function useCubeQuery(query) {
|
|
|
1557
1778
|
}
|
|
1558
1779
|
function _loadQuery() {
|
|
1559
1780
|
_loadQuery = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1560
|
-
var _t;
|
|
1781
|
+
var previousQuery, _t;
|
|
1561
1782
|
return _regenerator().w(function (_context) {
|
|
1562
1783
|
while (1) switch (_context.p = _context.n) {
|
|
1563
1784
|
case 0:
|
|
@@ -1565,7 +1786,10 @@ function useCubeQuery(query) {
|
|
|
1565
1786
|
_context.n = 7;
|
|
1566
1787
|
break;
|
|
1567
1788
|
}
|
|
1568
|
-
|
|
1789
|
+
// `areQueriesEqual` is declared for a single query, and reads no more
|
|
1790
|
+
// than `order` off one when given an array of queries
|
|
1791
|
+
previousQuery = currentQuery;
|
|
1792
|
+
if (!core.areQueriesEqual(previousQuery, query)) {
|
|
1569
1793
|
if (resetResultSetOnChange == null || resetResultSetOnChange) {
|
|
1570
1794
|
setResultSet(null);
|
|
1571
1795
|
}
|
|
@@ -1631,7 +1855,8 @@ function useCubeQuery(query) {
|
|
|
1631
1855
|
subscribeRequest = null;
|
|
1632
1856
|
}
|
|
1633
1857
|
};
|
|
1634
|
-
|
|
1858
|
+
// `order` is read off a single query; an array of queries does not carry it
|
|
1859
|
+
}, useDeepCompareMemoize([query, Object.keys((query === null || query === void 0 ? void 0 : query.order) || {}), options, context]));
|
|
1635
1860
|
return {
|
|
1636
1861
|
isLoading: isLoading,
|
|
1637
1862
|
resultSet: resultSet,
|