@sankhyalabs/core 7.2.3-rc.1 → 7.2.4-dev.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.
@@ -1057,7 +1057,8 @@ export default class DataUnit {
1057
1057
  *
1058
1058
  */
1059
1059
  public async setFieldValue(fieldName: string, newValue: any, records?: Array<string>, options?: DataUnitEventOptions): Promise<boolean> {
1060
- const noRecordSelected = !this.hasNewRecord() && !this.getSelectedRecord();
1060
+ const callerSpecifiedRecords = records != undefined && records.length > 0;
1061
+ const noRecordSelected = !callerSpecifiedRecords && !this.hasNewRecord() && !this.getSelectedRecord();
1061
1062
 
1062
1063
  const suppressCreateNewRecord = options?.suppressCreateNewRecord;
1063
1064
 
@@ -2,14 +2,15 @@
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
+ import { getSelection, getSelectionInfo } from "./SelectionSlice.js";
6
6
  import { getRecords } from "./RecordsSlice.js";
7
7
  import { getRemovedRecords } from "./RemovedRecordsSlice.js";
8
8
  import { getAddedRecords, isAddedRecord } from "./AddedRecordsSlice.js";
9
- import { ChangeOperation, Record } from "../../interfaces/dataUnit.js";
9
+ import { ChangeOperation, Record, SelectionMode } from "../../interfaces/dataUnit.js";
10
10
  import { Change } from "../../Changes.js";
11
11
  import { getWaitingChanges } from "./WaitingChangesSlice.js";
12
12
  import { getSelectionRecords } from "./SnapshotSlice.js";
13
+ import { DataUnitStorage } from "../../DataUnitStorage.js";
13
14
 
14
15
  class ChangesReducerImpl implements ActionReducer{
15
16
 
@@ -95,7 +96,7 @@ export const getChangedFieldValue = (fieldName: string, record: Record, stateMan
95
96
  }
96
97
 
97
98
  export const getChangesToSave = (dataUnit: string, stateManager: StateManager): Array<Change> => {
98
-
99
+
99
100
  const changes = getChanges(stateManager);
100
101
  const selectedRecords = getSelectionRecords(stateManager) || [];
101
102
  const records: Map<string, Record> = new Map(
@@ -105,9 +106,22 @@ export const getChangesToSave = (dataUnit: string, stateManager: StateManager):
105
106
  )
106
107
  .map(r => [r.__record__id__, r])
107
108
  );
108
-
109
+
110
+ if(changes != undefined && changes.size > 0){
111
+ const selectionInfo = getSelectionInfo(stateManager);
112
+ if(selectionInfo?.mode === SelectionMode.ALL_RECORDS){
113
+ const dataUnitInstance = DataUnitStorage.get(dataUnit);
114
+ const allLoaded = dataUnitInstance?.allRecordsLoader?.(dataUnitInstance) ?? [];
115
+ allLoaded.forEach(r => {
116
+ if(!records.has(r.__record__id__) && !isAddedRecord(r.__record__id__, stateManager)){
117
+ records.set(r.__record__id__, r);
118
+ }
119
+ });
120
+ }
121
+ }
122
+
109
123
  const result: Array<Change> = [];
110
-
124
+
111
125
  if(changes != undefined){
112
126
  Array.from(changes.entries())
113
127
  .forEach(([recordId, change]) =>{
@@ -92,7 +92,15 @@ function buildSnapshot(oldSnapshot: Snapshot, stateManager: StateManager): Snaps
92
92
 
93
93
  if(selection && selection.length > 0){
94
94
  selection.forEach(recordId => {
95
- const record = snapshotRecords.has(recordId) ? snapshotRecords.get(recordId) : oldSnapshot?.records.get(recordId);
95
+ let record: Record | undefined;
96
+ if(snapshotRecords.has(recordId)){
97
+ record = snapshotRecords.get(recordId);
98
+ } else {
99
+ const base = oldSnapshot?.selectionRecords.get(recordId) ?? oldSnapshot?.records.get(recordId);
100
+ if(base){
101
+ record = {...base, ...changes?.get(recordId)};
102
+ }
103
+ }
96
104
  if(record){
97
105
  selectionRecords.set(recordId, record);
98
106
  }