@cubejs-client/react 0.30.46 → 0.30.69

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/index.d.ts CHANGED
@@ -240,6 +240,7 @@ declare module '@cubejs-client/react' {
240
240
 
241
241
  meta: Meta | undefined;
242
242
  metaError?: Error | null;
243
+ richMetaError?: Error | null;
243
244
  metaErrorStack?: string | null;
244
245
  isFetchingMeta: boolean;
245
246
  /**
@@ -655,9 +656,11 @@ declare module '@cubejs-client/react' {
655
656
  sourceAxis: TSourceAxis;
656
657
  destinationAxis: TSourceAxis;
657
658
  };
659
+
658
660
  type PivotConfigExtraUpdateFields = {
659
661
  limit?: number;
660
662
  };
663
+
661
664
  type PivotConfigUpdater = {
662
665
  moveItem: (args: PivotConfigUpdaterArgs) => void;
663
666
  update: (pivotConfig: PivotConfig & PivotConfigExtraUpdateFields) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubejs-client/react",
3
- "version": "0.30.46",
3
+ "version": "0.30.69",
4
4
  "author": "Cube Dev, Inc.",
5
5
  "license": "MIT",
6
6
  "engines": {},
@@ -24,10 +24,8 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.1.2",
27
- "@cubejs-client/core": "^0.30.46",
28
- "anser": "^2.0.1",
27
+ "@cubejs-client/core": "^0.30.64",
29
28
  "core-js": "^3.6.5",
30
- "html-entities": "^2.3.2",
31
29
  "ramda": "^0.27.0"
32
30
  },
33
31
  "devDependencies": {
@@ -44,5 +42,5 @@
44
42
  "peerDependencies": {
45
43
  "react": ">=16.10.2"
46
44
  },
47
- "gitHead": "c29f3e26e595a96f140c55049131b764e852876e"
45
+ "gitHead": "bce06c7562427267389b5f134b1f0c413c6764c0"
48
46
  }
@@ -15,7 +15,7 @@ import {
15
15
 
16
16
  import QueryRenderer from './QueryRenderer.jsx';
17
17
  import CubeContext from './CubeContext';
18
- import { generateAnsiHTML, removeEmpty } from './utils';
18
+ import { removeEmpty } from './utils';
19
19
 
20
20
  const granularities = [
21
21
  { name: undefined, title: 'w/o grouping' },
@@ -31,6 +31,24 @@ const granularities = [
31
31
 
32
32
  export default class QueryBuilder extends React.Component {
33
33
  static contextType = CubeContext;
34
+
35
+ static defaultProps = {
36
+ cubejsApi: null,
37
+ stateChangeHeuristics: null,
38
+ disableHeuristics: false,
39
+ render: null,
40
+ wrapWithQueryRenderer: true,
41
+ defaultChartType: 'line',
42
+ defaultQuery: {},
43
+ initialVizState: null,
44
+ onVizStateChanged: null,
45
+
46
+ // deprecated
47
+ query: null,
48
+ setQuery: null,
49
+ vizState: null,
50
+ setVizState: null,
51
+ };
34
52
 
35
53
  // This is an anti-pattern, only kept for backward compatibility
36
54
  // https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html#anti-pattern-unconditionally-copying-props-to-state
@@ -148,20 +166,23 @@ export default class QueryBuilder extends React.Component {
148
166
 
149
167
  let meta;
150
168
  let metaError = null;
169
+ let richMetaError = null;
151
170
  let metaErrorStack = null;
152
171
 
153
172
  try {
154
173
  this.setState({ isFetchingMeta: true });
155
174
  meta = await this.cubejsApi().meta();
156
175
  } catch (error) {
157
- metaError = error;
176
+ metaError = error.response?.plainError || error;
177
+ richMetaError = error;
158
178
  metaErrorStack = error.response?.stack?.replace(error.message || '', '') || '';
159
179
  }
160
180
 
161
181
  this.setState(
162
182
  {
163
183
  meta,
164
- metaError: metaError ? new Error(generateAnsiHTML(metaError.message || metaError.toString())) : null,
184
+ metaError: metaError ? new Error(metaError.message || metaError.toString()) : null,
185
+ richMetaError,
165
186
  metaErrorStack,
166
187
  isFetchingMeta: false,
167
188
  },
@@ -248,6 +269,7 @@ export default class QueryBuilder extends React.Component {
248
269
  const {
249
270
  meta,
250
271
  metaError,
272
+ richMetaError,
251
273
  query,
252
274
  queryError,
253
275
  chartType,
@@ -339,6 +361,7 @@ export default class QueryBuilder extends React.Component {
339
361
  return {
340
362
  meta,
341
363
  metaError,
364
+ richMetaError,
342
365
  metaErrorStack,
343
366
  query,
344
367
  error: queryError, // Match same name as QueryRenderer prop
@@ -518,7 +541,8 @@ export default class QueryBuilder extends React.Component {
518
541
  }
519
542
  } catch (error) {
520
543
  this.setState({
521
- queryError: new Error(generateAnsiHTML(error.message || error.toString())),
544
+ queryError: new Error(error.response?.plainError || error.message),
545
+ richQueryError: new Error(error.message || error.toString())
522
546
  });
523
547
  }
524
548
  }
@@ -575,21 +599,3 @@ export default class QueryBuilder extends React.Component {
575
599
  }
576
600
  }
577
601
  }
578
-
579
- QueryBuilder.defaultProps = {
580
- cubejsApi: null,
581
- stateChangeHeuristics: null,
582
- disableHeuristics: false,
583
- render: null,
584
- wrapWithQueryRenderer: true,
585
- defaultChartType: 'line',
586
- defaultQuery: {},
587
- initialVizState: null,
588
- onVizStateChanged: null,
589
-
590
- // deprecated
591
- query: null,
592
- setQuery: null,
593
- vizState: null,
594
- setVizState: null,
595
- };
@@ -3,9 +3,20 @@ import { equals, toPairs, fromPairs } from 'ramda';
3
3
  import { isQueryPresent } from '@cubejs-client/core';
4
4
 
5
5
  import CubeContext from './CubeContext';
6
- import { generateAnsiHTML } from './utils';
7
6
 
8
7
  export default class QueryRenderer extends React.Component {
8
+ static contextType = CubeContext;
9
+
10
+ static defaultProps = {
11
+ cubejsApi: null,
12
+ query: null,
13
+ render: null,
14
+ queries: null,
15
+ loadSql: null,
16
+ updateOnlyOnStateChange: false,
17
+ resetResultSetOnChange: true
18
+ };
19
+
9
20
  // @deprected use `isQueryPresent` from `@cubejs-client/core`
10
21
  static isQueryPresent(query) {
11
22
  return isQueryPresent(query);
@@ -136,7 +147,7 @@ export default class QueryRenderer extends React.Component {
136
147
  const { render } = this.props;
137
148
 
138
149
  const loadState = {
139
- error: error ? new Error(generateAnsiHTML(error.message || error.toString())) : null,
150
+ error: error ? new Error(error.response?.plainError || error.message || error.toString()) : null,
140
151
  resultSet: queries ? (resultSet || {}) : resultSet,
141
152
  loadingState: { isLoading },
142
153
  sqlQuery
@@ -149,15 +160,3 @@ export default class QueryRenderer extends React.Component {
149
160
  return null;
150
161
  }
151
162
  }
152
-
153
- QueryRenderer.contextType = CubeContext;
154
-
155
- QueryRenderer.defaultProps = {
156
- cubejsApi: null,
157
- query: null,
158
- render: null,
159
- queries: null,
160
- loadSql: null,
161
- updateOnlyOnStateChange: false,
162
- resetResultSetOnChange: true
163
- };
@@ -17,11 +17,4 @@ const QueryRendererWithTotals = ({ query, ...restProps }) => (
17
17
  />
18
18
  );
19
19
 
20
- QueryRendererWithTotals.defaultProps = {
21
- query: null,
22
- render: null,
23
- queries: null,
24
- loadSql: null
25
- };
26
-
27
20
  export default QueryRendererWithTotals;
package/src/utils.js CHANGED
@@ -1,81 +1,3 @@
1
- import Anser from 'anser';
2
- import { encode } from 'html-entities';
3
-
4
- const colors = {
5
- reset: 'orange',
6
- black: 'black',
7
- red: 'red',
8
- green: 'green',
9
- yellow: 'orange',
10
- blue: 'blue',
11
- magenta: 'magenta',
12
- cyan: 'cyan',
13
- gray: 'gray',
14
- lightgrey: 'lightgrey',
15
- darkgrey: 'darkgrey',
16
- };
17
-
18
- const anserMap = {
19
- 'ansi-bright-black': 'black',
20
- 'ansi-bright-yellow': 'yellow',
21
- 'ansi-yellow': 'yellow',
22
- 'ansi-bright-green': 'green',
23
- 'ansi-green': 'green',
24
- 'ansi-bright-cyan': 'cyan',
25
- 'ansi-cyan': 'cyan',
26
- 'ansi-bright-red': 'red',
27
- 'ansi-red': 'red',
28
- 'ansi-bright-magenta': 'magenta',
29
- 'ansi-magenta': 'magenta',
30
- 'ansi-white': 'darkgrey',
31
- };
32
-
33
- export function generateAnsiHTML(txt) {
34
- const arr = new Anser().ansiToJson(encode(txt), {
35
- use_classes: true,
36
- });
37
-
38
- let result = '';
39
- let open = false;
40
- for (let index = 0; index < arr.length; ++index) {
41
- const c = arr[index];
42
- const { content } = c;
43
- const { fg } = c;
44
-
45
- const contentParts = content.split('\n');
46
- for (let j = 0; j < contentParts.length; ++j) {
47
- if (!open) {
48
- result += '<span data-ansi-line="true">';
49
- open = true;
50
- }
51
- const part = contentParts[j].replace('\r', '');
52
- const color = colors[anserMap[fg]];
53
-
54
- if (color != null) {
55
- result += `<span style="color: ${color};">${part}</span>`;
56
- } else {
57
- if (fg != null) {
58
- console.log('Missing color mapping: ', fg);
59
- }
60
-
61
- result += `<span>${part}</span>`;
62
- }
63
-
64
- if (j < contentParts.length - 1) {
65
- result += '</span>';
66
- open = false;
67
- result += '<br/>';
68
- }
69
- }
70
- }
71
-
72
- if (open) {
73
- result += '</span>';
74
- }
75
-
76
- return result;
77
- }
78
-
79
1
  export function removeEmpty(obj) {
80
2
  if (typeof obj !== 'object') {
81
3
  return obj;