@sankhyalabs/core 4.3.2 → 4.4.1
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/.docs/classes/Change.md +11 -11
- package/.docs/classes/DataUnit.md +197 -132
- package/.docs/classes/SelectionInfo.md +168 -0
- package/.docs/enums/Action.md +3 -14
- package/.docs/enums/ChangeOperation.md +4 -4
- package/.docs/enums/SelectionMode.md +30 -0
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/LoadDataRequest.md +13 -0
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/QuickFilter.md +13 -2
- package/.docs/interfaces/Record.md +4 -6
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/modules.md +2 -1
- package/README.md +3 -1
- package/dist/dataunit/DataUnit.d.ts +78 -44
- package/dist/dataunit/DataUnit.js +195 -101
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/loading/LoadDataRequest.d.ts +2 -0
- package/dist/dataunit/state/action/DataUnitAction.d.ts +0 -1
- package/dist/dataunit/state/action/DataUnitAction.js +0 -1
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/dataunit/state/slice/ChangesSlice.js +1 -2
- package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
- package/dist/dataunit/state/slice/LoadingControlSlice.d.ts +2 -2
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.d.ts +7 -4
- package/dist/dataunit/state/slice/SelectionSlice.js +40 -32
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SnapshotSlice.d.ts +18 -0
- package/dist/dataunit/state/slice/SnapshotSlice.js +85 -0
- package/dist/dataunit/state/slice/SnapshotSlice.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/dataunit/DataUnit.ts +226 -109
- package/src/dataunit/loading/LoadDataRequest.ts +3 -0
- package/src/dataunit/state/action/DataUnitAction.ts +0 -2
- package/src/dataunit/state/slice/ChangesSlice.ts +1 -1
- package/src/dataunit/state/slice/LoadingControlSlice.ts +2 -2
- package/src/dataunit/state/slice/SelectionSlice.ts +61 -45
- package/src/dataunit/state/slice/SnapshotSlice.ts +113 -0
- package/src/index.ts +4 -3
- package/.docs/interfaces/AllRecord.md +0 -96
- package/dist/dataunit/state/slice/CurrentRecordsSlice.d.ts +0 -12
- package/dist/dataunit/state/slice/CurrentRecordsSlice.js +0 -62
- package/dist/dataunit/state/slice/CurrentRecordsSlice.js.map +0 -1
- package/src/dataunit/state/slice/CurrentRecordsSlice.ts +0 -76
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,QAAQ,EAAE,EAAsB,MAAM,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,QAAQ,EAAE,EAAsB,MAAM,EAAE,eAAe,EAAgE,aAAa,EAAE,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAC1L,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAiC,aAAa,EAAQ,QAAQ,EAA2B,cAAc,EAA8B,MAAM,qCAAqC,CAAC;AACxL,OAAO,EAAE,cAAc,EAAE,MAAM,EAAoB,MAAM,2CAA2C,CAAC;AACrG,OAAO,kBAAkB,MAAM,+BAA+B,CAAC;AAC/D,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,gBAAgB,MAAM,kCAAkC,CAAC;AAChE,OAAO,sBAAsB,MAAM,wCAAwC,CAAC;AAC5E,OAAO,cAAc,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI1D,OAAO,EAAE,cAAc,EAAkB,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,8BAA8B;AAC9B,OAAO,EACH,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,SAAS,EACT,UAAU,EACV,aAAa,EACb,eAAe,EACf,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,QAAQ,EACR,eAAe,EAGf,QAAQ,EAGR,aAAa,EACb,cAAc,EAGd,cAAc,EACd,MAAM,EACN,MAAM,EAGN,eAAe,EAEf,kBAAkB,EAIlB,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,aAAa,EAIb,QAAQ,EAGR,aAAa,EACb,aAAa,EACb,cAAc,EAEd,cAAc,EACd,OAAO,EACV,CAAC"}
|
package/package.json
CHANGED
package/src/dataunit/DataUnit.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
68
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
break;
|
|
130
|
+
case Action.NEXT_SELECTED:
|
|
131
|
+
case Action.PREVIOUS_SELECTED:
|
|
133
132
|
case Action.DATA_LOADED:
|
|
134
|
-
|
|
135
|
-
|
|
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
|
|
256
|
-
quickFilter,
|
|
257
|
-
filters: 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 =
|
|
450
|
+
const selection = this.getSelectionInfo();
|
|
445
451
|
if (selection) {
|
|
446
|
-
|
|
447
|
-
|
|
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(
|
|
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
|
|
744
|
-
if (
|
|
745
|
-
|
|
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
|
-
*
|
|
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
|
|
887
|
-
|
|
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
|
|
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
|
-
* @
|
|
911
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
898
912
|
*
|
|
899
913
|
*/
|
|
900
|
-
public
|
|
901
|
-
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
915
|
-
|
|
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
|
-
*
|
|
934
|
+
* Seleciona múltiplos registros por ID ou todos os registros (multipágina) .
|
|
924
935
|
*
|
|
925
|
-
* @param
|
|
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
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
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
|
-
*
|
|
950
|
+
* Limpa a seleção.
|
|
940
951
|
*
|
|
941
|
-
* @param executionCtx - Contexto de execução da seleção
|
|
952
|
+
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
942
953
|
*
|
|
943
954
|
*/
|
|
944
|
-
public
|
|
945
|
-
|
|
946
|
-
this.setSelectionByIndex([0], executionCtx);
|
|
947
|
-
}
|
|
955
|
+
public clearSelection(executionCtx?: ExecutionContext){
|
|
956
|
+
this.setSelection([], executionCtx);
|
|
948
957
|
}
|
|
949
958
|
|
|
950
959
|
/**
|
|
951
960
|
*
|
|
952
|
-
*
|
|
961
|
+
* Atualiza a seleção dos registros atuais.
|
|
953
962
|
*
|
|
954
|
-
* @param
|
|
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
|
|
958
|
-
|
|
959
|
-
|
|
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
|
-
|
|
967
|
-
|
|
968
|
-
|
|
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
|
|
996
|
+
* Obtém informações sobre a seleção atual.
|
|
981
997
|
*
|
|
982
|
-
* @returns -
|
|
998
|
+
* @returns - Objeto com informações como registros selecionados e seleção por critério.
|
|
983
999
|
*
|
|
984
|
-
|
|
985
|
-
public
|
|
986
|
-
|
|
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<
|
|
1013
|
+
const selection: Array<string> = getSelection(this._stateManager);
|
|
1004
1014
|
if (!selection) return;
|
|
1005
|
-
return this.records.find(record => (selection as Array<
|
|
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.
|
|
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
|
|
1408
|
+
this.recordLoader(this, selection).then(response => {
|
|
1400
1409
|
this.dispatchAction(Action.RECORD_LOADED, response)
|
|
1401
1410
|
}).catch(cause => {
|
|
1402
1411
|
const {errorCode} = cause;
|
|
@@ -1423,7 +1432,7 @@ export default class DataUnit {
|
|
|
1423
1432
|
* @returns - Lista de filtros.
|
|
1424
1433
|
*
|
|
1425
1434
|
*/
|
|
1426
|
-
public getFilters(): Array<Filter> | undefined {
|
|
1435
|
+
public getFilters(): Array<Filter> | undefined {
|
|
1427
1436
|
let filters: Array<Filter> | undefined = undefined;
|
|
1428
1437
|
this._filterProviders.forEach(p => {
|
|
1429
1438
|
const f = p.getFilter(this.name);
|
|
@@ -1433,6 +1442,18 @@ export default class DataUnit {
|
|
|
1433
1442
|
});
|
|
1434
1443
|
return filters;
|
|
1435
1444
|
}
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
*
|
|
1448
|
+
* Obtém os filtros aplicados.
|
|
1449
|
+
*
|
|
1450
|
+
* @returns - Lista de filtros.
|
|
1451
|
+
*
|
|
1452
|
+
*/
|
|
1453
|
+
public getAppliedFilters(): Array<Filter> | undefined {
|
|
1454
|
+
const { filters }: LoadDataRequest = getCurrentRequest(this._stateManager) || {};
|
|
1455
|
+
return filters
|
|
1456
|
+
}
|
|
1436
1457
|
|
|
1437
1458
|
/**
|
|
1438
1459
|
*
|
|
@@ -1493,6 +1514,52 @@ export default class DataUnit {
|
|
|
1493
1514
|
this.metadata = {...this.metadata};
|
|
1494
1515
|
}
|
|
1495
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
|
+
}
|
|
1496
1563
|
}
|
|
1497
1564
|
|
|
1498
1565
|
export interface DUActionInterceptor {
|
|
@@ -1511,11 +1578,6 @@ export interface SavedRecord extends Record {
|
|
|
1511
1578
|
__old__id__?: string;
|
|
1512
1579
|
}
|
|
1513
1580
|
|
|
1514
|
-
export interface AllRecord extends Record {
|
|
1515
|
-
filter: Array<Filter>;
|
|
1516
|
-
sort: Array<Sort>;
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
1581
|
export enum ChangeOperation {
|
|
1520
1582
|
INSERT = "INSERT",
|
|
1521
1583
|
COPY = "COPY",
|
|
@@ -1615,6 +1677,7 @@ export interface PageRequest {
|
|
|
1615
1677
|
export interface QuickFilter {
|
|
1616
1678
|
term: string;
|
|
1617
1679
|
fields?: Array<string>;
|
|
1680
|
+
filter?: Filter;
|
|
1618
1681
|
}
|
|
1619
1682
|
|
|
1620
1683
|
export interface PageResponse {
|
|
@@ -1624,3 +1687,57 @@ export interface PageResponse {
|
|
|
1624
1687
|
hasMore: boolean;
|
|
1625
1688
|
records: Array<Record>;
|
|
1626
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
|
+
}
|
|
@@ -32,7 +32,7 @@ class ChangesReducerImpl implements ActionReducer{
|
|
|
32
32
|
);
|
|
33
33
|
return changes;
|
|
34
34
|
case Action.DATA_CHANGED:
|
|
35
|
-
const selection: Array<string> = action.payload.records || getSelection(stateManager)
|
|
35
|
+
const selection: Array<string> = action.payload.records || getSelection(stateManager);
|
|
36
36
|
if(selection){
|
|
37
37
|
const newState = new Map(currentState);
|
|
38
38
|
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|
|
|
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|
|
|
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
|
};
|