@zeedhi/teknisa-components-common 1.63.0 → 1.64.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.
@@ -540,21 +540,15 @@ class Notifications extends Iterable {
540
540
  this.createAccessors();
541
541
  }
542
542
  markAsRead({ event, element }) {
543
- if (this.events.markAllAsReadClick) {
544
- this.events.markAllAsReadClick({ event, element, component: this });
545
- }
543
+ this.callEvent('markAllAsReadClick', { event, element, component: this });
546
544
  }
547
545
  showAll(event, element) {
548
- if (this.events.showAllClick) {
549
- this.events.showAllClick({ event, element, component: this });
550
- }
546
+ this.callEvent('showAllClick', { event, element, component: this });
551
547
  }
552
548
  notificationClick(event, notification, element) {
553
- if (this.events.notificationClick) {
554
- this.events.notificationClick({
555
- event, notification, element, component: this,
556
- });
557
- }
549
+ this.callEvent('notificationClick', {
550
+ event, notification, element, component: this,
551
+ });
558
552
  }
559
553
  }
560
554
 
@@ -884,50 +878,34 @@ class GridBase {
884
878
  ];
885
879
  }
886
880
  addButtonClick({ event }) {
887
- if (this.grid.events.addClick) {
888
- this.grid.events.addClick({ component: this.grid, event });
889
- }
881
+ this.grid.callEvent('addClick', { component: this.grid, event });
890
882
  }
891
883
  deleteButtonClick({ event }) {
892
- if (this.grid.events.beforeDelete) {
893
- this.grid.events.beforeDelete({ component: this.grid, event });
894
- }
884
+ this.grid.callEvent('beforeDelete', { component: this.grid, event });
895
885
  if (!event.defaultPrevented) {
896
886
  this.grid.deleteRows();
897
- if (this.grid.events.afterDelete) {
898
- this.grid.events.afterDelete({ component: this.grid });
899
- }
887
+ this.grid.callEvent('afterDelete', { component: this.grid });
900
888
  }
901
889
  }
902
890
  reloadGrid() {
903
891
  this.grid.reload();
904
892
  }
905
893
  saveChanges({ event }) {
906
- if (this.grid.events.beforeSave) {
907
- this.grid.events.beforeSave({ component: this.grid, event });
908
- }
894
+ this.grid.callEvent('beforeSave', { component: this.grid, event });
909
895
  if (!event.defaultPrevented) {
910
896
  this.grid.saveEditedRows();
911
- if (this.grid.events.afterSave) {
912
- this.grid.events.afterSave({ component: this.grid });
913
- }
897
+ this.grid.callEvent('afterSave', { component: this.grid });
914
898
  }
915
899
  }
916
900
  cancelChanges({ event }) {
917
- if (this.grid.events.beforeCancel) {
918
- this.grid.events.beforeCancel({ component: this.grid, event });
919
- }
901
+ this.grid.callEvent('beforeCancel', { component: this.grid, event });
920
902
  if (!event.defaultPrevented) {
921
903
  this.grid.cancelEditedRows();
922
- if (this.grid.events.afterCancel) {
923
- this.grid.events.afterCancel({ component: this.grid });
924
- }
904
+ this.grid.callEvent('afterCancel', { component: this.grid });
925
905
  }
926
906
  }
927
907
  filterClick({ event }) {
928
- if (this.grid.events.filterClick) {
929
- this.grid.events.filterClick({ event, component: this.grid });
930
- }
908
+ this.grid.callEvent('filterClick', { component: this.grid, event });
931
909
  if (!event.defaultPrevented) {
932
910
  this.createFilterFromColumns();
933
911
  }
@@ -1169,9 +1147,7 @@ class GridBase {
1169
1147
  }
1170
1148
  });
1171
1149
  }
1172
- if (this.grid.events.beforeApplyFilter) {
1173
- this.grid.events.beforeApplyFilter({ event, component: this });
1174
- }
1150
+ this.grid.callEvent('beforeApplyFilter', { component: this.grid, event });
1175
1151
  if (!event.defaultPrevented) {
1176
1152
  datasource.get();
1177
1153
  this.filterModal.hide();
@@ -2403,13 +2379,17 @@ class TekGrid extends GridEditable {
2403
2379
  const reportFilter = new ReportFilter(dynamicFilter);
2404
2380
  filter = reportFilter.build();
2405
2381
  }
2382
+ let beforeOpen;
2383
+ if (typeof this.events.beforeOpenReport === 'function') {
2384
+ beforeOpen = this.events.beforeOpenReport;
2385
+ }
2406
2386
  return report.getReport(type, portrait, {
2407
2387
  metaData: merge(rowObj, {
2408
2388
  filter,
2409
2389
  groups: reportGroups,
2410
2390
  columns: reportAggregations,
2411
2391
  }),
2412
- }, this.events.beforeOpenReport).then((reportUrl) => window.open(reportUrl));
2392
+ }, beforeOpen).then((reportUrl) => window.open(reportUrl));
2413
2393
  });
2414
2394
  }
2415
2395
  initGrouping(lazyLoad) {
@@ -3146,13 +3126,17 @@ class TekTreeGrid extends TreeGridEditable {
3146
3126
  const reportFilter = new ReportFilter(this.datasource.dynamicFilter);
3147
3127
  filter = reportFilter.build();
3148
3128
  }
3129
+ let beforeOpen;
3130
+ if (typeof this.events.beforeOpenReport === 'function') {
3131
+ beforeOpen = this.events.beforeOpenReport;
3132
+ }
3149
3133
  return report.getReport(type, portrait, {
3150
3134
  metaData: merge(rowObj, {
3151
3135
  filter,
3152
3136
  groups: reportGroups,
3153
3137
  columns: reportAggregations,
3154
3138
  }),
3155
- }, this.events.beforeOpenReport).then((reportUrl) => window.open(reportUrl));
3139
+ }, beforeOpen).then((reportUrl) => window.open(reportUrl));
3156
3140
  });
3157
3141
  }
3158
3142
  setSearch(search) {
@@ -545,21 +545,15 @@
545
545
  this.createAccessors();
546
546
  }
547
547
  markAsRead({ event, element }) {
548
- if (this.events.markAllAsReadClick) {
549
- this.events.markAllAsReadClick({ event, element, component: this });
550
- }
548
+ this.callEvent('markAllAsReadClick', { event, element, component: this });
551
549
  }
552
550
  showAll(event, element) {
553
- if (this.events.showAllClick) {
554
- this.events.showAllClick({ event, element, component: this });
555
- }
551
+ this.callEvent('showAllClick', { event, element, component: this });
556
552
  }
557
553
  notificationClick(event, notification, element) {
558
- if (this.events.notificationClick) {
559
- this.events.notificationClick({
560
- event, notification, element, component: this,
561
- });
562
- }
554
+ this.callEvent('notificationClick', {
555
+ event, notification, element, component: this,
556
+ });
563
557
  }
564
558
  }
565
559
 
@@ -889,50 +883,34 @@
889
883
  ];
890
884
  }
891
885
  addButtonClick({ event }) {
892
- if (this.grid.events.addClick) {
893
- this.grid.events.addClick({ component: this.grid, event });
894
- }
886
+ this.grid.callEvent('addClick', { component: this.grid, event });
895
887
  }
896
888
  deleteButtonClick({ event }) {
897
- if (this.grid.events.beforeDelete) {
898
- this.grid.events.beforeDelete({ component: this.grid, event });
899
- }
889
+ this.grid.callEvent('beforeDelete', { component: this.grid, event });
900
890
  if (!event.defaultPrevented) {
901
891
  this.grid.deleteRows();
902
- if (this.grid.events.afterDelete) {
903
- this.grid.events.afterDelete({ component: this.grid });
904
- }
892
+ this.grid.callEvent('afterDelete', { component: this.grid });
905
893
  }
906
894
  }
907
895
  reloadGrid() {
908
896
  this.grid.reload();
909
897
  }
910
898
  saveChanges({ event }) {
911
- if (this.grid.events.beforeSave) {
912
- this.grid.events.beforeSave({ component: this.grid, event });
913
- }
899
+ this.grid.callEvent('beforeSave', { component: this.grid, event });
914
900
  if (!event.defaultPrevented) {
915
901
  this.grid.saveEditedRows();
916
- if (this.grid.events.afterSave) {
917
- this.grid.events.afterSave({ component: this.grid });
918
- }
902
+ this.grid.callEvent('afterSave', { component: this.grid });
919
903
  }
920
904
  }
921
905
  cancelChanges({ event }) {
922
- if (this.grid.events.beforeCancel) {
923
- this.grid.events.beforeCancel({ component: this.grid, event });
924
- }
906
+ this.grid.callEvent('beforeCancel', { component: this.grid, event });
925
907
  if (!event.defaultPrevented) {
926
908
  this.grid.cancelEditedRows();
927
- if (this.grid.events.afterCancel) {
928
- this.grid.events.afterCancel({ component: this.grid });
929
- }
909
+ this.grid.callEvent('afterCancel', { component: this.grid });
930
910
  }
931
911
  }
932
912
  filterClick({ event }) {
933
- if (this.grid.events.filterClick) {
934
- this.grid.events.filterClick({ event, component: this.grid });
935
- }
913
+ this.grid.callEvent('filterClick', { component: this.grid, event });
936
914
  if (!event.defaultPrevented) {
937
915
  this.createFilterFromColumns();
938
916
  }
@@ -1174,9 +1152,7 @@
1174
1152
  }
1175
1153
  });
1176
1154
  }
1177
- if (this.grid.events.beforeApplyFilter) {
1178
- this.grid.events.beforeApplyFilter({ event, component: this });
1179
- }
1155
+ this.grid.callEvent('beforeApplyFilter', { component: this.grid, event });
1180
1156
  if (!event.defaultPrevented) {
1181
1157
  datasource.get();
1182
1158
  this.filterModal.hide();
@@ -2408,13 +2384,17 @@
2408
2384
  const reportFilter = new ReportFilter(dynamicFilter);
2409
2385
  filter = reportFilter.build();
2410
2386
  }
2387
+ let beforeOpen;
2388
+ if (typeof this.events.beforeOpenReport === 'function') {
2389
+ beforeOpen = this.events.beforeOpenReport;
2390
+ }
2411
2391
  return report.getReport(type, portrait, {
2412
2392
  metaData: merge__default["default"](rowObj, {
2413
2393
  filter,
2414
2394
  groups: reportGroups,
2415
2395
  columns: reportAggregations,
2416
2396
  }),
2417
- }, this.events.beforeOpenReport).then((reportUrl) => window.open(reportUrl));
2397
+ }, beforeOpen).then((reportUrl) => window.open(reportUrl));
2418
2398
  });
2419
2399
  }
2420
2400
  initGrouping(lazyLoad) {
@@ -3151,13 +3131,17 @@
3151
3131
  const reportFilter = new ReportFilter(this.datasource.dynamicFilter);
3152
3132
  filter = reportFilter.build();
3153
3133
  }
3134
+ let beforeOpen;
3135
+ if (typeof this.events.beforeOpenReport === 'function') {
3136
+ beforeOpen = this.events.beforeOpenReport;
3137
+ }
3154
3138
  return report.getReport(type, portrait, {
3155
3139
  metaData: merge__default["default"](rowObj, {
3156
3140
  filter,
3157
3141
  groups: reportGroups,
3158
3142
  columns: reportAggregations,
3159
3143
  }),
3160
- }, this.events.beforeOpenReport).then((reportUrl) => window.open(reportUrl));
3144
+ }, beforeOpen).then((reportUrl) => window.open(reportUrl));
3161
3145
  });
3162
3146
  }
3163
3147
  setSearch(search) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/teknisa-components-common",
3
- "version": "1.63.0",
3
+ "version": "1.64.0",
4
4
  "description": "Teknisa Components Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -31,5 +31,5 @@
31
31
  "peerDependencies": {
32
32
  "@zeedhi/core": "*"
33
33
  },
34
- "gitHead": "b43f5f0f2f1a341165d854f1692022575356e13c"
34
+ "gitHead": "5594f5e85645cbc422c9e175b980624f08c447c2"
35
35
  }
@@ -193,8 +193,10 @@ describe('TekGrid', () => {
193
193
 
194
194
  describe('getReport()', () => {
195
195
  let httpReportSpy: jest.SpyInstance;
196
+ let reportSpy: jest.SpyInstance;
196
197
 
197
198
  beforeEach(() => {
199
+ reportSpy = jest.spyOn(Report.prototype, 'getReport').mockReturnValue(Promise.resolve(''));
198
200
  httpReportSpy = jest.spyOn(Http, 'post').mockImplementation((url) => {
199
201
  if (url === 'https://zhreport.teknisa.com/generateReport') {
200
202
  return Promise.resolve({
@@ -207,6 +209,7 @@ describe('TekGrid', () => {
207
209
  });
208
210
 
209
211
  afterEach(() => {
212
+ reportSpy.mockClear();
210
213
  httpReportSpy.mockReset();
211
214
  });
212
215
 
@@ -216,9 +219,11 @@ describe('TekGrid', () => {
216
219
  const instance = new TekGrid({
217
220
  name: 'grid_getReport',
218
221
  component: 'TekGrid',
222
+ events: {
223
+ beforeOpenReport: jest.fn(),
224
+ },
219
225
  });
220
226
 
221
- const spy = jest.spyOn(instance, 'getReport');
222
227
  instance.onCreated();
223
228
 
224
229
  const buttonProps = (instance as any).gridBase.exportConfigButtons[0] as IButton;
@@ -227,24 +232,13 @@ describe('TekGrid', () => {
227
232
  const event = new Event('click');
228
233
  button.click(event, {} as HTMLElement);
229
234
 
230
- expect(spy).toBeCalledTimes(1);
231
- spy.mockReset();
235
+ expect(reportSpy).toBeCalledTimes(1);
232
236
 
233
237
  (window as any).open.mockClear();
234
238
  });
235
239
 
236
240
  it('should call window open on getReport method', async () => {
237
241
  (window as any).open = jest.fn();
238
- const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
239
- data: {
240
- data: [],
241
- pagination: {
242
- page: 1,
243
- total: 0,
244
- limit: 10,
245
- },
246
- },
247
- }));
248
242
 
249
243
  const instance = new TekGrid({
250
244
  name: 'grid',
@@ -253,7 +247,7 @@ describe('TekGrid', () => {
253
247
  type: 'tek-rest',
254
248
  uniqueKey: 'id',
255
249
  route: '/zeedhi',
256
- lazyLoad: false,
250
+ lazyLoad: true,
257
251
  data: [
258
252
  { id: '1', department_id: '1' },
259
253
  ],
@@ -279,7 +273,6 @@ describe('TekGrid', () => {
279
273
 
280
274
  (window as any).open.mockClear();
281
275
  spy.mockReset();
282
- httpSpy.mockReset();
283
276
  });
284
277
 
285
278
  it('when called with a dynamicFilter, should format the filter values', async () => {
@@ -1,5 +1,5 @@
1
1
  import {
2
- Button, Form, IButton, IForm, IModal, Modal, ModalService, Text, TextInput,
2
+ Button, Form, IButton, IForm, IModal, Modal, ModalService, Report, Text, TextInput,
3
3
  } from '@zeedhi/common';
4
4
  import { Http, IDictionary, Metadata } from '@zeedhi/core';
5
5
  import {
@@ -7,6 +7,8 @@ import {
7
7
  } from '../../../../src';
8
8
  import { getChild, setClick } from '../../../__helpers__';
9
9
 
10
+ const flushPromises = () => new Promise(setImmediate);
11
+
10
12
  const clickOnFilterButton = (grid: TekTreeGrid, event?: any) => {
11
13
  const buttonProps = getChild<IButton>(grid.toolbarSlot, `${grid.name}_filterButton`);
12
14
  const button = new Button(buttonProps);
@@ -336,8 +338,10 @@ describe('TekTreeGrid', () => {
336
338
 
337
339
  describe('getReport()', () => {
338
340
  let httpReportSpy: jest.SpyInstance;
341
+ let reportSpy: jest.SpyInstance;
339
342
 
340
343
  beforeEach(() => {
344
+ reportSpy = jest.spyOn(Report.prototype, 'getReport').mockReturnValue(Promise.resolve(''));
341
345
  httpReportSpy = jest.spyOn(Http, 'post').mockImplementation((url) => {
342
346
  if (url === 'https://zhreport.teknisa.com/generateReport') {
343
347
  return Promise.resolve({
@@ -350,6 +354,7 @@ describe('TekTreeGrid', () => {
350
354
  });
351
355
 
352
356
  afterEach(() => {
357
+ reportSpy.mockClear();
353
358
  httpReportSpy.mockClear();
354
359
  });
355
360
 
@@ -359,9 +364,11 @@ describe('TekTreeGrid', () => {
359
364
  const instance = new TekTreeGrid({
360
365
  name: 'grid_getReport',
361
366
  component: 'TekTreeGrid',
367
+ events: {
368
+ beforeOpenReport: jest.fn(),
369
+ },
362
370
  });
363
371
 
364
- const spy = jest.spyOn(instance, 'getReport');
365
372
  instance.onCreated();
366
373
 
367
374
  const buttonProps = (instance as any).gridBase.exportConfigButtons[0] as IButton;
@@ -370,24 +377,13 @@ describe('TekTreeGrid', () => {
370
377
  const event = new Event('click');
371
378
  button.click(event, {} as HTMLElement);
372
379
 
373
- expect(spy).toBeCalledTimes(1);
374
- spy.mockClear();
380
+ expect(reportSpy).toBeCalledTimes(1);
375
381
 
376
382
  (window as any).open.mockClear();
377
383
  });
378
384
 
379
385
  it('should call window open on getReport method', async () => {
380
386
  (window as any).open = jest.fn();
381
- const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
382
- data: {
383
- data: [],
384
- pagination: {
385
- page: 1,
386
- total: 0,
387
- limit: 10,
388
- },
389
- },
390
- }));
391
387
 
392
388
  const instance = new TekTreeGrid({
393
389
  name: 'grid',
@@ -420,7 +416,6 @@ describe('TekTreeGrid', () => {
420
416
 
421
417
  (window as any).open.mockClear();
422
418
  spy.mockClear();
423
- httpSpy.mockClear();
424
419
  });
425
420
  });
426
421
 
@@ -462,7 +457,6 @@ describe('TekTreeGrid', () => {
462
457
  });
463
458
 
464
459
  it('should not call events.rowClick if cellClick prevents it', async () => {
465
- const flushPromises = () => new Promise(setImmediate);
466
460
  const rowClick = jest.fn();
467
461
 
468
462
  const data = [
@@ -1,4 +1,4 @@
1
- import { IBeforeReportEvent, IComponent, IComponentEvents, IComponentRender, IGridColumnEditable, IGridEditable, IIterableColumnsButton } from '@zeedhi/common';
1
+ import { IBeforeReportEvent, IComponent, IComponentEvents, IComponentRender, IGridColumnEditable, IGridEditable, IIterableColumnsButton, EventDef } from '@zeedhi/common';
2
2
  import { IDictionary, IEvent, IEventParam, IDateHelperValue, IDateHelperValues } from '@zeedhi/core';
3
3
  import { IDynamicFilterItem, TekGridLayoutOptions } from '..';
4
4
  export interface ITekGridLayoutEventParams extends IEventParam<ITekGrid> {
@@ -6,21 +6,21 @@ export interface ITekGridLayoutEventParams extends IEventParam<ITekGrid> {
6
6
  }
7
7
  export declare type ITekGridEvent<T> = (event: T) => Promise<any>;
8
8
  export interface ITekGridEvents<T = IEventParam<any> | ITekGridLayoutEventParams> extends IComponentEvents<T> {
9
- addClick?: IEvent<T>;
10
- afterCancel?: IEvent<T>;
11
- afterDelete?: IEvent<T>;
12
- afterSave?: IEvent<T>;
13
- beforeApplyFilter?: IEvent<T>;
14
- beforeCancel?: IEvent<T>;
15
- beforeDelete?: IEvent<T>;
16
- beforeSave?: IEvent<T>;
17
- filterClick?: IEvent<T>;
18
- loadLayouts?: ITekGridEvent<T>;
19
- saveLayouts?: IEvent<T>;
20
- groupRowClick?: IEvent<T>;
21
- groupSelect?: IEvent<T>;
22
- groupUnselect?: IEvent<T>;
23
- beforeOpenReport?: IBeforeReportEvent;
9
+ addClick?: EventDef<T>;
10
+ afterCancel?: EventDef<T>;
11
+ afterDelete?: EventDef<T>;
12
+ afterSave?: EventDef<T>;
13
+ beforeApplyFilter?: EventDef<T>;
14
+ beforeCancel?: EventDef<T>;
15
+ beforeDelete?: EventDef<T>;
16
+ beforeSave?: EventDef<T>;
17
+ filterClick?: EventDef<T>;
18
+ loadLayouts?: EventDef<T, ITekGridEvent<T>>;
19
+ saveLayouts?: EventDef<T>;
20
+ groupRowClick?: EventDef<T>;
21
+ groupSelect?: EventDef<T>;
22
+ groupUnselect?: EventDef<T>;
23
+ beforeOpenReport?: EventDef<T, IBeforeReportEvent>;
24
24
  [key: string]: any;
25
25
  }
26
26
  export declare type ITekGridLayoutOptionsEvent<T> = (event: T) => Promise<any>;
@@ -1,5 +1,5 @@
1
- import { IIterable, IComponentEvents } from '@zeedhi/common';
2
- import { IEventParam, IEvent } from '@zeedhi/core';
1
+ import { IIterable, IComponentEvents, EventDef } from '@zeedhi/common';
2
+ import { IEventParam } from '@zeedhi/core';
3
3
  import { Notifications } from './notifications';
4
4
  export interface INotification {
5
5
  id: string;
@@ -12,9 +12,9 @@ export interface INotificationsEvent extends IEventParam<Notifications> {
12
12
  notification: INotification;
13
13
  }
14
14
  export interface INotificationsEvents<T = INotificationsEvent | IEventParam<any>> extends IComponentEvents<T> {
15
- showAllClick?: IEvent<T>;
16
- notificationClick?: IEvent<T>;
17
- markAllAsReadClick?: IEvent<T>;
15
+ showAllClick?: EventDef<T>;
16
+ notificationClick?: EventDef<T>;
17
+ markAllAsReadClick?: EventDef<T>;
18
18
  }
19
19
  export interface INotifications extends IIterable {
20
20
  allNotificationsPath?: string;