@sankhyalabs/core 4.4.0 → 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 +179 -133
- 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 +3 -3
- 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 +69 -44
- package/dist/dataunit/DataUnit.js +184 -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 +212 -108
- 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
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ActionReducer, StateAction } from "../StateManager.js";
|
|
2
2
|
import { Action } from "../action/DataUnitAction.js";
|
|
3
3
|
import StateManager from "../StateManager.js";
|
|
4
|
-
import { getCurrentRecords } from "./
|
|
5
|
-
import { Record, SavedRecord } from "../../DataUnit.js";
|
|
4
|
+
import { getCurrentRecords, getSelectionRecords } from "./SnapshotSlice.js";
|
|
5
|
+
import { Record, SavedRecord, SelectionInfo, SelectionMode } from "../../DataUnit.js";
|
|
6
|
+
import { getCurrentRequest, getPaginationInfo } from "./LoadingControlSlice.js";
|
|
7
|
+
import { PaginationInfo } from "../../loading/PaginationInfo.js";
|
|
6
8
|
|
|
7
9
|
class SelectionReducerImpl implements ActionReducer {
|
|
8
10
|
|
|
@@ -11,10 +13,11 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
11
13
|
public reduce(stateManager: StateManager, currentState: SelectionState, action: StateAction): SelectionState|undefined {
|
|
12
14
|
|
|
13
15
|
switch (action.type) {
|
|
14
|
-
|
|
16
|
+
case Action.DATA_LOADED:
|
|
17
|
+
return !action.payload?.keepSelection ? undefined : currentState;
|
|
15
18
|
case Action.RECORDS_ADDED:
|
|
16
19
|
case Action.RECORDS_COPIED:
|
|
17
|
-
return {currentSelection: action.payload, lastSelection: currentState?.currentSelection};
|
|
20
|
+
return {currentSelection: action.payload.map((r: Record)=>r.__record__id__), lastSelection: currentState?.currentSelection};
|
|
18
21
|
case Action.DATA_SAVED:
|
|
19
22
|
return {currentSelection: updateSavedIds(stateManager, action.payload.records)};
|
|
20
23
|
case Action.RECORDS_REMOVED:
|
|
@@ -22,7 +25,7 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
22
25
|
|
|
23
26
|
if (currentState && removed) {
|
|
24
27
|
const currentSelection = currentState.currentSelection;
|
|
25
|
-
const record = currentSelection.filter(
|
|
28
|
+
const record = currentSelection.filter(recordId => !removed.includes(recordId));
|
|
26
29
|
|
|
27
30
|
if(record.length === 0) {
|
|
28
31
|
const currentRecords = getCurrentRecords(stateManager);
|
|
@@ -35,9 +38,9 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
35
38
|
removedIndex++
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
currentRecords.forEach((value) => {
|
|
41
|
+
currentRecords.forEach((value, key) => {
|
|
39
42
|
if(currentIndex === removedIndex) {
|
|
40
|
-
record.push(
|
|
43
|
+
record.push(key);
|
|
41
44
|
}
|
|
42
45
|
currentIndex++;
|
|
43
46
|
})
|
|
@@ -57,10 +60,10 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
57
60
|
if (!currentState || currentSelection.length === 0) {
|
|
58
61
|
index = action.type === Action.PREVIOUS_SELECTED ? 0 : Math.min(1, currentRecords.size);
|
|
59
62
|
} else {
|
|
60
|
-
index = getItemIndex(currentSelection[0]
|
|
63
|
+
index = getItemIndex(currentSelection[0], currentRecords) + (action.type === Action.PREVIOUS_SELECTED ? -1 : 1);
|
|
61
64
|
}
|
|
62
65
|
if (index < currentRecords.size && index >= 0) {
|
|
63
|
-
return { currentSelection: [Array.from(currentRecords.values())[index]] };
|
|
66
|
+
return { currentSelection: [Array.from(currentRecords.values())[index].__record__id__] };
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -69,42 +72,30 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
69
72
|
case Action.SELECTION_CHANGED:
|
|
70
73
|
const { type, selection: selectionSource } = action.payload;
|
|
71
74
|
|
|
75
|
+
if(selectionSource === SelectionMode.ALL_RECORDS){
|
|
76
|
+
return {currentSelection: [], mode: SelectionMode.ALL_RECORDS};
|
|
77
|
+
}
|
|
78
|
+
|
|
72
79
|
if (selectionSource && type === "index") {
|
|
73
80
|
const currentRecords = getCurrentRecords(stateManager);
|
|
74
81
|
if (currentRecords) {
|
|
75
82
|
const records = Array.from(currentRecords.values());
|
|
76
|
-
const
|
|
83
|
+
const selectionById: Array<string> = [];
|
|
77
84
|
selectionSource.forEach((i: number) => {
|
|
78
85
|
if (i >= 0 && i < currentRecords.size) {
|
|
79
|
-
|
|
86
|
+
selectionById.push(records[i].__record__id__);
|
|
80
87
|
}
|
|
81
88
|
});
|
|
82
|
-
return {currentSelection:
|
|
89
|
+
return {currentSelection: selectionById};
|
|
83
90
|
}
|
|
84
91
|
}
|
|
85
92
|
|
|
86
|
-
return {currentSelection: selectionSource};
|
|
87
|
-
|
|
88
|
-
case Action.SELECTION_REMOVED:
|
|
89
|
-
if (currentState != undefined) {
|
|
90
|
-
const { unselection } = action.payload;
|
|
91
|
-
const currentSelection = currentState.currentSelection;
|
|
92
|
-
const selectionFiltered = currentSelection?.filter((selectedRecord: Record) => {
|
|
93
|
-
return !((unselection || []) as Array<Record>)
|
|
94
|
-
.some((unselectedRecord: Record) => {
|
|
95
|
-
return unselectedRecord.__record__id__ === selectedRecord.__record__id__;
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
return {currentSelection: selectionFiltered};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return undefined;
|
|
103
|
-
|
|
93
|
+
return {currentSelection: selectionSource };
|
|
104
94
|
case Action.EDITION_CANCELED:
|
|
105
95
|
if(currentState?.lastSelection){
|
|
106
96
|
return { currentSelection: currentState.lastSelection };
|
|
107
97
|
}
|
|
98
|
+
break;
|
|
108
99
|
}
|
|
109
100
|
|
|
110
101
|
return currentState;
|
|
@@ -113,8 +104,12 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
113
104
|
|
|
114
105
|
export const SelectionReducer = new SelectionReducerImpl();
|
|
115
106
|
|
|
116
|
-
export const
|
|
117
|
-
|
|
107
|
+
export const getSelectionState = (stateManager: StateManager): SelectionState => {
|
|
108
|
+
return stateManager.select(SelectionReducer.sliceName, (state: SelectionState) => state);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const getSelection = (stateManager: StateManager): Array<string> => {
|
|
112
|
+
let selection: Array<string> | undefined = getCurrentSelection(stateManager);
|
|
118
113
|
|
|
119
114
|
if (!selection || selection.length === 0) {
|
|
120
115
|
return [];
|
|
@@ -123,6 +118,24 @@ export const getSelection = (stateManager: StateManager): Array<Record> => {
|
|
|
123
118
|
return selection;
|
|
124
119
|
};
|
|
125
120
|
|
|
121
|
+
export const getSelectionInfo = (stateManager: StateManager): SelectionInfo => {
|
|
122
|
+
|
|
123
|
+
const selection = getSelectionState(stateManager);
|
|
124
|
+
if(selection && selection.mode === SelectionMode.ALL_RECORDS){
|
|
125
|
+
const currentRequest = getCurrentRequest(stateManager);
|
|
126
|
+
const paginationInfo: PaginationInfo | undefined = getPaginationInfo(stateManager);
|
|
127
|
+
return new SelectionInfo(
|
|
128
|
+
[],
|
|
129
|
+
SelectionMode.ALL_RECORDS,
|
|
130
|
+
paginationInfo?.total || 0,
|
|
131
|
+
currentRequest?.filters,
|
|
132
|
+
currentRequest?.sort
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return new SelectionInfo(getSelectionRecords(stateManager) || [], SelectionMode.SOME_RECORDS, undefined);
|
|
137
|
+
}
|
|
138
|
+
|
|
126
139
|
export const hasNext = (stateManager: StateManager): boolean => {
|
|
127
140
|
const records = getCurrentRecords(stateManager);
|
|
128
141
|
if (records) {
|
|
@@ -130,7 +143,7 @@ export const hasNext = (stateManager: StateManager): boolean => {
|
|
|
130
143
|
if (!selection || selection.length === 0) {
|
|
131
144
|
return records.size > 0;
|
|
132
145
|
}
|
|
133
|
-
return records.size > (getItemIndex(selection[0]
|
|
146
|
+
return records.size > (getItemIndex(selection[0], records) + 1);
|
|
134
147
|
}
|
|
135
148
|
return false;
|
|
136
149
|
};
|
|
@@ -142,7 +155,7 @@ export const hasPrevious = (stateManager: StateManager): boolean => {
|
|
|
142
155
|
if (!selection || selection.length === 0) {
|
|
143
156
|
return false;
|
|
144
157
|
}
|
|
145
|
-
return getItemIndex(selection[0]
|
|
158
|
+
return getItemIndex(selection[0], records) > 0;
|
|
146
159
|
}
|
|
147
160
|
return false;
|
|
148
161
|
};
|
|
@@ -151,16 +164,16 @@ function getItemIndex(key: string, map: Map<string, any>): number {
|
|
|
151
164
|
return Array.from(map.keys()).indexOf(key);
|
|
152
165
|
}
|
|
153
166
|
|
|
154
|
-
function updateSavedIds(stateManager:StateManager, savedRecords:Array<SavedRecord>): Array<
|
|
155
|
-
const currentSelection: Array<
|
|
167
|
+
function updateSavedIds(stateManager:StateManager, savedRecords:Array<SavedRecord>): Array<string>{
|
|
168
|
+
const currentSelection: Array<string> = getSelection(stateManager);
|
|
156
169
|
if(currentSelection){
|
|
157
|
-
const newSelection: Array<
|
|
158
|
-
currentSelection.forEach(
|
|
159
|
-
const record = savedRecords.find(r => r.__old__id__ ===
|
|
170
|
+
const newSelection: Array<string> = [];
|
|
171
|
+
currentSelection.forEach( id => {
|
|
172
|
+
const record = savedRecords.find(r => r.__old__id__ === id);
|
|
160
173
|
if(record){
|
|
161
|
-
newSelection.push(record);
|
|
174
|
+
newSelection.push(record.__record__id__);
|
|
162
175
|
} else {
|
|
163
|
-
newSelection.push(
|
|
176
|
+
newSelection.push(id);
|
|
164
177
|
}
|
|
165
178
|
});
|
|
166
179
|
return newSelection;
|
|
@@ -168,10 +181,13 @@ function updateSavedIds(stateManager:StateManager, savedRecords:Array<SavedRecor
|
|
|
168
181
|
return currentSelection;
|
|
169
182
|
}
|
|
170
183
|
|
|
171
|
-
function getCurrentSelection(stateManager: StateManager):Array<
|
|
172
|
-
|
|
184
|
+
function getCurrentSelection(stateManager: StateManager):Array<string> | undefined{
|
|
185
|
+
const selectionState = getSelectionState(stateManager);
|
|
186
|
+
return selectionState ? selectionState.currentSelection : undefined;
|
|
173
187
|
}
|
|
188
|
+
|
|
174
189
|
interface SelectionState{
|
|
175
|
-
currentSelection: Array<
|
|
176
|
-
|
|
190
|
+
currentSelection: Array<string>;
|
|
191
|
+
mode?: SelectionMode;
|
|
192
|
+
lastSelection?: Array<string>;
|
|
177
193
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
|
|
2
|
+
import { ActionReducer } from "../StateManager.js";
|
|
3
|
+
import StateManager from "../StateManager.js";
|
|
4
|
+
import { Record } from "../../DataUnit.js";
|
|
5
|
+
import { getRecords } from "./RecordsSlice.js";
|
|
6
|
+
import { getSelection } from "./SelectionSlice.js";
|
|
7
|
+
import { getChanges } from "./ChangesSlice.js";
|
|
8
|
+
import { getRemovedRecords } from "./RemovedRecordsSlice.js";
|
|
9
|
+
import { getAddedRecords } from "./AddedRecordsSlice.js";
|
|
10
|
+
|
|
11
|
+
class SnapshotReducerImpl implements ActionReducer{
|
|
12
|
+
|
|
13
|
+
public sliceName: string = "snapshot";
|
|
14
|
+
|
|
15
|
+
public reduce(stateManager: StateManager, currentSnapshot: Snapshot): Snapshot {
|
|
16
|
+
return buildSnapshot(currentSnapshot, stateManager);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const SnapshotReducer = new SnapshotReducerImpl();
|
|
21
|
+
|
|
22
|
+
export const getSnapshot = (stateManager: StateManager): Snapshot | undefined => {
|
|
23
|
+
return stateManager.select(SnapshotReducer.sliceName, (state: Snapshot) => state);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const getCurrentRecords = (stateManager: StateManager): Map<string, Record> => {
|
|
27
|
+
const snapshot = getSnapshot(stateManager);
|
|
28
|
+
return snapshot ? snapshot.records : new Map();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const getSelectionRecords = (stateManager: StateManager): Array<Record> | undefined => {
|
|
32
|
+
const snapshot = getSnapshot(stateManager);
|
|
33
|
+
return snapshot ? Array.from(snapshot.selectionRecords.values()) : undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const getModifiedRecords = (stateManager: StateManager): Array<Record> | undefined => {
|
|
37
|
+
|
|
38
|
+
const currentRecords = getCurrentRecords(stateManager);
|
|
39
|
+
if(!currentRecords){
|
|
40
|
+
return undefined
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const changes = getChanges(stateManager);
|
|
44
|
+
const added = getAddedRecords(stateManager);
|
|
45
|
+
if(!changes && !added){
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let modifiedIDs = changes ? Array.from(changes.keys()) : [];
|
|
50
|
+
|
|
51
|
+
if(added){
|
|
52
|
+
modifiedIDs = modifiedIDs.concat(added.map(r=>r.__record__id__));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return Array.from(currentRecords.values()).filter(r=>modifiedIDs.includes(r.__record__id__));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const getFieldValue = (stateManager: StateManager, fieldName: string): any => {
|
|
59
|
+
const selection = getSelection(stateManager);
|
|
60
|
+
if(selection && selection.length > 0){
|
|
61
|
+
const currentRecords = getCurrentRecords(stateManager);
|
|
62
|
+
if(currentRecords){
|
|
63
|
+
const record = currentRecords.get(selection[0]);
|
|
64
|
+
return record ? record[fieldName] : undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export interface Snapshot{
|
|
71
|
+
records: Map<string, Record>;
|
|
72
|
+
selectionRecords: Map<string, Record>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function buildSnapshot(oldSnapshot: Snapshot, stateManager: StateManager): Snapshot{
|
|
76
|
+
|
|
77
|
+
let records = getRecords(stateManager) || [];
|
|
78
|
+
const added = getAddedRecords(stateManager);
|
|
79
|
+
|
|
80
|
+
if(added){
|
|
81
|
+
records = (records).concat(added);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const removedRecords = getRemovedRecords(stateManager);
|
|
85
|
+
if(removedRecords){
|
|
86
|
+
records = records.filter(record => !removedRecords.includes(record.__record__id__));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const changes = getChanges(stateManager);
|
|
90
|
+
const snapshotRecords: Map<string, Record> = new Map(records.map(source => [source.__record__id__, {...source, ...changes?.get(source.__record__id__)}]));
|
|
91
|
+
const selectionRecords: Map<string, Record> = new Map(oldSnapshot?.selectionRecords);
|
|
92
|
+
const selection: Array<string> = getSelection(stateManager);
|
|
93
|
+
|
|
94
|
+
if(selection && selection.length > 0){
|
|
95
|
+
selection.forEach(recordId => {
|
|
96
|
+
const record = snapshotRecords.has(recordId) ? snapshotRecords.get(recordId) : oldSnapshot?.records.get(recordId);
|
|
97
|
+
if(record){
|
|
98
|
+
selectionRecords.set(recordId, record);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
Array.from(selectionRecords.keys()).forEach(key => {
|
|
104
|
+
if(!selection.includes(key)){
|
|
105
|
+
selectionRecords.delete(key);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
records: snapshotRecords,
|
|
111
|
+
selectionRecords
|
|
112
|
+
}
|
|
113
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { HttpProvider } from "./http/HttpProvider.js";
|
|
|
9
9
|
import { SkwHttpProvider } from "./http/SkwHttpProvider.js";
|
|
10
10
|
import { RequestMetadata } from "./http/RequestMetadata.js";
|
|
11
11
|
import { AuthorizedServiceCaller } from "./http/AuthorizedServiceCaller.js";
|
|
12
|
-
import DataUnit, {SavedRecord, Record, Change, ChangeOperation, DUActionInterceptor, WaitingChange, PageRequest, QuickFilter,
|
|
12
|
+
import DataUnit, {SavedRecord, Record, Change, ChangeOperation, DUActionInterceptor, WaitingChange, PageRequest, QuickFilter, SelectionMode, SelectionInfo} from "./dataunit/DataUnit.js";
|
|
13
13
|
import { DataType } from "./dataunit/metadata/DataType.js";
|
|
14
14
|
import { UnitMetadata, FieldDescriptor, UserInterface, Sort, SortMode, SortingProvider, Filter, DependencyType, ChildDescriptor, ChildLink } from "./dataunit/metadata/UnitMetadata.js";
|
|
15
15
|
import { DataUnitAction, Action, ExecutionContext } from "./dataunit/state/action/DataUnitAction.js";
|
|
@@ -76,9 +76,10 @@ export {
|
|
|
76
76
|
SortMode,
|
|
77
77
|
LoadDataRequest,
|
|
78
78
|
LoadDataResponse,
|
|
79
|
+
SelectionInfo,
|
|
80
|
+
SelectionMode,
|
|
79
81
|
ElementIDUtils,
|
|
80
82
|
IElementIDInfo,
|
|
81
83
|
UserAgentUtils,
|
|
82
|
-
JSUtils
|
|
83
|
-
AllRecord
|
|
84
|
+
JSUtils
|
|
84
85
|
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
[@sankhyalabs/core](../README.md) / [Exports](../modules.md) / AllRecord
|
|
2
|
-
|
|
3
|
-
# Interface: AllRecord
|
|
4
|
-
|
|
5
|
-
## Hierarchy
|
|
6
|
-
|
|
7
|
-
- [`Record`](Record.md)
|
|
8
|
-
|
|
9
|
-
↳ **`AllRecord`**
|
|
10
|
-
|
|
11
|
-
## Table of contents
|
|
12
|
-
|
|
13
|
-
### Properties
|
|
14
|
-
|
|
15
|
-
- [\_\_owner\_\_dataunit\_\_name\_\_](AllRecord.md#__owner__dataunit__name__)
|
|
16
|
-
- [\_\_parent\_\_record\_\_id\_\_](AllRecord.md#__parent__record__id__)
|
|
17
|
-
- [\_\_record\_\_id\_\_](AllRecord.md#__record__id__)
|
|
18
|
-
- [\_\_record\_\_label\_\_](AllRecord.md#__record__label__)
|
|
19
|
-
- [filter](AllRecord.md#filter)
|
|
20
|
-
- [sort](AllRecord.md#sort)
|
|
21
|
-
|
|
22
|
-
## Properties
|
|
23
|
-
|
|
24
|
-
### \_\_owner\_\_dataunit\_\_name\_\_
|
|
25
|
-
|
|
26
|
-
• `Optional` **\_\_owner\_\_dataunit\_\_name\_\_**: `string`
|
|
27
|
-
|
|
28
|
-
#### Inherited from
|
|
29
|
-
|
|
30
|
-
[Record](Record.md).[__owner__dataunit__name__](Record.md#__owner__dataunit__name__)
|
|
31
|
-
|
|
32
|
-
#### Defined in
|
|
33
|
-
|
|
34
|
-
src/dataunit/DataUnit.ts:1518
|
|
35
|
-
|
|
36
|
-
___
|
|
37
|
-
|
|
38
|
-
### \_\_parent\_\_record\_\_id\_\_
|
|
39
|
-
|
|
40
|
-
• `Optional` **\_\_parent\_\_record\_\_id\_\_**: `string`
|
|
41
|
-
|
|
42
|
-
#### Inherited from
|
|
43
|
-
|
|
44
|
-
[Record](Record.md).[__parent__record__id__](Record.md#__parent__record__id__)
|
|
45
|
-
|
|
46
|
-
#### Defined in
|
|
47
|
-
|
|
48
|
-
src/dataunit/DataUnit.ts:1517
|
|
49
|
-
|
|
50
|
-
___
|
|
51
|
-
|
|
52
|
-
### \_\_record\_\_id\_\_
|
|
53
|
-
|
|
54
|
-
• **\_\_record\_\_id\_\_**: `string`
|
|
55
|
-
|
|
56
|
-
#### Inherited from
|
|
57
|
-
|
|
58
|
-
[Record](Record.md).[__record__id__](Record.md#__record__id__)
|
|
59
|
-
|
|
60
|
-
#### Defined in
|
|
61
|
-
|
|
62
|
-
src/dataunit/DataUnit.ts:1515
|
|
63
|
-
|
|
64
|
-
___
|
|
65
|
-
|
|
66
|
-
### \_\_record\_\_label\_\_
|
|
67
|
-
|
|
68
|
-
• `Optional` **\_\_record\_\_label\_\_**: `string`
|
|
69
|
-
|
|
70
|
-
#### Inherited from
|
|
71
|
-
|
|
72
|
-
[Record](Record.md).[__record__label__](Record.md#__record__label__)
|
|
73
|
-
|
|
74
|
-
#### Defined in
|
|
75
|
-
|
|
76
|
-
src/dataunit/DataUnit.ts:1516
|
|
77
|
-
|
|
78
|
-
___
|
|
79
|
-
|
|
80
|
-
### filter
|
|
81
|
-
|
|
82
|
-
• **filter**: [`Filter`](Filter.md)[]
|
|
83
|
-
|
|
84
|
-
#### Defined in
|
|
85
|
-
|
|
86
|
-
src/dataunit/DataUnit.ts:1527
|
|
87
|
-
|
|
88
|
-
___
|
|
89
|
-
|
|
90
|
-
### sort
|
|
91
|
-
|
|
92
|
-
• **sort**: [`Sort`](Sort.md)[]
|
|
93
|
-
|
|
94
|
-
#### Defined in
|
|
95
|
-
|
|
96
|
-
src/dataunit/DataUnit.ts:1528
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ActionReducer } from "../StateManager.js";
|
|
2
|
-
import StateManager from "../StateManager.js";
|
|
3
|
-
import { Record } from "../../DataUnit.js";
|
|
4
|
-
declare class CurrentRecordsReducerImpl implements ActionReducer {
|
|
5
|
-
sliceName: string;
|
|
6
|
-
reduce(stateManager: StateManager): Map<string, Record> | undefined;
|
|
7
|
-
}
|
|
8
|
-
export declare const CurrentRecordsReducer: CurrentRecordsReducerImpl;
|
|
9
|
-
export declare const getCurrentRecords: (stateManager: StateManager) => Map<string, Record>;
|
|
10
|
-
export declare const getModifiedRecords: (stateManager: StateManager) => Array<Record> | undefined;
|
|
11
|
-
export declare const getFieldValue: (stateManager: StateManager, fieldName: string) => any;
|
|
12
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { getRecords } from "./RecordsSlice.js";
|
|
2
|
-
import { getSelection } from "./SelectionSlice.js";
|
|
3
|
-
import { getChanges } from "./ChangesSlice.js";
|
|
4
|
-
import { getRemovedRecords } from "./RemovedRecordsSlice.js";
|
|
5
|
-
import { getAddedRecords } from "./AddedRecordsSlice.js";
|
|
6
|
-
class CurrentRecordsReducerImpl {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.sliceName = "currentRecords";
|
|
9
|
-
}
|
|
10
|
-
reduce(stateManager) {
|
|
11
|
-
let records = getRecords(stateManager);
|
|
12
|
-
const added = getAddedRecords(stateManager);
|
|
13
|
-
if (!records && !added) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
if (added) {
|
|
17
|
-
records = (added || []).concat(records || []);
|
|
18
|
-
}
|
|
19
|
-
const removedRecords = getRemovedRecords(stateManager);
|
|
20
|
-
if (removedRecords) {
|
|
21
|
-
records = records.filter(r => !removedRecords.includes(r.__record__id__));
|
|
22
|
-
}
|
|
23
|
-
const changes = getChanges(stateManager);
|
|
24
|
-
return new Map(records.map(r => {
|
|
25
|
-
const recordId = r.__record__id__;
|
|
26
|
-
const record = Object.assign(Object.assign({}, r), changes === null || changes === void 0 ? void 0 : changes.get(recordId));
|
|
27
|
-
return [recordId, record];
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export const CurrentRecordsReducer = new CurrentRecordsReducerImpl();
|
|
32
|
-
export const getCurrentRecords = (stateManager) => {
|
|
33
|
-
return stateManager.select(CurrentRecordsReducer.sliceName, (state) => state);
|
|
34
|
-
};
|
|
35
|
-
export const getModifiedRecords = (stateManager) => {
|
|
36
|
-
const currentRecords = getCurrentRecords(stateManager);
|
|
37
|
-
if (!currentRecords) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
const changes = getChanges(stateManager);
|
|
41
|
-
const added = getAddedRecords(stateManager);
|
|
42
|
-
if (!changes && !added) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
let modifiedIDs = changes ? Array.from(changes.keys()) : [];
|
|
46
|
-
if (added) {
|
|
47
|
-
modifiedIDs = modifiedIDs.concat(added.map(r => r.__record__id__));
|
|
48
|
-
}
|
|
49
|
-
return Array.from(currentRecords.values()).filter(r => modifiedIDs.includes(r.__record__id__));
|
|
50
|
-
};
|
|
51
|
-
export const getFieldValue = (stateManager, fieldName) => {
|
|
52
|
-
const selection = getSelection(stateManager);
|
|
53
|
-
if (selection && selection.length > 0) {
|
|
54
|
-
const currentRecords = getCurrentRecords(stateManager);
|
|
55
|
-
if (currentRecords) {
|
|
56
|
-
const record = currentRecords.get(selection[0].__record__id__);
|
|
57
|
-
return record ? record[fieldName] : undefined;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return undefined;
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=CurrentRecordsSlice.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CurrentRecordsSlice.js","sourceRoot":"","sources":["../../../../src/dataunit/state/slice/CurrentRecordsSlice.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { ActionReducer } from "../StateManager.js";
|
|
3
|
-
import StateManager from "../StateManager.js";
|
|
4
|
-
import { Record } from "../../DataUnit.js";
|
|
5
|
-
import { getRecords } from "./RecordsSlice.js";
|
|
6
|
-
import { getSelection } from "./SelectionSlice.js";
|
|
7
|
-
import { getChanges } from "./ChangesSlice.js";
|
|
8
|
-
import { getRemovedRecords } from "./RemovedRecordsSlice.js";
|
|
9
|
-
import { getAddedRecords } from "./AddedRecordsSlice.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class CurrentRecordsReducerImpl implements ActionReducer{
|
|
13
|
-
|
|
14
|
-
public sliceName: string = "currentRecords";
|
|
15
|
-
|
|
16
|
-
public reduce(stateManager: StateManager): Map<string, Record> | undefined {
|
|
17
|
-
let records = getRecords(stateManager);
|
|
18
|
-
const added = getAddedRecords(stateManager);
|
|
19
|
-
if(!records && !added){
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
if(added){
|
|
23
|
-
records = (added||[]).concat(records||[]);
|
|
24
|
-
}
|
|
25
|
-
const removedRecords = getRemovedRecords(stateManager);
|
|
26
|
-
if(removedRecords){
|
|
27
|
-
records = records.filter(r => !removedRecords.includes(r.__record__id__));
|
|
28
|
-
}
|
|
29
|
-
const changes = getChanges(stateManager);
|
|
30
|
-
return new Map(records.map(r => {
|
|
31
|
-
const recordId = r.__record__id__;
|
|
32
|
-
const record = {...r, ...changes?.get(recordId)};
|
|
33
|
-
return [recordId, record];
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const CurrentRecordsReducer = new CurrentRecordsReducerImpl();
|
|
39
|
-
|
|
40
|
-
export const getCurrentRecords = (stateManager: StateManager): Map<string, Record> => {
|
|
41
|
-
return stateManager.select(CurrentRecordsReducer.sliceName, (state: Map<string, Record>) => state);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const getModifiedRecords = (stateManager: StateManager): Array<Record> | undefined => {
|
|
45
|
-
|
|
46
|
-
const currentRecords = getCurrentRecords(stateManager);
|
|
47
|
-
if(!currentRecords){
|
|
48
|
-
return undefined
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const changes = getChanges(stateManager);
|
|
52
|
-
const added = getAddedRecords(stateManager);
|
|
53
|
-
if(!changes && !added){
|
|
54
|
-
return undefined
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let modifiedIDs = changes ? Array.from(changes.keys()) : [];
|
|
58
|
-
|
|
59
|
-
if(added){
|
|
60
|
-
modifiedIDs = modifiedIDs.concat(added.map(r=>r.__record__id__));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return Array.from(currentRecords.values()).filter(r=>modifiedIDs.includes(r.__record__id__));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const getFieldValue = (stateManager: StateManager, fieldName: string): any => {
|
|
67
|
-
const selection = getSelection(stateManager);
|
|
68
|
-
if(selection && selection.length > 0){
|
|
69
|
-
const currentRecords = getCurrentRecords(stateManager);
|
|
70
|
-
if(currentRecords){
|
|
71
|
-
const record = currentRecords.get(selection[0].__record__id__);
|
|
72
|
-
return record ? record[fieldName] : undefined;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return undefined;
|
|
76
|
-
};
|