@sankhyalabs/core 4.7.0 → 4.9.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.
@@ -42,6 +42,7 @@ export default class DataUnit {
42
42
  private _pageSize: number;
43
43
  private _childByName = new Map<string, DataUnit>();
44
44
  private _parentDataUnit: DataUnit | undefined;
45
+ private _loadingLockers: Promise<void>[];
45
46
 
46
47
  public metadataLoader?: (dataUnit: DataUnit) => Promise<UnitMetadata>;
47
48
  public dataLoader?: (dataUnit: DataUnit, request: LoadDataRequest) => Promise<LoadDataResponse>;
@@ -74,6 +75,7 @@ export default class DataUnit {
74
75
  this._interceptors = [];
75
76
  this._parentDataUnit = parentDataUnit;
76
77
  this._parentDataUnit?.subscribe(this.onDataUnitParentEvent);
78
+ this._loadingLockers = [];
77
79
  DataUnitStorage.put(this);
78
80
  }
79
81
 
@@ -241,13 +243,16 @@ export default class DataUnit {
241
243
  *
242
244
  */
243
245
  public async loadData(quickFilter?: QuickFilter, executionCtx?: ExecutionContext, checkLastFilter?: boolean): Promise<LoadDataResponse> {
246
+
247
+ await this.processLoadingLockers();
248
+
244
249
  if (this._parentDataUnit && !this._parentDataUnit.getSelectedRecord()) {
245
- if(this.records){
246
- this.clearDataUnit();
247
- }
248
- return Promise.resolve({
249
- records: []
250
- });
250
+ if(this.records){
251
+ this.clearDataUnit();
252
+ }
253
+ return Promise.resolve({
254
+ records: []
255
+ });
251
256
  }
252
257
 
253
258
  const loadDataRequest = this.getLoadDataRequest(quickFilter);
@@ -1577,6 +1582,28 @@ export default class DataUnit {
1577
1582
 
1578
1583
  return selection?.recordIds || [];
1579
1584
  }
1585
+
1586
+ /**
1587
+ * Adiciona um locker para impedir o carregamento dos registros do dataUnit.
1588
+ * @returns Retorna uma função responsável por liberar o lock adicionado.
1589
+ */
1590
+ public addLoadingLocker(): Function {
1591
+ let loadingLockerResolver;
1592
+
1593
+ this._loadingLockers.push(new Promise((resolve) => {
1594
+ loadingLockerResolver = resolve;
1595
+ }));
1596
+
1597
+ return loadingLockerResolver || Promise.resolve;
1598
+ }
1599
+
1600
+ private async processLoadingLockers(){
1601
+ if(this._loadingLockers.length) {
1602
+ await Promise.all(this._loadingLockers);
1603
+ this._loadingLockers = [];
1604
+ }
1605
+ }
1606
+
1580
1607
  }
1581
1608
 
1582
1609
  export interface DUActionInterceptor {
@@ -1676,6 +1703,7 @@ export class Change {
1676
1703
  public isUpdate(): boolean {
1677
1704
  return this._operation === ChangeOperation.UPDATE;
1678
1705
  }
1706
+
1679
1707
 
1680
1708
  }
1681
1709
 
@@ -23,10 +23,11 @@ export default class DateUtils{
23
23
  * Converte data para uma string no formato pt-BR.
24
24
  *
25
25
  * @param date - Data a ser convertida.
26
+ * @param options - Opções de formatação da data.
26
27
  * @returns - Uma string com a data no formato pt-BR DD/MM/YYYY.
27
28
  */
28
- public static formatDate(date: Date): string{
29
- return date ? new Intl.DateTimeFormat("pt-BR").format(date) : "";
29
+ public static formatDate(date: Date, options?: Intl.DateTimeFormatOptions): string{
30
+ return date ? new Intl.DateTimeFormat("pt-BR", options ?? {}).format(date) : "";
30
31
  }
31
32
 
32
33
  /**