@sankhyalabs/core 7.0.7 → 7.0.9
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/DataUnit.md +63 -63
- package/dist/dataunit/DataUnit.js +4 -1
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/formatting/PrettyFormatter.js +4 -1
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- package/package.json +1 -1
- package/reports/test-report.xml +381 -380
- package/src/dataunit/DataUnit.ts +3 -1
- package/src/dataunit/formatting/PrettyFormatter.ts +4 -0
- package/test/dataunit/formatting/PrettyFormatter.spec.ts +12 -0
package/src/dataunit/DataUnit.ts
CHANGED
|
@@ -1066,7 +1066,9 @@ export default class DataUnit {
|
|
|
1066
1066
|
if (noRecordSelected) await this.addRecord();
|
|
1067
1067
|
|
|
1068
1068
|
const typedValue = this.validateAndTypeValue(fieldName, newValue);
|
|
1069
|
-
const currentValue =
|
|
1069
|
+
const currentValue = records?.length === 1
|
|
1070
|
+
? (this.records.find(r => r.__record__id__ === records[0])?.[fieldName] ?? this.getFieldValue(fieldName))
|
|
1071
|
+
: this.getFieldValue(fieldName);
|
|
1070
1072
|
|
|
1071
1073
|
if (this.areEquivalentValues(newValue, currentValue, typedValue)) {
|
|
1072
1074
|
return Promise.resolve(false);
|
|
@@ -93,6 +93,10 @@ const getOptionFormat = (value: any, descriptor: FieldDescriptor) => {
|
|
|
93
93
|
} else {
|
|
94
94
|
options = {};
|
|
95
95
|
if(prop != undefined){
|
|
96
|
+
if (descriptor.properties?.switchLabelsAndValues) {
|
|
97
|
+
prop.forEach(opt => options[opt.value] = opt.label);
|
|
98
|
+
}
|
|
99
|
+
|
|
96
100
|
prop.forEach(opt => options[opt.label] = opt.value);
|
|
97
101
|
}
|
|
98
102
|
}
|
|
@@ -154,6 +154,18 @@ describe('getFormattedValue', () => {
|
|
|
154
154
|
expect(getFormattedValue(value, descriptor)).toBe('option1');
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
+
it('should return label when OPTIONSELECTOR has switchLabelsAndValues and value matches option value', () => {
|
|
158
|
+
const value = 'option1';
|
|
159
|
+
const descriptor: FieldDescriptor = {
|
|
160
|
+
userInterface: UserInterface.OPTIONSELECTOR,
|
|
161
|
+
properties: {
|
|
162
|
+
options: [{ label: 'Option 1', value: 'option1' }],
|
|
163
|
+
switchLabelsAndValues: true,
|
|
164
|
+
},
|
|
165
|
+
} as FieldDescriptor;
|
|
166
|
+
expect(getFormattedValue(value, descriptor)).toBe('Option 1');
|
|
167
|
+
});
|
|
168
|
+
|
|
157
169
|
it('should format masked values correctly', () => {
|
|
158
170
|
const value = '12345678901';
|
|
159
171
|
const descriptor = { properties: { mask: 'cpf' } } as FieldDescriptor;
|