@datarailsshared/dr_renderer 1.4.67 → 1.4.78

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/src/pivottable.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const helpers = require('./dr-renderer-helpers');
2
+ const { GenericRenderingError, GenericComputationalError} = require('./errors');
2
3
 
3
4
  // from pivottable@2.23.0
4
5
  let initPivotTable = function($, window, document) {
@@ -9,7 +10,7 @@ let initPivotTable = function($, window, document) {
9
10
  /*
10
11
  Utilities
11
12
  */
12
- var PivotData, addSeparators, aggregatorTemplates, aggregators, dayNamesEn, derivers, getSort, locales, mthNamesEn, naturalSort, numberFormat, pivotTableRenderer, rd, renderers, rx, rz, sortAs, usFmt, usFmtInt, usFmtPct, zeroPad, errorHandling;
13
+ var PivotData, addSeparators, aggregatorTemplates, aggregators, dayNamesEn, derivers, getSort, locales, mthNamesEn, naturalSort, numberFormat, pivotTableRenderer, rd, renderers, rx, rz, sortAs, usFmt, usFmtInt, usFmtPct, zeroPad;
13
14
  addSeparators = function(nStr, thousandsSep, decimalSep) {
14
15
  var rgx, x, x1, x2;
15
16
  nStr += '';
@@ -434,9 +435,6 @@ let initPivotTable = function($, window, document) {
434
435
  aggregators: aggregators,
435
436
  renderers: renderers,
436
437
  localeStrings: {
437
- renderError: "An error occurred rendering the PivotTable results.",
438
- computeError: "An error occurred computing the PivotTable results.",
439
- uiRenderError: "An error occurred rendering the PivotTable UI.",
440
438
  selectAll: "Select All",
441
439
  selectNone: "Select None",
442
440
  tooMany: "(too many to list)",
@@ -614,47 +612,6 @@ let initPivotTable = function($, window, document) {
614
612
  }
615
613
  return naturalSort;
616
614
  };
617
- errorHandling = {
618
- placeholders: {
619
- nodata: {
620
- title: 'No Data Available',
621
- text: 'This might happen because of a global filter or a change in the underlying data',
622
- btnText: '',
623
- class: 'nodata',
624
- },
625
- noPermission: {
626
- title: 'No Permission',
627
- text: 'You do not have permission to view the data',
628
- btnText: 'Request Permission',
629
- class: 'no-permission',
630
- },
631
- tooMuchData: {
632
- title: 'There is too much data. Please edit this widget',
633
- text: '',
634
- btnText: 'Edit Widget',
635
- class: 'too-much-data',
636
- },
637
- noPublishItem: {
638
- title: 'We can’t find the published item in the source file',
639
- text: '',
640
- btnText: 'Go to filebox',
641
- class: 'no-publish-item',
642
- },
643
- },
644
- getErrorPlaceholder: function(placeholder) {
645
- if (placeholder && typeof placeholder === 'object') {
646
- return $(`
647
- <div class="noData">
648
- <div class="noData-title">${placeholder.title}</div>
649
- <i class="noData-image ${placeholder.class}"></i>
650
- <div class="noData-text">${placeholder.text}</div>
651
- <div class="noData-error-action"></div>
652
- </div>
653
- `);
654
- }
655
- return null;
656
- },
657
- };
658
615
 
659
616
  /*
660
617
  Data Model class
@@ -964,7 +921,6 @@ let initPivotTable = function($, window, document) {
964
921
  numberFormat: numberFormat,
965
922
  sortAs: sortAs,
966
923
  PivotData: PivotData,
967
- errorHandling: errorHandling,
968
924
  };
969
925
  if (window.$) {
970
926
  window.$.pivotUtilities = $.pivotUtilities
@@ -1229,24 +1185,23 @@ let initPivotTable = function($, window, document) {
1229
1185
  localeStrings: localeStrings
1230
1186
  };
1231
1187
  opts = $.extend(true, {}, localeDefaults, $.extend({}, defaults, inputOpts));
1232
- result = null;
1233
1188
  try {
1234
1189
  pivotData = new opts.dataClass(input, opts);
1235
1190
  try {
1236
1191
  result = opts.renderer(pivotData, opts.rendererOptions);
1237
1192
  } catch (error) {
1238
- e = error;
1239
- if (typeof console !== "undefined" && console !== null) {
1240
- console.error(e.stack);
1241
- }
1242
- result = $("<span>").html(opts.localeStrings.renderError);
1193
+ const genericRenderingError = new GenericRenderingError();
1194
+ console.error(genericRenderingError.title);
1195
+ throw genericRenderingError;
1243
1196
  }
1244
1197
  } catch (error) {
1245
- e = error;
1246
- if (typeof console !== "undefined" && console !== null) {
1247
- console.error(e.stack);
1198
+ if (error instanceof GenericRenderingError) {
1199
+ throw error;
1200
+ } else {
1201
+ const genericComputationalError = new GenericComputationalError();
1202
+ console.error(genericComputationalError.title);
1203
+ throw genericComputationalError;
1248
1204
  }
1249
- result = $("<span>").html(opts.localeStrings.computeError);
1250
1205
  }
1251
1206
  x = this[0];
1252
1207
  while (x.hasChildNodes()) {
@@ -1748,7 +1703,9 @@ let initPivotTable = function($, window, document) {
1748
1703
  if (typeof console !== "undefined" && console !== null) {
1749
1704
  console.error(e.stack);
1750
1705
  }
1751
- this.html(opts.localeStrings.uiRenderError);
1706
+ // This function is not used internally or in webclient_angular/export_widget_service
1707
+ // TODO if it not removed in DR-39041, upgrade the error propagation
1708
+ this.html("An error occurred rendering the PivotTable UI.");
1752
1709
  }
1753
1710
  return this;
1754
1711
  };
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Enum for dr renderer error codes.
3
+ */
4
+ export type RendererErrorCodes = number;
5
+ export namespace RendererErrorCodes {
6
+ let NoDataError: number;
7
+ let TooMuchDataError: number;
8
+ let DataConflictError: number;
9
+ let GaugeConfigurationError: number;
10
+ let GenericRenderingError: number;
11
+ let GenericComputationalError: number;
12
+ }
13
+ /**
14
+ * Base error class for all renderer-related errors.
15
+ * @class BaseRendererError
16
+ * @extends Error
17
+ */
18
+ export class BaseRendererError extends Error {
19
+ /**
20
+ * Creates a new BaseRendererError instance.
21
+ * @param {Object} config - Error configuration object
22
+ * @param {number} config.code - Unique error code
23
+ * @param {string} config.title - Error title/message
24
+ * @param {Object} [config.options={}] - Additional error options or context
25
+ */
26
+ constructor({ code, title, options }: {
27
+ code: number;
28
+ title: string;
29
+ options?: Object | undefined;
30
+ });
31
+ /**
32
+ * Error code for identification purposes
33
+ * @type {number}
34
+ */
35
+ code: number;
36
+ /**
37
+ * Human-readable error title
38
+ * @type {string}
39
+ */
40
+ title: string;
41
+ /**
42
+ * Additional options or context for the error
43
+ * @type {Object}
44
+ */
45
+ options: Object;
46
+ }
47
+ /**
48
+ * Error thrown when there is too much data to render efficiently.
49
+ * @class TooMuchDataError
50
+ * @extends BaseRendererError
51
+ */
52
+ export class TooMuchDataError extends BaseRendererError {
53
+ /**
54
+ * Creates a new TooMuchDataError instance.
55
+ * This error is thrown when the dataset exceeds the renderer's capacity
56
+ * and requires the user to edit the widget.
57
+ */
58
+ constructor();
59
+ }
60
+ /**
61
+ * Error thrown when no data is available.
62
+ * @class NoDataError
63
+ * @extends BaseRendererError
64
+ */
65
+ export class NoDataError extends BaseRendererError {
66
+ /**
67
+ * Creates a new NoDataError instance.
68
+ * This error is thrown when a widget or component has no available data.
69
+ */
70
+ constructor();
71
+ }
72
+ /**
73
+ * Error thrown when there are conflicts in the data being processed.
74
+ * @class DataConflictError
75
+ * @extends BaseRendererError
76
+ */
77
+ export class DataConflictError extends BaseRendererError {
78
+ /**
79
+ * Creates a new DataConflictError instance.
80
+ * @param {Object} [options] - Additional context about the data conflict.
81
+ */
82
+ constructor(options?: Object);
83
+ }
84
+ /**
85
+ * Error thrown when a gauge chart is missing required info.
86
+ * @class GaugeConfigurationError
87
+ * @extends BaseRendererError
88
+ */
89
+ export class GaugeConfigurationError extends BaseRendererError {
90
+ /**
91
+ * Creates a new GaugeConfigurationError instance.
92
+ */
93
+ constructor();
94
+ }
95
+ /**
96
+ * Generic error for rendering failures in PivotTable components.
97
+ * @class GenericRenderingError
98
+ * @extends BaseRendererError
99
+ */
100
+ export class GenericRenderingError extends BaseRendererError {
101
+ /**
102
+ * Creates a new GenericRenderingError instance.
103
+ * This error is thrown when an unexpected error occurs during
104
+ * the rendering process of PivotTable results.
105
+ */
106
+ constructor();
107
+ }
108
+ /**
109
+ * Generic error for computational failures in PivotTable components.
110
+ * @class GenericComputationalError
111
+ * @extends BaseRendererError
112
+ */
113
+ export class GenericComputationalError extends BaseRendererError {
114
+ /**
115
+ * Creates a new GenericComputationalError instance.
116
+ * This error is thrown when an unexpected error occurs during
117
+ * the computation process of PivotTable results.
118
+ */
119
+ constructor();
120
+ }
@@ -1 +1,2 @@
1
- export * from './graph-table-renderer';
1
+ export * from './graph-table-renderer';
2
+ export * from './errors'
@@ -0,0 +1,157 @@
1
+ const {
2
+ BaseRendererError,
3
+ NoDataError,
4
+ TooMuchDataError,
5
+ DataConflictError,
6
+ GaugeConfigurationError,
7
+ GenericRenderingError,
8
+ GenericComputationalError
9
+ } = require('../src/errors');
10
+
11
+ describe('Error Classes', () => {
12
+ describe('BaseRendererError', () => {
13
+ it('should create instance with provided code and title', () => {
14
+ const error = new BaseRendererError({ code: 5, title: 'Test Error' });
15
+
16
+ expect(error.code).toBe(5);
17
+ expect(error.title).toBe('Test Error');
18
+ });
19
+
20
+ it('should create instance with options parameter', () => {
21
+ const options = { isBreakdown: true, minCategories: 5 };
22
+ const error = new BaseRendererError({ code: 5, title: 'Test Error', options });
23
+
24
+ expect(error.code).toBe(5);
25
+ expect(error.title).toBe('Test Error');
26
+ expect(error.options).toEqual(options);
27
+ });
28
+
29
+ it('should set empty options object when no options provided', () => {
30
+ const error = new BaseRendererError({ code: 1, title: 'Test' });
31
+
32
+ expect(error.options).toEqual({});
33
+ });
34
+
35
+ it('should be instance of BaseRendererError', () => {
36
+ const error = new BaseRendererError({ code: 1, title: 'Test' });
37
+ expect(error).toBeInstanceOf(BaseRendererError);
38
+ });
39
+
40
+ it('should be instance of Error', () => {
41
+ const error = new BaseRendererError({ code: 1, title: 'Test' });
42
+ expect(error).toBeInstanceOf(Error);
43
+ });
44
+ });
45
+
46
+ describe('NoDataError', () => {
47
+ it('should create instance with correct code and title', () => {
48
+ const error = new NoDataError();
49
+
50
+ expect(error.code).toBe(1);
51
+ expect(error.title).toBe('No Data Available');
52
+ });
53
+
54
+ it('should be instance of BaseRendererError', () => {
55
+ const error = new NoDataError();
56
+ expect(error).toBeInstanceOf(BaseRendererError);
57
+ });
58
+ });
59
+
60
+ describe('TooMuchDataError', () => {
61
+ it('should create instance with correct code and title', () => {
62
+ const error = new TooMuchDataError();
63
+
64
+ expect(error.code).toBe(3);
65
+ expect(error.title).toBe('There is too much data. Please edit this widget');
66
+ });
67
+
68
+ it('should be instance of BaseRendererError', () => {
69
+ const error = new TooMuchDataError();
70
+ expect(error).toBeInstanceOf(BaseRendererError);
71
+ });
72
+ });
73
+
74
+ describe('DataConflictError', () => {
75
+ it('should create instance with correct code and title', () => {
76
+ const error = new DataConflictError();
77
+
78
+ expect(error.code).toBe(5);
79
+ expect(error.title).toBe('Data Conflict');
80
+ });
81
+
82
+ it('should create instance with options parameter', () => {
83
+ const options = {
84
+ isBreakdown: true,
85
+ uniqueCategories: ['A', 'B'],
86
+ minCategories: 5,
87
+ maxCategories: 10
88
+ };
89
+ const error = new DataConflictError(options);
90
+
91
+ expect(error.code).toBe(5);
92
+ expect(error.title).toBe('Data Conflict');
93
+ expect(error.options).toEqual(options);
94
+ });
95
+
96
+ it('should create instance with empty options when none provided', () => {
97
+ const error = new DataConflictError();
98
+
99
+ expect(error.options).toEqual({});
100
+ });
101
+ });
102
+
103
+ describe('GaugeConfigurationError', () => {
104
+ it('should create instance with correct code and title', () => {
105
+ const error = new GaugeConfigurationError();
106
+
107
+ expect(error.code).toBe(6);
108
+ expect(error.title).toBe('Please configure goal and needle');
109
+ });
110
+
111
+ it('should create instance with empty options', () => {
112
+ const error = new GaugeConfigurationError();
113
+
114
+ expect(error.options).toEqual({});
115
+ });
116
+ });
117
+
118
+ describe('GenericRenderingError', () => {
119
+ it('should create instance with correct code and title', () => {
120
+ const error = new GenericRenderingError();
121
+
122
+ expect(error.code).toBe(7);
123
+ expect(error.title).toBe('An error occurred rendering the PivotTable results.');
124
+ });
125
+
126
+ it('should create instance with empty options', () => {
127
+ const error = new GenericRenderingError();
128
+
129
+ expect(error.options).toEqual({});
130
+ });
131
+
132
+ it('should be instance of BaseRendererError', () => {
133
+ const error = new GenericRenderingError();
134
+ expect(error).toBeInstanceOf(BaseRendererError);
135
+ });
136
+ });
137
+
138
+ describe('GenericComputationalError', () => {
139
+ it('should create instance with correct code and title', () => {
140
+ const error = new GenericComputationalError();
141
+
142
+ expect(error.code).toBe(8);
143
+ expect(error.title).toBe('An error occurred computing the PivotTable results.');
144
+ });
145
+
146
+ it('should create instance with empty options', () => {
147
+ const error = new GenericComputationalError();
148
+
149
+ expect(error.options).toEqual({});
150
+ });
151
+
152
+ it('should be instance of BaseRendererError', () => {
153
+ const error = new GenericComputationalError();
154
+ expect(error).toBeInstanceOf(BaseRendererError);
155
+ });
156
+ });
157
+ });