@sankhyalabs/core 4.4.0 → 4.4.2

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.
Files changed (52) hide show
  1. package/.docs/classes/Change.md +11 -11
  2. package/.docs/classes/DataUnit.md +179 -133
  3. package/.docs/classes/SelectionInfo.md +168 -0
  4. package/.docs/enums/Action.md +3 -14
  5. package/.docs/enums/ChangeOperation.md +4 -4
  6. package/.docs/enums/SelectionMode.md +30 -0
  7. package/.docs/interfaces/DUActionInterceptor.md +1 -1
  8. package/.docs/interfaces/LoadDataRequest.md +13 -0
  9. package/.docs/interfaces/PageRequest.md +3 -3
  10. package/.docs/interfaces/QuickFilter.md +3 -3
  11. package/.docs/interfaces/Record.md +4 -6
  12. package/.docs/interfaces/SavedRecord.md +5 -5
  13. package/.docs/interfaces/WaitingChange.md +3 -3
  14. package/.docs/modules.md +2 -1
  15. package/README.md +3 -1
  16. package/dist/dataunit/DataUnit.d.ts +69 -44
  17. package/dist/dataunit/DataUnit.js +184 -101
  18. package/dist/dataunit/DataUnit.js.map +1 -1
  19. package/dist/dataunit/loading/LoadDataRequest.d.ts +2 -0
  20. package/dist/dataunit/metadata/DataType.js +3 -0
  21. package/dist/dataunit/metadata/DataType.js.map +1 -1
  22. package/dist/dataunit/state/action/DataUnitAction.d.ts +0 -1
  23. package/dist/dataunit/state/action/DataUnitAction.js +0 -1
  24. package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
  25. package/dist/dataunit/state/slice/ChangesSlice.js +2 -2
  26. package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
  27. package/dist/dataunit/state/slice/LoadingControlSlice.d.ts +2 -2
  28. package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
  29. package/dist/dataunit/state/slice/SelectionSlice.d.ts +7 -4
  30. package/dist/dataunit/state/slice/SelectionSlice.js +40 -32
  31. package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
  32. package/dist/dataunit/state/slice/SnapshotSlice.d.ts +18 -0
  33. package/dist/dataunit/state/slice/SnapshotSlice.js +85 -0
  34. package/dist/dataunit/state/slice/SnapshotSlice.js.map +1 -0
  35. package/dist/index.d.ts +2 -2
  36. package/dist/index.js +2 -2
  37. package/dist/index.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/dataunit/DataUnit.ts +212 -108
  40. package/src/dataunit/loading/LoadDataRequest.ts +3 -0
  41. package/src/dataunit/metadata/DataType.ts +3 -0
  42. package/src/dataunit/state/action/DataUnitAction.ts +0 -2
  43. package/src/dataunit/state/slice/ChangesSlice.ts +2 -1
  44. package/src/dataunit/state/slice/LoadingControlSlice.ts +2 -2
  45. package/src/dataunit/state/slice/SelectionSlice.ts +61 -45
  46. package/src/dataunit/state/slice/SnapshotSlice.ts +113 -0
  47. package/src/index.ts +4 -3
  48. package/.docs/interfaces/AllRecord.md +0 -96
  49. package/dist/dataunit/state/slice/CurrentRecordsSlice.d.ts +0 -12
  50. package/dist/dataunit/state/slice/CurrentRecordsSlice.js +0 -62
  51. package/dist/dataunit/state/slice/CurrentRecordsSlice.js.map +0 -1
  52. package/src/dataunit/state/slice/CurrentRecordsSlice.ts +0 -76
@@ -13,11 +13,11 @@ import { LoadDataResponse } from "./loading/LoadDataResponse.js";
13
13
  import { PaginationInfo } from "./loading/PaginationInfo.js";
14
14
  import { AddedRecordsReducer, getAddedRecords, prepareAddedRecordId, prepareCopiedRecord } from "./state/slice/AddedRecordsSlice.js";
15
15
  import { ChangesReducer, getChangesToSave, isDirty, hasDirtyRecords } from "./state/slice/ChangesSlice.js";
16
- import { CurrentRecordsReducer, getCurrentRecords, getFieldValue, getModifiedRecords } from "./state/slice/CurrentRecordsSlice.js";
16
+ import { SnapshotReducer, getCurrentRecords, getFieldValue, getModifiedRecords } from "./state/slice/SnapshotSlice.js";
17
17
  import { getCurrentPage, getLastPage, getPaginationInfo, getCurrentRequest, LoadingControlReducer, hasMorePages, hasPreviousPages } from "./state/slice/LoadingControlSlice.js";
18
18
  import { getRecords, RecordsReducer } from "./state/slice/RecordsSlice.js";
19
19
  import { RemovedRecordsReducer } from "./state/slice/RemovedRecordsSlice.js";
20
- import { getSelection, hasNext, hasPrevious, SelectionReducer } from "./state/slice/SelectionSlice.js";
20
+ import { getSelection, getSelectionInfo, hasNext, hasPrevious, SelectionReducer } from "./state/slice/SelectionSlice.js";
21
21
  import { getField, getMetadata, UnitMetadataReducer } from "./state/slice/UnitMetadataSlice.js";
22
22
  import { getBlockingWaitingChanges, getWaitingChangePromisses, isWaiting, WaitingChangesReducer } from "./state/slice/WaitingChangesSlice.js";
23
23
  import { canRedo, canUndo, HistReducer } from "./state/HistReducer.js";
@@ -64,8 +64,8 @@ export default class DataUnit {
64
64
  SelectionReducer,
65
65
  ChangesReducer,
66
66
  WaitingChangesReducer,
67
- CurrentRecordsReducer,
68
- InvalidFieldsReducer
67
+ InvalidFieldsReducer,
68
+ SnapshotReducer
69
69
  ]
70
70
  );
71
71
  this._observers = [];
@@ -127,14 +127,15 @@ export default class DataUnit {
127
127
  private onDataUnitParentEvent = (action: DataUnitAction) => {
128
128
  switch(action.type){
129
129
  case Action.SELECTION_CHANGED:
130
- if(this._parentDataUnit?.hasCopiedRecord() || this._parentDataUnit?.hasNewRecord()) return;
131
- this.loadData();
132
- break;
130
+ case Action.NEXT_SELECTED:
131
+ case Action.PREVIOUS_SELECTED:
133
132
  case Action.DATA_LOADED:
134
- if(this._parentDataUnit?.getSelectedRecord() == undefined){
135
- this.clearDataUnit();
133
+ this.clearDataUnit();
134
+ const selectedRecord = this._parentDataUnit?.getSelectedRecord();
135
+ if(selectedRecord != undefined && this.isNewRecord(selectedRecord.__record__id__)){
136
+ this.loadData();
136
137
  }
137
- break;
138
+ break;
138
139
  }
139
140
  }
140
141
 
@@ -183,7 +184,7 @@ export default class DataUnit {
183
184
  if (this.dataLoader) {
184
185
  this.dataLoader(this, request).then(
185
186
  response => {
186
- this.dispatchAction(Action.DATA_LOADED, response, executionCtx);
187
+ this.dispatchAction(Action.DATA_LOADED, {...response, keepSelection: request.keepSelection}, executionCtx);
187
188
  resolve(response);
188
189
  }
189
190
  ).catch(error => {
@@ -240,9 +241,6 @@ export default class DataUnit {
240
241
  *
241
242
  */
242
243
  public async loadData(quickFilter?: QuickFilter, executionCtx?: ExecutionContext, checkLastFilter?: boolean): Promise<LoadDataResponse> {
243
-
244
- await this.clearSelection(executionCtx);
245
-
246
244
  if (this._parentDataUnit && !this._parentDataUnit.getSelectedRecord()) {
247
245
  if(this.records){
248
246
  this.clearDataUnit();
@@ -252,18 +250,7 @@ export default class DataUnit {
252
250
  });
253
251
  }
254
252
 
255
- const loadDataRequest: LoadDataRequest = {
256
- quickFilter,
257
- filters: quickFilter?.filter ? [quickFilter.filter] : this.getFilters(),
258
- sort: this.getSort(),
259
- parentRecordId: this.getParentRecordId()
260
- };
261
-
262
- if (this._pageSize > 0) {
263
- loadDataRequest.limit = this._pageSize
264
- loadDataRequest.offset = 0;
265
- }
266
-
253
+ const loadDataRequest = this.getLoadDataRequest(quickFilter);
267
254
  return this.executeLoadData(loadDataRequest, executionCtx, checkLastFilter);
268
255
  }
269
256
 
@@ -292,7 +279,8 @@ export default class DataUnit {
292
279
  return this.executeLoadData({
293
280
  ...request,
294
281
  limit: this._pageSize,
295
- offset: page * this._pageSize
282
+ offset: page * this._pageSize,
283
+ keepSelection: true
296
284
  }, executionCtx);
297
285
  }
298
286
  }
@@ -323,6 +311,24 @@ export default class DataUnit {
323
311
  return this.gotoPage(getCurrentPage(this._stateManager) - 1, executionCtx);
324
312
  }
325
313
 
314
+ private getLoadDataRequest(quickFilter?: QuickFilter): LoadDataRequest {
315
+ const request: LoadDataRequest = {
316
+ filters: quickFilter?.filter ? [quickFilter.filter] : this.getFilters(),
317
+ sort: this.getSort(),
318
+ parentRecordId: this.getParentRecordId()
319
+ };
320
+
321
+ if (quickFilter) {
322
+ request.quickFilter = quickFilter;
323
+ }
324
+
325
+ if (this._pageSize > 0) {
326
+ request.limit = this._pageSize
327
+ request.offset = 0;
328
+ }
329
+
330
+ return request;
331
+ }
326
332
 
327
333
  private async notifySavingData(executionCtx?: ExecutionContext): Promise<boolean>{
328
334
  const notifyPromises: Array<Promise<boolean>> = [];
@@ -441,12 +447,16 @@ export default class DataUnit {
441
447
  *
442
448
  */
443
449
  public async removeSelectedRecords(buffered: boolean = false): Promise<Array<string>> {
444
- const selection = getSelection(this._stateManager);
450
+ const selection = this.getSelectionInfo();
445
451
  if (selection) {
446
- const records = this.getSelection() || [];
447
- return this.removeRecords(selection.map(sel => sel.__record__id__), records, buffered);
452
+ if(selection.isAllRecords()){
453
+ throw new Error("Exclusão remota não implementada.");
454
+ }
455
+ const records = selection?.records || [];
456
+ const recordIds = selection?.recordIds || [];
457
+ return this.removeRecords(recordIds, records, buffered);
448
458
  }
449
- return Promise.resolve(selection);
459
+ return Promise.resolve([]);
450
460
  }
451
461
 
452
462
  /**
@@ -740,9 +750,12 @@ export default class DataUnit {
740
750
  *
741
751
  */
742
752
  public copySelected(executionCtx?: ExecutionContext): void {
743
- const selectedRecords = this.getSelection();
744
- if (selectedRecords) {
745
- this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
753
+ const selectionInfo = this.getSelectionInfo();
754
+ if (selectionInfo) {
755
+ const selectedRecords = selectionInfo.records;
756
+ if(selectedRecords){
757
+ this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
758
+ }
746
759
  }
747
760
  }
748
761
 
@@ -879,117 +892,114 @@ export default class DataUnit {
879
892
  }
880
893
 
881
894
  /**
882
- * Obtém todos os registros selecionados.
883
895
  *
884
- * @returns - Lista de todos os registros selecionados.
896
+ * Seleciona o primeiro registro.
897
+ *
898
+ * @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
899
+ *
885
900
  */
886
- public getSelection(): Array<Record> {
887
- return getSelection(this._stateManager);
901
+ public selectFirst(executionCtx?: ExecutionContext): void {
902
+ if (this.records.length > 0) {
903
+ this.setSelectionByIndex([0], executionCtx);
904
+ }
888
905
  }
889
906
 
890
907
  /**
891
908
  *
892
- * Seleciona múltiplos registros.
893
- *
894
- * @param selection - Registros para selecionar.
895
- * @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
909
+ * Seleciona o último registro.
896
910
  *
897
- * @returns - Verdadeiro se ação executada.
911
+ * @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
898
912
  *
899
913
  */
900
- public setSelection(selection: Array<Record>, executionCtx?: ExecutionContext): Promise<boolean> {
901
- return this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }, executionCtx);
914
+ public selectLast(executionCtx?: ExecutionContext): void {
915
+ if (this.records.length > 0) {
916
+ this.setSelectionByIndex([this.records.length - 1], executionCtx);
917
+ }
902
918
  }
903
919
 
904
920
  /**
905
921
  *
906
- * Remove a seleção de múltiplos registros.
907
- *
908
- * @param unselection - Registros para remover a seleção.
909
- * @param executionCtx - Contexto de execução da remoção da seleção dos registros do DataUnit.
922
+ * Seleciona múltiplos registros por índice.
910
923
  *
911
- * @returns - Verdadeiro se ação executada.
924
+ * @param selection - Índices desejados para a seleção.
925
+ * @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
912
926
  *
913
927
  */
914
- public setUnselection(unselection: Array<Record>, executionCtx?: ExecutionContext): Promise<boolean> {
915
- if (this.getSelection()?.length > 0) {
916
- return this.dispatchAction(Action.SELECTION_REMOVED, { type: "id", unselection }, executionCtx);
917
- }
918
- return Promise.resolve(false);
928
+ public setSelectionByIndex(selection: Array<number>, executionCtx?: ExecutionContext): void {
929
+ this.dispatchAction(Action.SELECTION_CHANGED, { type: "index", selection }, executionCtx);
919
930
  }
920
931
 
921
932
  /**
922
933
  *
923
- * Remove a seleção de todos os registros.
934
+ * Seleciona múltiplos registros por ID ou todos os registros (multipágina) .
924
935
  *
925
- * @param executionCtx - Contexto de execução da remoção da seleção dos registros do DataUnit.
936
+ * @param selection - IDs para selecionar ou o modo de seleção completo.
937
+ * @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
926
938
  *
927
- * @returns - Verdadeiro se ação executada.
928
939
  *
929
940
  */
930
- public clearSelection(executionCtx?: ExecutionContext): Promise<boolean> {
931
- if (this.getSelection()?.length > 0) {
932
- return this.dispatchAction(Action.SELECTION_REMOVED, { type: "id", unselection: this.getSelection() }, executionCtx);
933
- }
934
- return Promise.resolve(false);
941
+ public setSelection(selection: Array<string> | SelectionMode.ALL_RECORDS, executionCtx?: ExecutionContext): Promise<SelectionInfo> {
942
+ return new Promise(resolve => {
943
+ this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }, executionCtx)
944
+ .then(()=>resolve(getSelectionInfo(this._stateManager)));
945
+ });
935
946
  }
936
947
 
937
948
  /**
938
949
  *
939
- * Seleciona o primeiro registro.
950
+ * Limpa a seleção.
940
951
  *
941
- * @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
952
+ * @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
942
953
  *
943
954
  */
944
- public selectFirst(executionCtx?: ExecutionContext): void {
945
- if (this.records.length > 0) {
946
- this.setSelectionByIndex([0], executionCtx);
947
- }
955
+ public clearSelection(executionCtx?: ExecutionContext){
956
+ this.setSelection([], executionCtx);
948
957
  }
949
958
 
950
959
  /**
951
960
  *
952
- * Seleciona o último registro.
961
+ * Atualiza a seleção dos registros atuais.
953
962
  *
954
- * @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
963
+ * @param selection - IDs dos registros selecionados no snapshot atual
964
+ * @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
955
965
  *
966
+ * @returns - Informações sobre a seleção.
956
967
  */
957
- public selectLast(executionCtx?: ExecutionContext): void {
958
- if (this.records.length > 0) {
959
- this.setSelectionByIndex([this.records.length - 1], executionCtx);
968
+ public updatePageSelection(selection: Array<string>, executionCtx?: ExecutionContext): Promise<SelectionInfo|undefined>{
969
+
970
+ if(!selection){
971
+ return Promise.resolve(this.getSelectionInfo());
960
972
  }
961
- }
962
973
 
974
+ return new Promise(resolve => {
975
+ const newSelection: Set<string> = new Set(getSelection(this._stateManager));
976
+ const currentRecords = getCurrentRecords(this._stateManager) || new Map();
977
+ Array.from(currentRecords.keys()).forEach(
978
+ recordId => {
979
+ if(selection.includes(recordId)){
980
+ newSelection.add(recordId);
981
+ } else {
982
+ newSelection.delete(recordId);
983
+ }
984
+ }
985
+ );
963
986
 
964
- /**
965
- *
966
- * Seleciona múltiplos registros por índice.
967
- *
968
- * @param selection - Índices desejados para a seleção.
969
- * @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
970
- *
971
- * @returns - Verdadeiro se ação executada.
972
- *
973
- */
974
- public setSelectionByIndex(selection: Array<number>, executionCtx?: ExecutionContext): Promise<boolean> {
975
- return this.dispatchAction(Action.SELECTION_CHANGED, { type: "index", selection }, executionCtx);
987
+ this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) }, executionCtx)
988
+ .then(()=>{
989
+ resolve(this.getSelectionInfo())
990
+ });
991
+ });
976
992
  }
977
993
 
978
994
  /**
979
995
  *
980
- * Obtém os registros selecionados da página atual.
996
+ * Obtém informações sobre a seleção atual.
981
997
  *
982
- * @returns - Lista de registros selecionados da página atual.
998
+ * @returns - Objeto com informações como registros selecionados e seleção por critério.
983
999
  *
984
- */
985
- public getSelectedRecords(): Array<Record> | undefined {
986
- const selection: Array<Record> = this.getSelection();
987
- if (selection) {
988
- const currentRecords: Array<Record> = this.records;
989
- return currentRecords?.filter((record: Record) => {
990
- return selection.some((sel: Record) => sel.__record__id__ === record.__record__id__);
991
- });
992
- }
1000
+ **/
1001
+ public getSelectionInfo(): SelectionInfo | undefined {
1002
+ return getSelectionInfo(this._stateManager)
993
1003
  }
994
1004
 
995
1005
  /**
@@ -1000,15 +1010,14 @@ export default class DataUnit {
1000
1010
  *
1001
1011
  */
1002
1012
  public getSelectedRecord(): Record | undefined {
1003
- const selection: Array<Record> = this.getSelection();
1013
+ const selection: Array<string> = getSelection(this._stateManager);
1004
1014
  if (!selection) return;
1005
- return this.records.find(record => (selection as Array<Record>).some(sel => sel.__record__id__ === record.__record__id__));
1015
+ return this.records.find(record => (selection as Array<string>).includes(record.__record__id__));
1006
1016
  }
1007
1017
 
1008
1018
  /**
1009
1019
  *
1010
1020
  * Limpa todos os registros do DataUnit
1011
- *
1012
1021
  *
1013
1022
  *
1014
1023
  */
@@ -1390,13 +1399,13 @@ export default class DataUnit {
1390
1399
  */
1391
1400
  public reloadCurrentRecord(): Promise<Array<Record>>{
1392
1401
  return new Promise(async (resolve, fail) => {
1393
- const selection = this.getSelection();
1402
+ const selection = getSelection(this._stateManager);
1394
1403
  this.dispatchAction(Action.LOADING_RECORD, selection);
1395
1404
 
1396
1405
  if(!this.dataLoader) return;
1397
1406
  if(!this.recordLoader) return;
1398
1407
 
1399
- this.recordLoader(this, selection?.map(sel => sel.__record__id__)).then(response => {
1408
+ this.recordLoader(this, selection).then(response => {
1400
1409
  this.dispatchAction(Action.RECORD_LOADED, response)
1401
1410
  }).catch(cause => {
1402
1411
  const {errorCode} = cause;
@@ -1505,6 +1514,52 @@ export default class DataUnit {
1505
1514
  this.metadata = {...this.metadata};
1506
1515
  }
1507
1516
  }
1517
+
1518
+ /**
1519
+ *
1520
+ * Obtém todos os registros selecionados.
1521
+ *
1522
+ * @returns - Lista de registros selecionados.
1523
+ *
1524
+ * @deprecated - Utilize o método `getSelectionInfo()` para obter os registros selecionados.
1525
+ * Devido a seleção virtual baseada em critérios e ordenação (ALL_RECORDS), esse
1526
+ * método foi descontinuado e pode retornar erros no caso da seleção virtual.
1527
+ *
1528
+ */
1529
+ public getSelectedRecords(): Array<Record> | undefined {
1530
+ console.warn("DataUnit: O método `getSelectedRecords` foi descontinuado. Use o método `getSelectionInfo`.");
1531
+ const selection = this.getSelectionInfo();
1532
+
1533
+ if(selection != undefined && selection.isAllRecords()){
1534
+ throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
1535
+ }
1536
+
1537
+ if (selection) {
1538
+ return selection.records;
1539
+ }
1540
+ }
1541
+
1542
+ /**
1543
+ *
1544
+ * Obtém ids dos registros selecionados.
1545
+ *
1546
+ * @returns - Lista com id de todos os registros selecionados.
1547
+ *
1548
+ * @deprecated - Utilize o método `getSelectionInfo()` para obter os registros selecionados.
1549
+ * Devido a seleção virtual baseada em critérios e ordenação (ALL_RECORDS), esse
1550
+ * método foi descontinuado e pode retornar erros no caso da seleção virtual.
1551
+ *
1552
+ */
1553
+ public getSelection(): Array<string> {
1554
+ console.warn("DataUnit: O método `getSelection` foi descontinuado. Use o método `getSelectionInfo`.");
1555
+ const selection = this.getSelectionInfo();
1556
+
1557
+ if(selection != undefined && selection.isAllRecords()){
1558
+ throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
1559
+ }
1560
+
1561
+ return selection?.recordIds || [];
1562
+ }
1508
1563
  }
1509
1564
 
1510
1565
  export interface DUActionInterceptor {
@@ -1523,11 +1578,6 @@ export interface SavedRecord extends Record {
1523
1578
  __old__id__?: string;
1524
1579
  }
1525
1580
 
1526
- export interface AllRecord extends Record {
1527
- filter: Array<Filter>;
1528
- sort: Array<Sort>;
1529
- }
1530
-
1531
1581
  export enum ChangeOperation {
1532
1582
  INSERT = "INSERT",
1533
1583
  COPY = "COPY",
@@ -1637,3 +1687,57 @@ export interface PageResponse {
1637
1687
  hasMore: boolean;
1638
1688
  records: Array<Record>;
1639
1689
  }
1690
+
1691
+ export enum SelectionMode{
1692
+ ALL_RECORDS = "ALL_RECORDS",
1693
+ SOME_RECORDS = "SOME_RECORDS"
1694
+ }
1695
+
1696
+ export class SelectionInfo{
1697
+
1698
+ private _records: Array<Record>;
1699
+ public mode: SelectionMode;
1700
+ private _total?: number;
1701
+ public filters?: Array<Filter>;
1702
+ public sort?: Array<Sort>;
1703
+
1704
+ constructor(records: Array<Record>, mode: SelectionMode = SelectionMode.SOME_RECORDS, total?:number, filters?: Array<Filter>, sort?: Array<Sort>){
1705
+ this._records = records;
1706
+ this._total = total;
1707
+ this.mode = mode;
1708
+ this.filters = filters;
1709
+ this.sort = sort;
1710
+ }
1711
+
1712
+ public get records(): Array<Record> | undefined{
1713
+ if(this.isAllRecords()){
1714
+ throw new Error("Erro interno: [ALL_RECORDS] - Impossível retornar os registros selecionados numa seleção virtual.")
1715
+ }
1716
+ return this._records;
1717
+ }
1718
+
1719
+ public get recordIds(): Array<string> | undefined{
1720
+
1721
+ const records = this.records;
1722
+
1723
+ if(records == undefined){
1724
+ return undefined;
1725
+ }
1726
+ return records.map(record => record.__record__id__);
1727
+ }
1728
+
1729
+ public get length(): number{
1730
+ if(this.isAllRecords()){
1731
+ return this._total || 0;
1732
+ }
1733
+ return this.records == undefined ? 0: this.records.length;
1734
+ }
1735
+
1736
+ public isAllRecords(): boolean{
1737
+ return this.mode === SelectionMode.ALL_RECORDS;
1738
+ }
1739
+
1740
+ public isEmpty(): boolean{
1741
+ return this.length === 0;
1742
+ }
1743
+ }
@@ -20,4 +20,7 @@ export interface LoadDataRequest {
20
20
 
21
21
  /** Info parent */
22
22
  parentRecordId?: string | undefined;
23
+
24
+ /** Na navegação de páginas devemos manter a seleção */
25
+ keepSelection?: boolean;
23
26
  }
@@ -100,6 +100,9 @@ export const toString = ( dataType: DataType|undefined, value: any): string => {
100
100
 
101
101
  if (dataType) {
102
102
  if (dataType === DataType.OBJECT) {
103
+ if (typeof value !== "object") {
104
+ value = {label: "", value }
105
+ }
103
106
  return JSON.stringify(value);
104
107
  } else if (dataType === DataType.DATE) {
105
108
  return DateUtils.formatRfc3339(value as Date);
@@ -58,8 +58,6 @@ export enum Action{
58
58
  LOADING_RECORD = "loadingRecord",
59
59
  RECORD_LOADED = "recordLoaded",
60
60
 
61
- SELECTION_REMOVED = "selectionRemoved",
62
-
63
61
  CHILD_CHANGED = "childChanged",
64
62
 
65
63
  FIELD_INVALIDATED = "fieldInvalidated",
@@ -27,12 +27,13 @@ class ChangesReducerImpl implements ActionReducer{
27
27
  delete rChanges.__record__source__id__;
28
28
  delete rChanges.__record__label__;
29
29
  delete rChanges.__copy__;
30
+ delete rChanges.__owner__dataunit__name__;
30
31
  changes.set(r.__record__id__, rChanges);
31
32
  }
32
33
  );
33
34
  return changes;
34
35
  case Action.DATA_CHANGED:
35
- const selection: Array<string> = action.payload.records || getSelection(stateManager)?.map(sel => sel.__record__id__);
36
+ const selection: Array<string> = action.payload.records || getSelection(stateManager);
36
37
  if(selection){
37
38
  const newState = new Map(currentState);
38
39
  selection.forEach(recordId => {
@@ -21,12 +21,12 @@ class LoadingControlReducerImpl implements ActionReducer {
21
21
 
22
22
  export const LoadingControlReducer = new LoadingControlReducerImpl();
23
23
 
24
- export const getPaginationInfo = (stateManager: StateManager): PaginationInfo|void => {
24
+ export const getPaginationInfo = (stateManager: StateManager): PaginationInfo|undefined => {
25
25
  const state: LoadingControlState = stateManager.select(LoadingControlReducer.sliceName, (state: LoadingControlState) => state);
26
26
  return state ? state.paginationInfo : undefined;
27
27
  };
28
28
 
29
- export const getCurrentRequest = (stateManager: StateManager): LoadDataRequest|void => {
29
+ export const getCurrentRequest = (stateManager: StateManager): LoadDataRequest|undefined => {
30
30
  const state: LoadingControlState = stateManager.select(LoadingControlReducer.sliceName, (state: LoadingControlState) => state);
31
31
  return state ? state.lastRequest : undefined;
32
32
  };