@cubejs-client/react 0.30.30 → 0.30.60

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/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.30.60](https://github.com/cube-js/cube.js/compare/v0.30.59...v0.30.60) (2022-08-28)
7
+
8
+ **Note:** Version bump only for package @cubejs-client/react
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.30.46](https://github.com/cube-js/cube.js/compare/v0.30.45...v0.30.46) (2022-08-10)
15
+
16
+ **Note:** Version bump only for package @cubejs-client/react
17
+
18
+
19
+
20
+
21
+
22
+ ## [0.30.40](https://github.com/cube-js/cube.js/compare/v0.30.39...v0.30.40) (2022-07-26)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **client-react:** update hooks for React 18 StrictMode ([#4999](https://github.com/cube-js/cube.js/issues/4999)) ([fd6352c](https://github.com/cube-js/cube.js/commit/fd6352c61a614afef61b2a9d4332ecf300594b3b))
28
+
29
+
30
+
31
+
32
+
6
33
  ## [0.30.30](https://github.com/cube-js/cube.js/compare/v0.30.29...v0.30.30) (2022-07-05)
7
34
 
8
35
 
@@ -26,126 +26,27 @@ import 'core-js/modules/es.regexp.to-string.js';
26
26
  import React, { createContext, useRef, useEffect, useContext, useState } from 'react';
27
27
  import { equals, toPairs, fromPairs, uniqBy, prop, indexBy, uniq, pick, clone } from 'ramda';
28
28
  import { isQueryPresent, getQueryMembers, flattenFilters, moveItemInArray, movePivotItem, removeEmptyQueryFields, ResultSet, defaultOrder, validateQuery, defaultHeuristics, areQueriesEqual } from '@cubejs-client/core';
29
- import _typeof from '@babel/runtime/helpers/typeof';
30
- import 'core-js/modules/es.regexp.exec.js';
31
- import 'core-js/modules/es.string.split.js';
32
- import 'core-js/modules/es.string.replace.js';
33
- import 'core-js/modules/es.array.concat.js';
34
- import 'core-js/modules/es.object.from-entries.js';
35
- import 'core-js/modules/es.object.entries.js';
36
- import 'core-js/modules/es.array.is-array.js';
37
- import Anser from 'anser';
38
- import { encode } from 'html-entities';
39
29
  import _extends from '@babel/runtime/helpers/extends';
40
30
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
41
31
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
42
32
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
43
33
  import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
44
34
  import _regeneratorRuntime from '@babel/runtime/regenerator';
35
+ import 'core-js/modules/es.regexp.exec.js';
36
+ import 'core-js/modules/es.string.replace.js';
45
37
  import 'core-js/modules/es.function.name.js';
38
+ import 'core-js/modules/es.array.concat.js';
46
39
  import 'core-js/modules/es.array.splice.js';
47
40
  import 'core-js/modules/es.array.sort.js';
41
+ import 'core-js/modules/es.array.is-array.js';
42
+ import 'core-js/modules/es.object.from-entries.js';
48
43
  import 'core-js/modules/es.array.find.js';
49
44
  import 'core-js/modules/es.array.reduce.js';
45
+ import _typeof from '@babel/runtime/helpers/typeof';
46
+ import 'core-js/modules/es.object.entries.js';
50
47
 
51
48
  var CubeContext = /*#__PURE__*/createContext(null);
52
49
 
53
- var colors = {
54
- reset: 'orange',
55
- black: 'black',
56
- red: 'red',
57
- green: 'green',
58
- yellow: 'orange',
59
- blue: 'blue',
60
- magenta: 'magenta',
61
- cyan: 'cyan',
62
- gray: 'gray',
63
- lightgrey: 'lightgrey',
64
- darkgrey: 'darkgrey'
65
- };
66
- var anserMap = {
67
- 'ansi-bright-black': 'black',
68
- 'ansi-bright-yellow': 'yellow',
69
- 'ansi-yellow': 'yellow',
70
- 'ansi-bright-green': 'green',
71
- 'ansi-green': 'green',
72
- 'ansi-bright-cyan': 'cyan',
73
- 'ansi-cyan': 'cyan',
74
- 'ansi-bright-red': 'red',
75
- 'ansi-red': 'red',
76
- 'ansi-bright-magenta': 'magenta',
77
- 'ansi-magenta': 'magenta',
78
- 'ansi-white': 'darkgrey'
79
- };
80
- function generateAnsiHTML(txt) {
81
- var arr = new Anser().ansiToJson(encode(txt), {
82
- use_classes: true
83
- });
84
- var result = '';
85
- var open = false;
86
-
87
- for (var index = 0; index < arr.length; ++index) {
88
- var c = arr[index];
89
- var content = c.content;
90
- var fg = c.fg;
91
- var contentParts = content.split('\n');
92
-
93
- for (var j = 0; j < contentParts.length; ++j) {
94
- if (!open) {
95
- result += '<span data-ansi-line="true">';
96
- open = true;
97
- }
98
-
99
- var part = contentParts[j].replace('\r', '');
100
- var color = colors[anserMap[fg]];
101
-
102
- if (color != null) {
103
- result += "<span style=\"color: ".concat(color, ";\">").concat(part, "</span>");
104
- } else {
105
- if (fg != null) {
106
- console.log('Missing color mapping: ', fg);
107
- }
108
-
109
- result += "<span>".concat(part, "</span>");
110
- }
111
-
112
- if (j < contentParts.length - 1) {
113
- result += '</span>';
114
- open = false;
115
- result += '<br/>';
116
- }
117
- }
118
- }
119
-
120
- if (open) {
121
- result += '</span>';
122
- }
123
-
124
- return result;
125
- }
126
- function removeEmpty(obj) {
127
- if (_typeof(obj) !== 'object') {
128
- return obj;
129
- }
130
-
131
- return Object.fromEntries(Object.entries(obj).filter(function (_ref) {
132
- var _ref2 = _slicedToArray(_ref, 2),
133
- v = _ref2[1];
134
-
135
- return v != null;
136
- }).map(function (_ref3) {
137
- var _ref4 = _slicedToArray(_ref3, 2),
138
- k = _ref4[0],
139
- v = _ref4[1];
140
-
141
- if (Array.isArray(v)) {
142
- return [k, v.map(removeEmpty)];
143
- }
144
-
145
- return [k, _typeof(v) === 'object' ? removeEmpty(v) : v];
146
- }));
147
- }
148
-
149
50
  function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
150
51
 
151
52
  function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$6(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -349,6 +250,8 @@ var QueryRenderer = /*#__PURE__*/function (_React$Component) {
349
250
  }, {
350
251
  key: "render",
351
252
  value: function render() {
253
+ var _error$response;
254
+
352
255
  var _this$state = this.state,
353
256
  error = _this$state.error,
354
257
  queries = _this$state.queries,
@@ -357,7 +260,7 @@ var QueryRenderer = /*#__PURE__*/function (_React$Component) {
357
260
  sqlQuery = _this$state.sqlQuery;
358
261
  var render = this.props.render;
359
262
  var loadState = {
360
- error: error ? new Error(generateAnsiHTML(error.message || error.toString())) : null,
263
+ error: error ? new Error(((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.plainError) || error.message || error.toString()) : null,
361
264
  resultSet: queries ? resultSet || {} : resultSet,
362
265
  loadingState: {
363
266
  isLoading: isLoading
@@ -424,6 +327,29 @@ QueryRendererWithTotals.defaultProps = {
424
327
  loadSql: null
425
328
  };
426
329
 
330
+ function removeEmpty(obj) {
331
+ if (_typeof(obj) !== 'object') {
332
+ return obj;
333
+ }
334
+
335
+ return Object.fromEntries(Object.entries(obj).filter(function (_ref) {
336
+ var _ref2 = _slicedToArray(_ref, 2),
337
+ v = _ref2[1];
338
+
339
+ return v != null;
340
+ }).map(function (_ref3) {
341
+ var _ref4 = _slicedToArray(_ref3, 2),
342
+ k = _ref4[0],
343
+ v = _ref4[1];
344
+
345
+ if (Array.isArray(v)) {
346
+ return [k, v.map(removeEmpty)];
347
+ }
348
+
349
+ return [k, _typeof(v) === 'object' ? removeEmpty(v) : v];
350
+ }));
351
+ }
352
+
427
353
  function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
428
354
 
429
355
  function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -473,7 +399,7 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
473
399
  _this = _super.call(this, props);
474
400
 
475
401
  _defineProperty(_assertThisInitialized(_this), "fetchMeta", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
476
- var meta, metaError, metaErrorStack, _error$response, _error$response$stack;
402
+ var meta, metaError, richMetaError, metaErrorStack, _error$response, _error$response2, _error$response2$stac;
477
403
 
478
404
  return _regeneratorRuntime.wrap(function _callee$(_context) {
479
405
  while (1) {
@@ -488,31 +414,34 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
488
414
 
489
415
  case 2:
490
416
  metaError = null;
417
+ richMetaError = null;
491
418
  metaErrorStack = null;
492
- _context.prev = 4;
419
+ _context.prev = 5;
493
420
 
494
421
  _this.setState({
495
422
  isFetchingMeta: true
496
423
  });
497
424
 
498
- _context.next = 8;
425
+ _context.next = 9;
499
426
  return _this.cubejsApi().meta();
500
427
 
501
- case 8:
428
+ case 9:
502
429
  meta = _context.sent;
503
- _context.next = 15;
430
+ _context.next = 17;
504
431
  break;
505
432
 
506
- case 11:
507
- _context.prev = 11;
508
- _context.t0 = _context["catch"](4);
509
- metaError = _context.t0;
510
- metaErrorStack = ((_error$response = _context.t0.response) === null || _error$response === void 0 ? void 0 : (_error$response$stack = _error$response.stack) === null || _error$response$stack === void 0 ? void 0 : _error$response$stack.replace(_context.t0.message || '', '')) || '';
433
+ case 12:
434
+ _context.prev = 12;
435
+ _context.t0 = _context["catch"](5);
436
+ metaError = ((_error$response = _context.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.plainError) || _context.t0;
437
+ richMetaError = _context.t0;
438
+ metaErrorStack = ((_error$response2 = _context.t0.response) === null || _error$response2 === void 0 ? void 0 : (_error$response2$stac = _error$response2.stack) === null || _error$response2$stac === void 0 ? void 0 : _error$response2$stac.replace(_context.t0.message || '', '')) || '';
511
439
 
512
- case 15:
440
+ case 17:
513
441
  _this.setState({
514
442
  meta: meta,
515
- metaError: metaError ? new Error(generateAnsiHTML(metaError.message || metaError.toString())) : null,
443
+ metaError: metaError ? new Error(metaError.message || metaError.toString()) : null,
444
+ richMetaError: richMetaError,
516
445
  metaErrorStack: metaErrorStack,
517
446
  isFetchingMeta: false
518
447
  }, function () {
@@ -521,12 +450,12 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
521
450
  _this.updateQuery({});
522
451
  });
523
452
 
524
- case 16:
453
+ case 18:
525
454
  case "end":
526
455
  return _context.stop();
527
456
  }
528
457
  }
529
- }, _callee, null, [[4, 11]]);
458
+ }, _callee, null, [[5, 12]]);
530
459
  })));
531
460
 
532
461
  _this.state = _objectSpread$4(_objectSpread$4({
@@ -750,6 +679,7 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
750
679
  var _this$state = this.state,
751
680
  meta = _this$state.meta,
752
681
  metaError = _this$state.metaError,
682
+ richMetaError = _this$state.richMetaError,
753
683
  query = _this$state.query,
754
684
  queryError = _this$state.queryError,
755
685
  chartType = _this$state.chartType,
@@ -846,6 +776,7 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
846
776
  return _objectSpread$4({
847
777
  meta: meta,
848
778
  metaError: metaError,
779
+ richMetaError: richMetaError,
849
780
  metaErrorStack: metaErrorStack,
850
781
  query: query,
851
782
  error: queryError,
@@ -965,7 +896,7 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
965
896
  var _updateVizState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(state) {
966
897
  var _this4 = this;
967
898
 
968
- var _this$props2, setQuery, setVizState, _this$state2, stateQuery, statePivotConfig, chartType, meta, finalState, vizStateSent, handleVizStateChange, runSetters, shouldFetchDryRun, response;
899
+ var _this$props2, setQuery, setVizState, _this$state2, stateQuery, statePivotConfig, chartType, meta, finalState, vizStateSent, handleVizStateChange, runSetters, shouldFetchDryRun, response, _error$response3;
969
900
 
970
901
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
971
902
  while (1) {
@@ -1059,7 +990,8 @@ var QueryBuilder = /*#__PURE__*/function (_React$Component) {
1059
990
  _context5.prev = 27;
1060
991
  _context5.t0 = _context5["catch"](16);
1061
992
  this.setState({
1062
- queryError: new Error(generateAnsiHTML(_context5.t0.message || _context5.t0.toString()))
993
+ queryError: new Error(((_error$response3 = _context5.t0.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.plainError) || _context5.t0.message),
994
+ richQueryError: new Error(_context5.t0.message || _context5.t0.toString())
1063
995
  });
1064
996
 
1065
997
  case 30:
@@ -1416,7 +1348,7 @@ function useLazyDryRun(query) {
1416
1348
  function useCubeQuery(query) {
1417
1349
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1418
1350
  var mutexRef = useRef({});
1419
- var isMounted = useRef(true);
1351
+ var isMounted = useIsMounted();
1420
1352
 
1421
1353
  var _useState = useState(null),
1422
1354
  _useState2 = _slicedToArray(_useState, 2),
@@ -1490,7 +1422,7 @@ function useCubeQuery(query) {
1490
1422
  case 10:
1491
1423
  response = _context2.sent;
1492
1424
 
1493
- if (isMounted.current) {
1425
+ if (isMounted()) {
1494
1426
  setResultSet(response);
1495
1427
  setProgress(null);
1496
1428
  }
@@ -1502,14 +1434,14 @@ function useCubeQuery(query) {
1502
1434
  _context2.prev = 14;
1503
1435
  _context2.t0 = _context2["catch"](7);
1504
1436
 
1505
- if (isMounted.current) {
1437
+ if (isMounted()) {
1506
1438
  setError(_context2.t0);
1507
1439
  setResultSet(null);
1508
1440
  setProgress(null);
1509
1441
  }
1510
1442
 
1511
1443
  case 17:
1512
- if (isMounted.current) {
1444
+ if (isMounted()) {
1513
1445
  setLoading(false);
1514
1446
  }
1515
1447
 
@@ -1523,11 +1455,6 @@ function useCubeQuery(query) {
1523
1455
  return _fetch.apply(this, arguments);
1524
1456
  }
1525
1457
 
1526
- useEffect(function () {
1527
- return function () {
1528
- isMounted.current = false;
1529
- };
1530
- }, []);
1531
1458
  useEffect(function () {
1532
1459
  var _options$skip = options.skip,
1533
1460
  skip = _options$skip === void 0 ? false : _options$skip,
@@ -1587,7 +1514,7 @@ function useCubeQuery(query) {
1587
1514
  mutexKey: 'query',
1588
1515
  progressCallback: progressCallback
1589
1516
  }, function (e, result) {
1590
- if (isMounted.current) {
1517
+ if (isMounted()) {
1591
1518
  if (e) {
1592
1519
  setError(e);
1593
1520
  } else {
@@ -1613,7 +1540,7 @@ function useCubeQuery(query) {
1613
1540
  _context.prev = 17;
1614
1541
  _context.t0 = _context["catch"](4);
1615
1542
 
1616
- if (isMounted.current) {
1543
+ if (isMounted()) {
1617
1544
  setError(_context.t0);
1618
1545
  setResultSet(null);
1619
1546
  setLoading(false);