@cubejs-client/react 1.7.37 → 1.7.39
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/README.md +4 -4
- package/dist/CubeProvider.d.ts +1 -1
- package/dist/QueryBuilder.d.ts +4 -2
- package/dist/QueryBuilder.d.ts.map +1 -1
- package/dist/QueryRenderer.d.ts +2 -0
- package/dist/QueryRenderer.d.ts.map +1 -1
- package/dist/QueryRendererWithTotals.d.ts +2 -1
- package/dist/QueryRendererWithTotals.d.ts.map +1 -1
- package/dist/cubejs-client-react.cjs.js +88 -42
- package/dist/cubejs-client-react.cjs.js.map +1 -1
- package/dist/cubejs-client-react.esm.js +62 -34
- package/dist/cubejs-client-react.esm.js.map +1 -1
- package/dist/cubejs-client-react.umd.js +88 -42
- package/dist/cubejs-client-react.umd.js.map +1 -1
- package/dist/hooks/cube-query.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +5 -5
- package/package.json +17 -4
- package/src/CubeProvider.tsx +1 -1
- package/src/QueryBuilder.tsx +3 -5
- package/src/QueryRenderer.tsx +2 -4
- package/src/hooks/cube-query.ts +68 -25
- package/src/index.ts +1 -1
- package/src/types.ts +5 -5
|
@@ -383,14 +383,11 @@
|
|
|
383
383
|
var _this;
|
|
384
384
|
_classCallCheck(this, QueryRenderer);
|
|
385
385
|
_this = _callSuper(this, QueryRenderer, [props]);
|
|
386
|
+
_defineProperty(_this, "context", void 0);
|
|
386
387
|
// These sit after the lifecycle methods because `react/sort-comp` sorts
|
|
387
388
|
// TypeScript field declarations into `everything-else`, which the configured
|
|
388
389
|
// order puts after `lifecycle`. Runtime is unaffected: field initializers run
|
|
389
390
|
// right after `super()`, so the constructor's assignments still win.
|
|
390
|
-
//
|
|
391
|
-
// `this.context` is not re-declared: React types it as `any`, and a field
|
|
392
|
-
// declaration would be emitted at runtime and shadow the context React
|
|
393
|
-
// assigns.
|
|
394
391
|
_defineProperty(_this, "mutexObj", void 0);
|
|
395
392
|
_this.state = {};
|
|
396
393
|
_this.mutexObj = {};
|
|
@@ -684,7 +681,7 @@
|
|
|
684
681
|
}];
|
|
685
682
|
|
|
686
683
|
/**
|
|
687
|
-
* `<QueryBuilder />` is used to build interactive analytics query builders. It abstracts state management and API calls to Cube
|
|
684
|
+
* `<QueryBuilder />` is used to build interactive analytics query builders. It abstracts state management and API calls to Cube Backend. It uses render prop technique and doesn’t render anything itself, but calls the render function instead.
|
|
688
685
|
*
|
|
689
686
|
* **Example**
|
|
690
687
|
*
|
|
@@ -752,14 +749,11 @@
|
|
|
752
749
|
var _this;
|
|
753
750
|
_classCallCheck(this, QueryBuilder);
|
|
754
751
|
_this = _callSuper(this, QueryBuilder, [props]);
|
|
752
|
+
_defineProperty(_this, "context", void 0);
|
|
755
753
|
// These sit after the lifecycle methods because `react/sort-comp` sorts
|
|
756
754
|
// TypeScript field declarations into `everything-else`, which the configured
|
|
757
755
|
// order puts after `lifecycle`. Runtime is unaffected: field initializers run
|
|
758
756
|
// right after `super()`, so the constructor's assignments still win.
|
|
759
|
-
//
|
|
760
|
-
// `this.context` is not re-declared: React types it as `any`, and a field
|
|
761
|
-
// declaration would be emitted at runtime and shadow the context React
|
|
762
|
-
// assigns.
|
|
763
757
|
_defineProperty(_this, "mutexObj", void 0);
|
|
764
758
|
_defineProperty(_this, "orderMembersOrderKeys", void 0);
|
|
765
759
|
_defineProperty(_this, "prevContext", void 0);
|
|
@@ -1430,7 +1424,7 @@
|
|
|
1430
1424
|
});
|
|
1431
1425
|
|
|
1432
1426
|
/**
|
|
1433
|
-
* Cube
|
|
1427
|
+
* Cube context provider
|
|
1434
1428
|
* ```js
|
|
1435
1429
|
* import React from 'react';
|
|
1436
1430
|
* import cube from '@cubejs-client/core';
|
|
@@ -1623,7 +1617,7 @@
|
|
|
1623
1617
|
}
|
|
1624
1618
|
|
|
1625
1619
|
/**
|
|
1626
|
-
* A React hook for executing Cube
|
|
1620
|
+
* A React hook for executing Cube queries
|
|
1627
1621
|
* ```js
|
|
1628
1622
|
* import React from 'react';
|
|
1629
1623
|
* import { Table } from 'antd';
|
|
@@ -1682,17 +1676,29 @@
|
|
|
1682
1676
|
error = _useState0[0],
|
|
1683
1677
|
setError = _useState0[1];
|
|
1684
1678
|
var context = React.useContext(CubeContext);
|
|
1679
|
+
var requestIdRef = React.useRef(0);
|
|
1680
|
+
var hasStartedRequestRef = React.useRef(false);
|
|
1685
1681
|
var subscribeRequest = null;
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
var progressCallback = function progressCallback(progressResult) {
|
|
1689
|
-
return setProgress(progressResult.progressResponse);
|
|
1690
|
-
};
|
|
1691
|
-
function fetch() {
|
|
1692
|
-
return _fetch.apply(this, arguments);
|
|
1682
|
+
function isCurrentRequest(requestId) {
|
|
1683
|
+
return requestId === requestIdRef.current;
|
|
1693
1684
|
}
|
|
1694
|
-
function
|
|
1695
|
-
|
|
1685
|
+
function startRequest() {
|
|
1686
|
+
hasStartedRequestRef.current = true;
|
|
1687
|
+
return ++requestIdRef.current;
|
|
1688
|
+
}
|
|
1689
|
+
function createProgressCallback(requestId) {
|
|
1690
|
+
return function (progressResult) {
|
|
1691
|
+
if (isCurrentRequest(requestId)) {
|
|
1692
|
+
// `progressResponse` is not part of the public `ProgressResult` API
|
|
1693
|
+
setProgress(progressResult.progressResponse);
|
|
1694
|
+
}
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
function fetchQuery(_x) {
|
|
1698
|
+
return _fetchQuery.apply(this, arguments);
|
|
1699
|
+
}
|
|
1700
|
+
function _fetchQuery() {
|
|
1701
|
+
_fetchQuery = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(requestId) {
|
|
1696
1702
|
var resetResultSetOnChange, cubeApi, _context$options, response, _t2;
|
|
1697
1703
|
return _regenerator().w(function (_context2) {
|
|
1698
1704
|
while (1) switch (_context2.p = _context2.n) {
|
|
@@ -1710,35 +1716,61 @@
|
|
|
1710
1716
|
}
|
|
1711
1717
|
setError(null);
|
|
1712
1718
|
setLoading(true);
|
|
1719
|
+
setProgress(null);
|
|
1713
1720
|
_context2.p = 2;
|
|
1714
1721
|
_context2.n = 3;
|
|
1715
1722
|
return cubeApi.load(query, _objectSpread2({
|
|
1716
1723
|
mutexObj: mutexRef.current,
|
|
1717
1724
|
mutexKey: 'query',
|
|
1718
|
-
progressCallback:
|
|
1725
|
+
progressCallback: createProgressCallback(requestId),
|
|
1719
1726
|
castNumerics: Boolean(typeof options.castNumerics === 'boolean' ? options.castNumerics : context === null || context === void 0 || (_context$options = context.options) === null || _context$options === void 0 ? void 0 : _context$options.castNumerics)
|
|
1720
1727
|
}, options.cache ? {
|
|
1721
1728
|
cache: options.cache
|
|
1722
1729
|
} : {}));
|
|
1723
1730
|
case 3:
|
|
1724
1731
|
response = _context2.v;
|
|
1725
|
-
|
|
1726
|
-
|
|
1732
|
+
if (isCurrentRequest(requestId)) {
|
|
1733
|
+
setResultSet(response);
|
|
1734
|
+
setProgress(null);
|
|
1735
|
+
}
|
|
1727
1736
|
_context2.n = 5;
|
|
1728
1737
|
break;
|
|
1729
1738
|
case 4:
|
|
1730
1739
|
_context2.p = 4;
|
|
1731
1740
|
_t2 = _context2.v;
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1741
|
+
if (isCurrentRequest(requestId)) {
|
|
1742
|
+
setError(_t2);
|
|
1743
|
+
setResultSet(null);
|
|
1744
|
+
setProgress(null);
|
|
1745
|
+
}
|
|
1735
1746
|
case 5:
|
|
1736
|
-
|
|
1747
|
+
if (isCurrentRequest(requestId)) {
|
|
1748
|
+
setLoading(false);
|
|
1749
|
+
}
|
|
1737
1750
|
case 6:
|
|
1738
1751
|
return _context2.a(2);
|
|
1739
1752
|
}
|
|
1740
1753
|
}, _callee2, null, [[2, 4]]);
|
|
1741
1754
|
}));
|
|
1755
|
+
return _fetchQuery.apply(this, arguments);
|
|
1756
|
+
}
|
|
1757
|
+
function fetch() {
|
|
1758
|
+
return _fetch.apply(this, arguments);
|
|
1759
|
+
}
|
|
1760
|
+
function _fetch() {
|
|
1761
|
+
_fetch = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
1762
|
+
var requestId;
|
|
1763
|
+
return _regenerator().w(function (_context3) {
|
|
1764
|
+
while (1) switch (_context3.n) {
|
|
1765
|
+
case 0:
|
|
1766
|
+
requestId = startRequest();
|
|
1767
|
+
_context3.n = 1;
|
|
1768
|
+
return fetchQuery(requestId);
|
|
1769
|
+
case 1:
|
|
1770
|
+
return _context3.a(2);
|
|
1771
|
+
}
|
|
1772
|
+
}, _callee3);
|
|
1773
|
+
}));
|
|
1742
1774
|
return _fetch.apply(this, arguments);
|
|
1743
1775
|
}
|
|
1744
1776
|
React.useEffect(function () {
|
|
@@ -1754,15 +1786,15 @@
|
|
|
1754
1786
|
}
|
|
1755
1787
|
function _loadQuery() {
|
|
1756
1788
|
_loadQuery = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1757
|
-
var previousQuery, _t;
|
|
1789
|
+
var requestId, previousQuery, _t;
|
|
1758
1790
|
return _regenerator().w(function (_context) {
|
|
1759
1791
|
while (1) switch (_context.p = _context.n) {
|
|
1760
1792
|
case 0:
|
|
1761
1793
|
if (!(!skip && core.isQueryPresent(query))) {
|
|
1762
|
-
_context.n =
|
|
1794
|
+
_context.n = 8;
|
|
1763
1795
|
break;
|
|
1764
1796
|
}
|
|
1765
|
-
// `areQueriesEqual` is declared for a single query, and reads no more
|
|
1797
|
+
requestId = startRequest(); // `areQueriesEqual` is declared for a single query, and reads no more
|
|
1766
1798
|
// than `order` off one when given an array of queries
|
|
1767
1799
|
previousQuery = currentQuery;
|
|
1768
1800
|
if (!core.areQueriesEqual(previousQuery, query)) {
|
|
@@ -1773,6 +1805,7 @@
|
|
|
1773
1805
|
}
|
|
1774
1806
|
setError(null);
|
|
1775
1807
|
setLoading(true);
|
|
1808
|
+
setProgress(null);
|
|
1776
1809
|
_context.p = 1;
|
|
1777
1810
|
if (!subscribeRequest) {
|
|
1778
1811
|
_context.n = 3;
|
|
@@ -1790,34 +1823,46 @@
|
|
|
1790
1823
|
subscribeRequest = cubeApi.subscribe(query, _objectSpread2({
|
|
1791
1824
|
mutexObj: mutexRef.current,
|
|
1792
1825
|
mutexKey: 'query',
|
|
1793
|
-
progressCallback:
|
|
1826
|
+
progressCallback: createProgressCallback(requestId)
|
|
1794
1827
|
}, options.cache ? {
|
|
1795
1828
|
cache: options.cache
|
|
1796
1829
|
} : {}), function (e, result) {
|
|
1797
|
-
if (
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1830
|
+
if (isCurrentRequest(requestId)) {
|
|
1831
|
+
if (e) {
|
|
1832
|
+
setError(e);
|
|
1833
|
+
} else {
|
|
1834
|
+
setResultSet(result);
|
|
1835
|
+
}
|
|
1836
|
+
setLoading(false);
|
|
1837
|
+
setProgress(null);
|
|
1801
1838
|
}
|
|
1802
|
-
setLoading(false);
|
|
1803
|
-
setProgress(null);
|
|
1804
1839
|
});
|
|
1805
1840
|
_context.n = 5;
|
|
1806
1841
|
break;
|
|
1807
1842
|
case 4:
|
|
1808
1843
|
_context.n = 5;
|
|
1809
|
-
return
|
|
1844
|
+
return fetchQuery(requestId);
|
|
1810
1845
|
case 5:
|
|
1811
1846
|
_context.n = 7;
|
|
1812
1847
|
break;
|
|
1813
1848
|
case 6:
|
|
1814
1849
|
_context.p = 6;
|
|
1815
1850
|
_t = _context.v;
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1851
|
+
if (isCurrentRequest(requestId)) {
|
|
1852
|
+
setError(_t);
|
|
1853
|
+
setResultSet(null);
|
|
1854
|
+
setLoading(false);
|
|
1855
|
+
setProgress(null);
|
|
1856
|
+
}
|
|
1820
1857
|
case 7:
|
|
1858
|
+
_context.n = 9;
|
|
1859
|
+
break;
|
|
1860
|
+
case 8:
|
|
1861
|
+
if (hasStartedRequestRef.current) {
|
|
1862
|
+
setLoading(false);
|
|
1863
|
+
setProgress(null);
|
|
1864
|
+
}
|
|
1865
|
+
case 9:
|
|
1821
1866
|
return _context.a(2);
|
|
1822
1867
|
}
|
|
1823
1868
|
}, _callee, null, [[1, 6]]);
|
|
@@ -1826,6 +1871,7 @@
|
|
|
1826
1871
|
}
|
|
1827
1872
|
loadQuery();
|
|
1828
1873
|
return function () {
|
|
1874
|
+
requestIdRef.current += 1;
|
|
1829
1875
|
if (subscribeRequest) {
|
|
1830
1876
|
subscribeRequest.unsubscribe();
|
|
1831
1877
|
subscribeRequest = null;
|