@sankhyalabs/core 5.20.0-dev.82 → 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.
- package/.docs/classes/Change.md +11 -11
- package/.docs/classes/DataUnit.md +176 -124
- package/.docs/classes/FieldComparator.md +6 -2
- package/.docs/classes/SelectionInfo.md +12 -12
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/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/.docs/type-aliases/DataUnitEventOptions.md +1 -1
- package/dist/dataunit/DataUnit.d.ts +9 -0
- package/dist/dataunit/DataUnit.js +13 -0
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/metadata/DataType.d.ts +1 -1
- package/dist/dataunit/metadata/DataType.js +3 -3
- package/dist/dataunit/metadata/DataType.js.map +1 -1
- package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
- package/dist/dataunit/sorting/FieldComparator.js +4 -4
- package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
- package/dist/utils/SortingUtils.js +9 -1
- package/dist/utils/SortingUtils.js.map +1 -1
- package/package.json +1 -1
- package/reports/test-report.xml +392 -392
- package/src/dataunit/DataUnit.ts +17 -1
- package/src/dataunit/metadata/DataType.ts +3 -3
- package/src/dataunit/sorting/FieldComparator.ts +4 -4
- package/src/utils/SortingUtils.ts +10 -1
package/src/dataunit/DataUnit.ts
CHANGED
|
@@ -56,6 +56,7 @@ export default class DataUnit {
|
|
|
56
56
|
private _waitingToReload: boolean = false;
|
|
57
57
|
private _cancelPagination: boolean = false;
|
|
58
58
|
private _isMultipleEdition: boolean = false;
|
|
59
|
+
private _fieldSourceValue: Map<string, string> = new Map<string, string>();
|
|
59
60
|
|
|
60
61
|
public metadataLoader?: (dataUnit: DataUnit) => Promise<UnitMetadata>;
|
|
61
62
|
public dataLoader?: (dataUnit: DataUnit, request: LoadDataRequest) => Promise<LoadDataResponse>;
|
|
@@ -1287,7 +1288,7 @@ export default class DataUnit {
|
|
|
1287
1288
|
public getSelectionInfo(): SelectionInfo{
|
|
1288
1289
|
const selectionInfo: SelectionInfo = getSelectionInfo(this._stateManager);
|
|
1289
1290
|
selectionInfo.getAllRecords = () => {
|
|
1290
|
-
|
|
1291
|
+
|
|
1291
1292
|
let records = this.allRecordsLoader?.(this) ?? [];
|
|
1292
1293
|
|
|
1293
1294
|
if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
|
|
@@ -1960,6 +1961,21 @@ export default class DataUnit {
|
|
|
1960
1961
|
this._allowReleaseCallbacks = allow;
|
|
1961
1962
|
}
|
|
1962
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
|
+
|
|
1963
1979
|
private async processLoadingLockers(){
|
|
1964
1980
|
if(this._loadingLockers.length) {
|
|
1965
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 {
|
|
@@ -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
|
-
|
|
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
|
}
|