@sankhyalabs/core 5.20.0-dev.81 → 5.20.0-dev.83

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.
Files changed (35) hide show
  1. package/.docs/classes/Change.md +11 -11
  2. package/.docs/classes/DataUnit.md +230 -122
  3. package/.docs/classes/FieldComparator.md +6 -2
  4. package/.docs/classes/SelectionInfo.md +12 -12
  5. package/.docs/enumerations/Action.md +41 -31
  6. package/.docs/enumerations/ChangeOperation.md +4 -4
  7. package/.docs/enumerations/SelectionMode.md +2 -2
  8. package/.docs/interfaces/DUActionInterceptor.md +1 -1
  9. package/.docs/interfaces/PageRequest.md +3 -3
  10. package/.docs/interfaces/QuickFilter.md +3 -3
  11. package/.docs/interfaces/Record.md +4 -4
  12. package/.docs/interfaces/SavedRecord.md +5 -5
  13. package/.docs/interfaces/WaitingChange.md +3 -3
  14. package/.docs/type-aliases/DataUnitEventOptions.md +1 -1
  15. package/dist/dataunit/DataUnit.d.ts +19 -0
  16. package/dist/dataunit/DataUnit.js +34 -2
  17. package/dist/dataunit/DataUnit.js.map +1 -1
  18. package/dist/dataunit/metadata/DataType.d.ts +1 -1
  19. package/dist/dataunit/metadata/DataType.js +3 -3
  20. package/dist/dataunit/metadata/DataType.js.map +1 -1
  21. package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
  22. package/dist/dataunit/sorting/FieldComparator.js +4 -4
  23. package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
  24. package/dist/dataunit/state/action/DataUnitAction.d.ts +1 -0
  25. package/dist/dataunit/state/action/DataUnitAction.js +1 -0
  26. package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
  27. package/dist/utils/SortingUtils.js +9 -1
  28. package/dist/utils/SortingUtils.js.map +1 -1
  29. package/package.json +1 -1
  30. package/reports/test-report.xml +483 -483
  31. package/src/dataunit/DataUnit.ts +41 -3
  32. package/src/dataunit/metadata/DataType.ts +3 -3
  33. package/src/dataunit/sorting/FieldComparator.ts +4 -4
  34. package/src/dataunit/state/action/DataUnitAction.ts +2 -0
  35. package/src/utils/SortingUtils.ts +10 -1
@@ -55,6 +55,8 @@ export default class DataUnit {
55
55
  private _allowReleaseCallbacks: boolean;
56
56
  private _waitingToReload: boolean = false;
57
57
  private _cancelPagination: boolean = false;
58
+ private _isMultipleEdition: boolean = false;
59
+ private _fieldSourceValue: Map<string, string> = new Map<string, string>();
58
60
 
59
61
  public metadataLoader?: (dataUnit: DataUnit) => Promise<UnitMetadata>;
60
62
  public dataLoader?: (dataUnit: DataUnit, request: LoadDataRequest) => Promise<LoadDataResponse>;
@@ -183,6 +185,21 @@ export default class DataUnit {
183
185
  this._cancelPagination = cancelPagination;
184
186
  }
185
187
 
188
+ /**
189
+ * Informa se o DataUnit está no modo de edição de múltiplos registros.
190
+ */
191
+ public get isMultipleEdition(): boolean {
192
+ return this._isMultipleEdition;
193
+ }
194
+
195
+ /**
196
+ * Define se o DataUnit está no modo de edição de múltiplos registros.
197
+ */
198
+ public set isMultipleEdition(isMultipleEdition) {
199
+ this._isMultipleEdition = isMultipleEdition;
200
+ this.dispatchAction(Action.MULTIPLE_EDITION_CHANGED, {isMultipleEdition});
201
+ }
202
+
186
203
  /**
187
204
  *
188
205
  * Obtém o nome de identificação do DataUnit (geralmente em formato de URI - Uniform Resource Identifier).
@@ -1031,7 +1048,7 @@ export default class DataUnit {
1031
1048
  const typedValue = this.validateAndTypeValue(fieldName, newValue);
1032
1049
  const currentValue = this.getFieldValue(fieldName);
1033
1050
 
1034
- if(!(newValue instanceof Promise) && ObjectUtils.hasEquivalentProps(currentValue, typedValue)){
1051
+ if(this.areEquivalentValues(newValue, currentValue, typedValue)) {
1035
1052
  return Promise.resolve(false);
1036
1053
  }
1037
1054
 
@@ -1046,7 +1063,7 @@ export default class DataUnit {
1046
1063
  return promise;
1047
1064
  }
1048
1065
 
1049
- if (currentValue !== typedValue) {
1066
+ if (this.isMultipleEdition || currentValue !== typedValue) {
1050
1067
  const promise = this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records }, undefined, options);
1051
1068
  this._savingLockers.push(promise);
1052
1069
  return promise;
@@ -1055,6 +1072,12 @@ export default class DataUnit {
1055
1072
  return Promise.resolve(false);
1056
1073
  }
1057
1074
 
1075
+ private areEquivalentValues(newValue: any, currentValue: any, typedValue: any) {
1076
+ return !(newValue instanceof Promise)
1077
+ && ObjectUtils.hasEquivalentProps(currentValue, typedValue)
1078
+ && !this.isMultipleEdition;
1079
+ }
1080
+
1058
1081
  /**
1059
1082
  *
1060
1083
  * Marca campos como inválidos.
@@ -1265,7 +1288,7 @@ export default class DataUnit {
1265
1288
  public getSelectionInfo(): SelectionInfo{
1266
1289
  const selectionInfo: SelectionInfo = getSelectionInfo(this._stateManager);
1267
1290
  selectionInfo.getAllRecords = () => {
1268
-
1291
+
1269
1292
  let records = this.allRecordsLoader?.(this) ?? [];
1270
1293
 
1271
1294
  if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
@@ -1938,6 +1961,21 @@ export default class DataUnit {
1938
1961
  this._allowReleaseCallbacks = allow;
1939
1962
  }
1940
1963
 
1964
+
1965
+ /**
1966
+ * Adiciona um mapeamento de origem dos dados de um determinado campo
1967
+ */
1968
+ public addSourceFieldValue(sourceFieldName:string, targetFieldName:string): void{
1969
+ this._fieldSourceValue.set(sourceFieldName, targetFieldName);
1970
+ }
1971
+
1972
+ /**
1973
+ * Retornar o campo de origem dos dados caso exista mapeamento
1974
+ */
1975
+ public getSourceFieldValue(targetFieldName:string): string | undefined{
1976
+ return this._fieldSourceValue.get(targetFieldName);
1977
+ }
1978
+
1941
1979
  private async processLoadingLockers(){
1942
1980
  if(this._loadingLockers.length) {
1943
1981
  await Promise.all(this._loadingLockers);
@@ -148,7 +148,7 @@ const isSearchField = (userInterface:UserInterface | undefined): boolean => {
148
148
  return userInterface === UserInterface.SEARCH || userInterface === UserInterface.SEARCHPLUS;
149
149
  }
150
150
 
151
- export const compareValues = (valueA: any, valueB: any, descriptor: FieldDescriptor): number => {
151
+ export const compareValues = (valueA: any, valueB: any, descriptor: FieldDescriptor, onlyLabel:boolean = false): number => {
152
152
 
153
153
  if(useStringForComparison(descriptor)){
154
154
  return (getFormattedValue(valueA, descriptor) as string).localeCompare(getFormattedValue(valueB, descriptor));
@@ -156,8 +156,8 @@ export const compareValues = (valueA: any, valueB: any, descriptor: FieldDescrip
156
156
 
157
157
  const {dataType, userInterface} = descriptor;
158
158
  if(isSearchField(userInterface) || userInterface === UserInterface.OPTIONSELECTOR){
159
- const optionValueA = valueA?.value || valueA;
160
- const optionValueB = valueB?.value || valueB;
159
+ const optionValueA = (onlyLabel ? valueA?.label : valueA?.value) || valueA;
160
+ const optionValueB = (onlyLabel ? valueB?.label : valueB?.value) || valueB;
161
161
  if(isNaN(optionValueA) || isNaN(optionValueB)){
162
162
  return (optionValueA as string).localeCompare(optionValueB);
163
163
  }
@@ -4,16 +4,16 @@ import { FieldDescriptor } from '../metadata/UnitMetadata.js';
4
4
 
5
5
  export class FieldComparator {
6
6
 
7
- public static compare(field: FieldDescriptor, recordA: Record, recordB: Record, asc: boolean = true): number {
7
+ public static compare(field: FieldDescriptor, recordA: Record, recordB: Record, asc: boolean = true, onlyLabel: boolean = false): number {
8
8
  const valueA = (asc ? recordA : recordB)[field.name];
9
9
  const valueB = (asc ? recordB : recordA)[field.name];
10
10
 
11
- return FieldComparator.compareValues(field, valueA, valueB);
11
+ return FieldComparator.compareValues(field, valueA, valueB, onlyLabel);
12
12
  }
13
13
 
14
- public static compareValues(descriptor: FieldDescriptor, valueA: any, valueB: any): number {
14
+ public static compareValues(descriptor: FieldDescriptor, valueA: any, valueB: any, onlyLabel: boolean = false): number {
15
15
  const undefinedComparison = this.compareUndefined(valueA == undefined, valueB == undefined);
16
- return (undefinedComparison != undefined) ? undefinedComparison : compareValues(valueA, valueB, descriptor);
16
+ return (undefinedComparison != undefined) ? undefinedComparison : compareValues(valueA, valueB, descriptor, onlyLabel);
17
17
  }
18
18
 
19
19
  public static compareUndefined(isUndefinedA: boolean, isUndefinedB: boolean): number | undefined {
@@ -26,6 +26,8 @@ export interface ExecutionContext{
26
26
 
27
27
  export enum Action{
28
28
 
29
+ MULTIPLE_EDITION_CHANGED = "multipleEditionChanged",
30
+
29
31
  LOADING_METADATA = "loadingMetadata",
30
32
  METADATA_LOADED = "metadataLoaded",
31
33
 
@@ -17,7 +17,16 @@ export default class SortingUtils {
17
17
  return (recordA, recordB) => {
18
18
  for (const sort of sorting) {
19
19
  if (sort.field){
20
- const result = FieldComparator.compare(dataUnit.getField(sort.field) as FieldDescriptor, recordA, recordB, sort.mode === SortMode.ASC);
20
+ let field = dataUnit.getField(sort.field) as FieldDescriptor;
21
+ let onlyLabel = false;
22
+ if(!field){
23
+ const sourceFieldName = dataUnit.getSourceFieldValue(sort.field) ?? "";
24
+
25
+ field = dataUnit.getField(sourceFieldName) as FieldDescriptor;
26
+ onlyLabel = true;
27
+ }
28
+
29
+ const result = FieldComparator.compare(field, recordA, recordB, sort.mode === SortMode.ASC, onlyLabel);
21
30
  if (result != 0) {
22
31
  return result;
23
32
  }