@sankhyalabs/core 5.10.0-dev.7 → 5.10.0-dev.8
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 +118 -118
- package/.docs/classes/SelectionInfo.md +11 -11
- package/.docs/enums/ChangeOperation.md +4 -4
- package/.docs/enums/SelectionMode.md +2 -2
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/QuickFilter.md +3 -3
- package/.docs/interfaces/Record.md +4 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/dist/dataunit/DataUnit.js +4 -4
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/state/slice/ChangesSlice.js +4 -4
- package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.d.ts +0 -1
- package/dist/dataunit/state/slice/RecordsSlice.js +2 -6
- package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SnapshotSlice.d.ts +0 -1
- package/dist/dataunit/state/slice/SnapshotSlice.js +3 -24
- package/dist/dataunit/state/slice/SnapshotSlice.js.map +1 -1
- package/package.json +1 -1
- package/src/dataunit/DataUnit.ts +4 -10
- package/src/dataunit/state/slice/ChangesSlice.ts +4 -4
- package/src/dataunit/state/slice/RecordsSlice.ts +3 -8
- package/src/dataunit/state/slice/SnapshotSlice.ts +3 -29
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapshotSlice.js","sourceRoot":"","sources":["../../../../src/dataunit/state/slice/SnapshotSlice.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,E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CAAC,GAAG,CAAC,EAAE;QAC9C,IAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAC;YACxB,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;SAChC;IACL,CAAC,CAAC,CAAC;IAEF,OAAO;QACJ,OAAO,EAAE,eAAe;QACxB,gBAAgB;KACnB,CAAA;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/dataunit/DataUnit.ts
CHANGED
|
@@ -13,13 +13,7 @@ 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 {
|
|
17
|
-
SnapshotReducer,
|
|
18
|
-
getCurrentRecords,
|
|
19
|
-
getFieldValue,
|
|
20
|
-
getModifiedRecords,
|
|
21
|
-
getSelectionRecords,
|
|
22
|
-
} from './state/slice/SnapshotSlice.js';
|
|
16
|
+
import { SnapshotReducer, getCurrentRecords, getFieldValue, getModifiedRecords } from "./state/slice/SnapshotSlice.js";
|
|
23
17
|
import { getCurrentPage, getLastPage, getPaginationInfo, getCurrentRequest, LoadingControlReducer, hasMorePages, hasPreviousPages } from "./state/slice/LoadingControlSlice.js";
|
|
24
18
|
import { getRecords, RecordsReducer } from "./state/slice/RecordsSlice.js";
|
|
25
19
|
import { RemovedRecordsReducer } from "./state/slice/RemovedRecordsSlice.js";
|
|
@@ -1097,9 +1091,9 @@ export default class DataUnit {
|
|
|
1097
1091
|
*
|
|
1098
1092
|
*/
|
|
1099
1093
|
public getSelectedRecord(): Record | undefined {
|
|
1100
|
-
const selection =
|
|
1101
|
-
if (!selection
|
|
1102
|
-
return selection
|
|
1094
|
+
const selection: Array<string> = getSelection(this._stateManager);
|
|
1095
|
+
if (!selection) return;
|
|
1096
|
+
return this.records.find(record => (selection as Array<string>).includes(record.__record__id__));
|
|
1103
1097
|
}
|
|
1104
1098
|
|
|
1105
1099
|
/**
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { ActionReducer, StateAction } from "../StateManager.js";
|
|
3
3
|
import { Action } from "../action/DataUnitAction.js";
|
|
4
4
|
import StateManager from "../StateManager.js";
|
|
5
|
+
import { getSelection } from "./SelectionSlice.js";
|
|
5
6
|
import { getRecords } from "./RecordsSlice.js";
|
|
6
7
|
import { getRemovedRecords } from "./RemovedRecordsSlice.js";
|
|
7
8
|
import { getAddedRecords } from "./AddedRecordsSlice.js";
|
|
8
9
|
import { Change, ChangeOperation, Record } from "../../DataUnit.js";
|
|
9
10
|
import { getWaitingChanges } from "./WaitingChangesSlice.js";
|
|
10
|
-
import { getSelectionRecords } from './SnapshotSlice.js';
|
|
11
11
|
|
|
12
12
|
class ChangesReducerImpl implements ActionReducer{
|
|
13
13
|
|
|
@@ -32,8 +32,8 @@ class ChangesReducerImpl implements ActionReducer{
|
|
|
32
32
|
}
|
|
33
33
|
);
|
|
34
34
|
return changes;
|
|
35
|
-
case Action.DATA_CHANGED:
|
|
36
|
-
const selection: Array<string> = action.payload.records ||
|
|
35
|
+
case Action.DATA_CHANGED:
|
|
36
|
+
const selection: Array<string> = action.payload.records || getSelection(stateManager);
|
|
37
37
|
if(selection){
|
|
38
38
|
const newState = new Map(currentState);
|
|
39
39
|
selection.forEach(recordId => {
|
|
@@ -85,7 +85,7 @@ export const getChangesToSave = (dataUnit: string, stateManager: StateManager):
|
|
|
85
85
|
const result: Array<Change> = [];
|
|
86
86
|
|
|
87
87
|
const changes = getChanges(stateManager);
|
|
88
|
-
const records =
|
|
88
|
+
const records = getRecords(stateManager);
|
|
89
89
|
|
|
90
90
|
records?.forEach(r => {
|
|
91
91
|
if(changes){
|
|
@@ -40,18 +40,18 @@ class RecordsReducerImpl implements ActionReducer {
|
|
|
40
40
|
savedRecords.forEach(sr => {
|
|
41
41
|
const recordId = sr.__old__id__ || sr.__record__id__;
|
|
42
42
|
const newRecord: Record = { ...sr };
|
|
43
|
+
delete newRecord["__old__id__"];
|
|
43
44
|
if(recordsMap.has(recordId)){
|
|
44
45
|
recordsMap.set(recordId, newRecord);
|
|
45
|
-
} else
|
|
46
|
+
} else {
|
|
46
47
|
newRecords.push(newRecord);
|
|
47
48
|
}
|
|
48
|
-
delete newRecord["__old__id__"];
|
|
49
49
|
});
|
|
50
50
|
return newRecords.concat(Array.from(recordsMap.values()));
|
|
51
51
|
|
|
52
52
|
case Action.RECORD_LOADED:
|
|
53
53
|
action.payload.forEach((record: any) => {
|
|
54
|
-
for(let i = 0; i < currentState.length; i++){
|
|
54
|
+
for(let i = 0; i < currentState.length; i++){
|
|
55
55
|
if(currentState[i].__record__id__ === record.__record__id__){
|
|
56
56
|
currentState[i] = record;
|
|
57
57
|
}
|
|
@@ -60,11 +60,6 @@ class RecordsReducerImpl implements ActionReducer {
|
|
|
60
60
|
}
|
|
61
61
|
return currentState;
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
private isNewRecord(record: Record){
|
|
65
|
-
return (!Object.prototype.hasOwnProperty.call(record,"__old__id__")
|
|
66
|
-
|| record["__old__id__"] !== record["__record__id__"]);
|
|
67
|
-
}
|
|
68
63
|
}
|
|
69
64
|
|
|
70
65
|
export const RecordsReducer = new RecordsReducerImpl();
|
|
@@ -28,11 +28,6 @@ export const getCurrentRecords = (stateManager: StateManager): Map<string, Recor
|
|
|
28
28
|
return snapshot ? snapshot.records : new Map();
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export const getSelectionRecordsMap = (stateManager: StateManager): Map<string, Record> => {
|
|
32
|
-
const snapshot = getSnapshot(stateManager);
|
|
33
|
-
return snapshot ? snapshot.selectionRecords : new Map();
|
|
34
|
-
};
|
|
35
|
-
|
|
36
31
|
export const getSelectionRecords = (stateManager: StateManager): Array<Record> | undefined => {
|
|
37
32
|
const snapshot = getSnapshot(stateManager);
|
|
38
33
|
return snapshot ? Array.from(snapshot.selectionRecords.values()) : undefined;
|
|
@@ -40,7 +35,7 @@ export const getSelectionRecords = (stateManager: StateManager): Array<Record> |
|
|
|
40
35
|
|
|
41
36
|
export const getModifiedRecords = (stateManager: StateManager): Array<Record> | undefined => {
|
|
42
37
|
|
|
43
|
-
const currentRecords =
|
|
38
|
+
const currentRecords = getCurrentRecords(stateManager);
|
|
44
39
|
if(!currentRecords){
|
|
45
40
|
return undefined
|
|
46
41
|
}
|
|
@@ -63,9 +58,9 @@ export const getModifiedRecords = (stateManager: StateManager): Array<Record> |
|
|
|
63
58
|
export const getFieldValue = (stateManager: StateManager, fieldName: string): any => {
|
|
64
59
|
const selection = getSelection(stateManager);
|
|
65
60
|
if(selection && selection.length > 0){
|
|
66
|
-
const currentRecords =
|
|
61
|
+
const currentRecords = getCurrentRecords(stateManager);
|
|
67
62
|
if(currentRecords){
|
|
68
|
-
const record = currentRecords.
|
|
63
|
+
const record = currentRecords.get(selection[0]);
|
|
69
64
|
return record ? record[fieldName] : undefined;
|
|
70
65
|
}
|
|
71
66
|
}
|
|
@@ -94,11 +89,6 @@ function buildSnapshot(oldSnapshot: Snapshot, stateManager: StateManager): Snaps
|
|
|
94
89
|
const changes = getChanges(stateManager);
|
|
95
90
|
const snapshotRecords: Map<string, Record> = new Map(records.map(source => [source.__record__id__, {...source, ...changes?.get(source.__record__id__)}]));
|
|
96
91
|
const selectionRecords: Map<string, Record> = new Map(oldSnapshot?.selectionRecords);
|
|
97
|
-
|
|
98
|
-
for (let [chave, valor] of selectionRecords) {
|
|
99
|
-
selectionRecords.set(chave, {...valor, ...changes?.get(chave)});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
92
|
const selection: Array<string> = getSelection(stateManager);
|
|
103
93
|
|
|
104
94
|
if(selection && selection.length > 0){
|
|
@@ -120,20 +110,4 @@ function buildSnapshot(oldSnapshot: Snapshot, stateManager: StateManager): Snaps
|
|
|
120
110
|
records: snapshotRecords,
|
|
121
111
|
selectionRecords
|
|
122
112
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function buildCurrentRecords(stateManager: StateManager) {
|
|
126
|
-
const currentRecords = getCurrentRecords(stateManager);
|
|
127
|
-
const selectionRecords = getSelectionRecordsMap(stateManager);
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Precisamos verificar tanto os registros da seleção quanto os da página atual, pois o usuário pode estar tentando
|
|
131
|
-
* editar um registro que não está na página atual ou que não está selecionado.
|
|
132
|
-
*/
|
|
133
|
-
selectionRecords.forEach(record => {
|
|
134
|
-
if (!currentRecords.has(record.__record__id__)) {
|
|
135
|
-
currentRecords.set(record.__record__id__, record);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
return currentRecords;
|
|
139
113
|
}
|