@zeedhi/teknisa-components-common 1.106.0 → 1.107.0

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.
@@ -1,5 +1,5 @@
1
1
  import { KeyMap, I18n, FormatterParserProvider, Messages, Metadata, DatasourceFactory, MemoryDatasource, URL, Utils, RestDatasource, Config, Accessor, Loader, DateHelper, Http, Singleton, VersionService } from '@zeedhi/core';
2
- import { Form, Button, Tooltip, GridEditable, Grid, ComponentRender, Iterable, Carousel, IterableComponentRender as IterableComponentRender$1, Loading as Loading$1, GridColumnEditable, Report, ColumnNotFoundError, IterableColumnsButtonController, IterableColumnsButton, ModalService, SelectMultiple, TreeGridEditable, List } from '@zeedhi/common';
2
+ import { Form, Button, Tooltip, GridEditable, Grid, ComponentRender, Iterable, Carousel, IterableComponentRender as IterableComponentRender$1, Loading as Loading$1, GridColumnEditable, Report, EmptyDataError, AlertService, ColumnNotFoundError, IterableColumnsButtonController, IterableColumnsButton, ModalService, SelectMultiple, TreeGridEditable, List } from '@zeedhi/common';
3
3
  import debounce from 'lodash.debounce';
4
4
  import merge from 'lodash.merge';
5
5
  import { UserInfo } from '@zeedhi/zd-user-info-common';
@@ -1254,6 +1254,7 @@ Messages.add({
1254
1254
  TEKGRID_HELPERVALUE_CURRENT_YEAR: 'Ano Atual',
1255
1255
  TEKGRID_WITH_GROUPS: '(Com grupos)',
1256
1256
  TEKGRID_GRID_MIRROR: '(Espelho do grid)',
1257
+ TEKGRID_NO_DATA: 'Não há dados para gerar o relatório',
1257
1258
  },
1258
1259
  },
1259
1260
  'en-US': {
@@ -1326,6 +1327,7 @@ Messages.add({
1326
1327
  TEKGRID_HELPERVALUE_CURRENT_YEAR: 'Current Year',
1327
1328
  TEKGRID_WITH_GROUPS: '(With groups)',
1328
1329
  TEKGRID_GRID_MIRROR: '(Grid mirror)',
1330
+ TEKGRID_NO_DATA: 'There is no data to generate the report',
1329
1331
  },
1330
1332
  },
1331
1333
  'es-CL': {
@@ -1398,6 +1400,7 @@ Messages.add({
1398
1400
  TEKGRID_HELPERVALUE_CURRENT_YEAR: 'Año actual',
1399
1401
  TEKGRID_WITH_GROUPS: '(Con grupos)',
1400
1402
  TEKGRID_GRID_MIRROR: '(Espejo de grid)',
1403
+ TEKGRID_NO_DATA: 'No hay datos para generar el reporte',
1401
1404
  },
1402
1405
  },
1403
1406
  });
@@ -2490,16 +2493,25 @@ class TekGrid extends GridEditable {
2490
2493
  if (typeof this.events.beforeOpenReport === 'function') {
2491
2494
  beforeOpen = this.events.beforeOpenReport;
2492
2495
  }
2493
- return report
2494
- .getReport(typeValue, portrait, {
2495
- metaData: merge(rowObj, {
2496
- filter,
2497
- groups: reportGroups,
2498
- columns: reportAggregations,
2499
- xlsDefaultType: this.xlsDefaultType,
2500
- }),
2501
- }, beforeOpen)
2502
- .then((reportUrl) => window.open(reportUrl));
2496
+ try {
2497
+ const reportUrl = yield report
2498
+ .getReport(typeValue, portrait, {
2499
+ metaData: merge(rowObj, {
2500
+ filter,
2501
+ groups: reportGroups,
2502
+ columns: reportAggregations,
2503
+ xlsDefaultType: this.xlsDefaultType,
2504
+ }),
2505
+ }, beforeOpen);
2506
+ window.open(reportUrl);
2507
+ }
2508
+ catch (e) {
2509
+ if (e instanceof EmptyDataError) {
2510
+ AlertService.show({ name: 'no-data-warning', text: I18n.translate('TEKGRID_NO_DATA'), color: 'warning' });
2511
+ return;
2512
+ }
2513
+ throw e;
2514
+ }
2503
2515
  });
2504
2516
  }
2505
2517
  registerTask(task) {
@@ -1258,6 +1258,7 @@
1258
1258
  TEKGRID_HELPERVALUE_CURRENT_YEAR: 'Ano Atual',
1259
1259
  TEKGRID_WITH_GROUPS: '(Com grupos)',
1260
1260
  TEKGRID_GRID_MIRROR: '(Espelho do grid)',
1261
+ TEKGRID_NO_DATA: 'Não há dados para gerar o relatório',
1261
1262
  },
1262
1263
  },
1263
1264
  'en-US': {
@@ -1330,6 +1331,7 @@
1330
1331
  TEKGRID_HELPERVALUE_CURRENT_YEAR: 'Current Year',
1331
1332
  TEKGRID_WITH_GROUPS: '(With groups)',
1332
1333
  TEKGRID_GRID_MIRROR: '(Grid mirror)',
1334
+ TEKGRID_NO_DATA: 'There is no data to generate the report',
1333
1335
  },
1334
1336
  },
1335
1337
  'es-CL': {
@@ -1402,6 +1404,7 @@
1402
1404
  TEKGRID_HELPERVALUE_CURRENT_YEAR: 'Año actual',
1403
1405
  TEKGRID_WITH_GROUPS: '(Con grupos)',
1404
1406
  TEKGRID_GRID_MIRROR: '(Espejo de grid)',
1407
+ TEKGRID_NO_DATA: 'No hay datos para generar el reporte',
1405
1408
  },
1406
1409
  },
1407
1410
  });
@@ -2494,16 +2497,25 @@
2494
2497
  if (typeof this.events.beforeOpenReport === 'function') {
2495
2498
  beforeOpen = this.events.beforeOpenReport;
2496
2499
  }
2497
- return report
2498
- .getReport(typeValue, portrait, {
2499
- metaData: merge__default["default"](rowObj, {
2500
- filter,
2501
- groups: reportGroups,
2502
- columns: reportAggregations,
2503
- xlsDefaultType: this.xlsDefaultType,
2504
- }),
2505
- }, beforeOpen)
2506
- .then((reportUrl) => window.open(reportUrl));
2500
+ try {
2501
+ const reportUrl = yield report
2502
+ .getReport(typeValue, portrait, {
2503
+ metaData: merge__default["default"](rowObj, {
2504
+ filter,
2505
+ groups: reportGroups,
2506
+ columns: reportAggregations,
2507
+ xlsDefaultType: this.xlsDefaultType,
2508
+ }),
2509
+ }, beforeOpen);
2510
+ window.open(reportUrl);
2511
+ }
2512
+ catch (e) {
2513
+ if (e instanceof common.EmptyDataError) {
2514
+ common.AlertService.show({ name: 'no-data-warning', text: core.I18n.translate('TEKGRID_NO_DATA'), color: 'warning' });
2515
+ return;
2516
+ }
2517
+ throw e;
2518
+ }
2507
2519
  });
2508
2520
  }
2509
2521
  registerTask(task) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/teknisa-components-common",
3
- "version": "1.106.0",
3
+ "version": "1.107.0",
4
4
  "description": "Teknisa Components Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -32,5 +32,5 @@
32
32
  "peerDependencies": {
33
33
  "@zeedhi/core": "^1.97.0"
34
34
  },
35
- "gitHead": "665962544705695986852f9d8719e6e6716e6587"
35
+ "gitHead": "1123e6f810f91d3dbff16805911d4558caf9d6b2"
36
36
  }
@@ -314,7 +314,7 @@ describe('TekRestDatasource', () => {
314
314
  search_in: [],
315
315
  page: 1,
316
316
  limit: 10,
317
- search_in_params: "{}",
317
+ search_in_params: '{}',
318
318
  },
319
319
  }));
320
320
  });
@@ -2,6 +2,8 @@
2
2
 
3
3
  import {
4
4
  Button, Dropdown, IModal, Modal, ModalService, Search, TextInput, Text, Report,
5
+ AlertService,
6
+ EmptyDataError,
5
7
  } from '@zeedhi/common';
6
8
  import {
7
9
  KeyMap, Http, Metadata, IDictionary, IEventParam,
@@ -375,7 +377,7 @@ describe('TekGrid', () => {
375
377
 
376
378
  const getReport = async () => { await instance.getReport('pdf'); };
377
379
 
378
- expect(getReport).rejects.not.toEqual(new Error());
380
+ expect(getReport).not.toThrow();
379
381
 
380
382
  const getColumnSpy = jest.spyOn(instance, 'getColumn').mockImplementationOnce(() => {
381
383
  throw Error();
@@ -414,6 +416,37 @@ describe('TekGrid', () => {
414
416
  },
415
417
  }, undefined);
416
418
  });
419
+
420
+ it('when data is empty, should show alert', async () => {
421
+ reportSpy = jest.spyOn(Report.prototype, 'getReport').mockImplementation(() => { throw new EmptyDataError(); });
422
+ const alertSpy = jest.spyOn(AlertService, 'show').mockImplementation(() => 1);
423
+
424
+ const instance = new TekGrid({
425
+ name: 'grid',
426
+ component: 'TekGrid',
427
+ datasource: {
428
+ data: [],
429
+ },
430
+ });
431
+
432
+ expect(async () => instance.getReport('xls2')).not.toThrow();
433
+
434
+ expect(alertSpy).toHaveBeenCalledWith({ name: 'no-data-warning', text: 'TEKGRID_NO_DATA', color: 'warning' });
435
+ });
436
+
437
+ it('when an error happens, should throw normally', async () => {
438
+ reportSpy = jest.spyOn(Report.prototype, 'getReport').mockImplementation(() => { throw new Error(); });
439
+
440
+ const instance = new TekGrid({
441
+ name: 'grid',
442
+ component: 'TekGrid',
443
+ datasource: {
444
+ data: [],
445
+ },
446
+ });
447
+
448
+ expect(async () => instance.getReport('xls2')).rejects.toThrow();
449
+ });
417
450
  });
418
451
 
419
452
  describe('saveChanges()', () => {
@@ -101,7 +101,7 @@ export declare class TekGrid extends GridEditable implements ITekGrid {
101
101
  columnHasFilterData(column: TekGridColumn): boolean;
102
102
  private buildReportGroups;
103
103
  private buildReportAggregations;
104
- getReport(type: string, portrait?: boolean, rowObj?: any): Promise<Window | null>;
104
+ getReport(type: string, portrait?: boolean, rowObj?: any): Promise<void>;
105
105
  private groups;
106
106
  private summary;
107
107
  private originalDatasourceLoadAll?;