@sankhyalabs/core 4.0.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/classes/Change.md +11 -11
- package/.docs/classes/DataUnit.md +125 -70
- package/.docs/enums/Action.md +12 -1
- package/.docs/enums/ChangeOperation.md +4 -4
- package/.docs/interfaces/AllRecord.md +96 -0
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/QuickFilter.md +2 -2
- package/.docs/interfaces/Record.md +6 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/modules.md +1 -0
- package/dist/dataunit/DataUnit.d.ts +37 -10
- package/dist/dataunit/DataUnit.js +61 -31
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/state/action/DataUnitAction.d.ts +1 -0
- package/dist/dataunit/state/action/DataUnitAction.js +1 -0
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/dataunit/state/slice/ChangesSlice.js +2 -2
- package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
- package/dist/dataunit/state/slice/CurrentRecordsSlice.js +3 -3
- package/dist/dataunit/state/slice/CurrentRecordsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.d.ts +4 -3
- package/dist/dataunit/state/slice/SelectionSlice.js +31 -25
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/JSUtils.js +2 -2
- package/dist/utils/JSUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/dataunit/DataUnit.ts +72 -35
- package/src/dataunit/state/action/DataUnitAction.ts +2 -1
- package/src/dataunit/state/slice/ChangesSlice.ts +2 -2
- package/src/dataunit/state/slice/CurrentRecordsSlice.ts +3 -3
- package/src/dataunit/state/slice/SelectionSlice.ts +40 -33
- package/src/index.ts +3 -2
- package/src/utils/JSUtils.ts +4 -4
|
@@ -22,7 +22,7 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
22
22
|
|
|
23
23
|
if (currentState && removed) {
|
|
24
24
|
const currentSelection = currentState.currentSelection;
|
|
25
|
-
const record = currentSelection.filter(
|
|
25
|
+
const record = currentSelection.filter((selectedRecord: Record) => !removed.includes(selectedRecord.__record__id__));
|
|
26
26
|
|
|
27
27
|
if(record.length === 0) {
|
|
28
28
|
const currentRecords = getCurrentRecords(stateManager);
|
|
@@ -35,9 +35,9 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
35
35
|
removedIndex++
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
currentRecords.forEach((value
|
|
38
|
+
currentRecords.forEach((value) => {
|
|
39
39
|
if(currentIndex === removedIndex) {
|
|
40
|
-
record.push(
|
|
40
|
+
record.push(value);
|
|
41
41
|
}
|
|
42
42
|
currentIndex++;
|
|
43
43
|
})
|
|
@@ -57,10 +57,10 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
57
57
|
if (!currentState || currentSelection.length === 0) {
|
|
58
58
|
index = action.type === Action.PREVIOUS_SELECTED ? 0 : Math.min(1, currentRecords.size);
|
|
59
59
|
} else {
|
|
60
|
-
index = getItemIndex(currentSelection[0], currentRecords) + (action.type === Action.PREVIOUS_SELECTED ? -1 : 1);
|
|
60
|
+
index = getItemIndex(currentSelection[0].__record__id__, currentRecords) + (action.type === Action.PREVIOUS_SELECTED ? -1 : 1);
|
|
61
61
|
}
|
|
62
62
|
if (index < currentRecords.size && index >= 0) {
|
|
63
|
-
return { currentSelection: [Array.from(currentRecords.values())[index]
|
|
63
|
+
return { currentSelection: [Array.from(currentRecords.values())[index]] };
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -73,17 +73,34 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
73
73
|
const currentRecords = getCurrentRecords(stateManager);
|
|
74
74
|
if (currentRecords) {
|
|
75
75
|
const records = Array.from(currentRecords.values());
|
|
76
|
-
const
|
|
76
|
+
const selectionRecord: Array<Record> = [];
|
|
77
77
|
selectionSource.forEach((i: number) => {
|
|
78
78
|
if (i >= 0 && i < currentRecords.size) {
|
|
79
|
-
|
|
79
|
+
selectionRecord.push(records[i]);
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
|
-
return {currentSelection:
|
|
82
|
+
return {currentSelection: selectionRecord};
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
return {currentSelection:
|
|
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
|
+
|
|
87
104
|
case Action.EDITION_CANCELED:
|
|
88
105
|
if(currentState?.lastSelection){
|
|
89
106
|
return { currentSelection: currentState.lastSelection };
|
|
@@ -96,8 +113,8 @@ class SelectionReducerImpl implements ActionReducer {
|
|
|
96
113
|
|
|
97
114
|
export const SelectionReducer = new SelectionReducerImpl();
|
|
98
115
|
|
|
99
|
-
export const
|
|
100
|
-
|
|
116
|
+
export const getAllSelection = (stateManager: StateManager): Array<Record> => {
|
|
117
|
+
const selection: Array<Record> = getCurrentSelection(stateManager);
|
|
101
118
|
|
|
102
119
|
if (!selection || selection.length === 0) {
|
|
103
120
|
return [];
|
|
@@ -113,7 +130,7 @@ export const hasNext = (stateManager: StateManager): boolean => {
|
|
|
113
130
|
if (!selection || selection.length === 0) {
|
|
114
131
|
return records.size > 0;
|
|
115
132
|
}
|
|
116
|
-
return records.size > (getItemIndex(selection[0], records) + 1);
|
|
133
|
+
return records.size > (getItemIndex(selection[0].__record__id__, records) + 1);
|
|
117
134
|
}
|
|
118
135
|
return false;
|
|
119
136
|
};
|
|
@@ -125,35 +142,25 @@ export const hasPrevious = (stateManager: StateManager): boolean => {
|
|
|
125
142
|
if (!selection || selection.length === 0) {
|
|
126
143
|
return false;
|
|
127
144
|
}
|
|
128
|
-
return getItemIndex(selection[0], records) > 0;
|
|
145
|
+
return getItemIndex(selection[0].__record__id__, records) > 0;
|
|
129
146
|
}
|
|
130
147
|
return false;
|
|
131
148
|
};
|
|
132
149
|
|
|
133
|
-
function getFilteredSelection(selection: Array<string>, stateManager: StateManager): Array<string>{
|
|
134
|
-
|
|
135
|
-
if(selection){
|
|
136
|
-
const records = getCurrentRecords(stateManager);
|
|
137
|
-
return selection.filter(id => records.has(id));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return selection;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
150
|
function getItemIndex(key: string, map: Map<string, any>): number {
|
|
144
151
|
return Array.from(map.keys()).indexOf(key);
|
|
145
152
|
}
|
|
146
153
|
|
|
147
|
-
function updateSavedIds(stateManager:StateManager, savedRecords:Array<SavedRecord>): Array<
|
|
148
|
-
const currentSelection: Array<
|
|
154
|
+
function updateSavedIds(stateManager:StateManager, savedRecords:Array<SavedRecord>): Array<Record>{
|
|
155
|
+
const currentSelection: Array<Record> = getAllSelection(stateManager);
|
|
149
156
|
if(currentSelection){
|
|
150
|
-
const newSelection: Array<
|
|
151
|
-
currentSelection.forEach(
|
|
152
|
-
const record = savedRecords.find(r => r.__old__id__ ===
|
|
157
|
+
const newSelection: Array<Record> = [];
|
|
158
|
+
currentSelection.forEach(recordSelection => {
|
|
159
|
+
const record = savedRecords.find(r => r.__old__id__ === recordSelection.__record__id__);
|
|
153
160
|
if(record){
|
|
154
|
-
newSelection.push(record
|
|
161
|
+
newSelection.push(record);
|
|
155
162
|
} else {
|
|
156
|
-
newSelection.push(
|
|
163
|
+
newSelection.push(recordSelection);
|
|
157
164
|
}
|
|
158
165
|
});
|
|
159
166
|
return newSelection;
|
|
@@ -161,10 +168,10 @@ function updateSavedIds(stateManager:StateManager, savedRecords:Array<SavedRecor
|
|
|
161
168
|
return currentSelection;
|
|
162
169
|
}
|
|
163
170
|
|
|
164
|
-
function getCurrentSelection(stateManager: StateManager):Array<
|
|
171
|
+
function getCurrentSelection(stateManager: StateManager):Array<Record>{
|
|
165
172
|
return stateManager.select(SelectionReducer.sliceName, (state: SelectionState) => state)?.currentSelection;
|
|
166
173
|
}
|
|
167
174
|
interface SelectionState{
|
|
168
|
-
currentSelection: Array<
|
|
169
|
-
lastSelection?: Array<
|
|
175
|
+
currentSelection: Array<Record>;
|
|
176
|
+
lastSelection?: Array<Record>;
|
|
170
177
|
}
|
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} from "./dataunit/DataUnit.js";
|
|
12
|
+
import DataUnit, {SavedRecord, Record, Change, ChangeOperation, DUActionInterceptor, WaitingChange, PageRequest, QuickFilter, AllRecord} 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";
|
|
@@ -79,5 +79,6 @@ export {
|
|
|
79
79
|
ElementIDUtils,
|
|
80
80
|
IElementIDInfo,
|
|
81
81
|
UserAgentUtils,
|
|
82
|
-
JSUtils
|
|
82
|
+
JSUtils,
|
|
83
|
+
AllRecord
|
|
83
84
|
};
|
package/src/utils/JSUtils.ts
CHANGED
|
@@ -46,11 +46,11 @@ export class JSUtils{
|
|
|
46
46
|
*
|
|
47
47
|
* @returns - Retorna um valor booleando informando se a string está encodada com base64.
|
|
48
48
|
*/
|
|
49
|
-
public static isBase64(str:string): boolean {
|
|
50
|
-
str = str.replaceAll("\n", "");
|
|
51
|
-
if (str ==='' || str.trim() ===''){ return false; }
|
|
49
|
+
public static isBase64(str: string): boolean {
|
|
50
|
+
str = (str || '').replaceAll("\n", "");
|
|
51
|
+
if (str === '' || str.trim() === ''){ return false; }
|
|
52
52
|
try {
|
|
53
|
-
return btoa(atob(str)) == str;
|
|
53
|
+
return window.btoa(window.atob(str)) == str;
|
|
54
54
|
} catch (err) {
|
|
55
55
|
return false;
|
|
56
56
|
}
|