Transformations: GroupToMatrix add 0 as special value (#97642)

* Add support for 0 empty value

* Remove only

* Add zero option
This commit is contained in:
Tobias Skarhed 2024-12-19 10:53:33 +01:00 committed by GitHub
parent e0af98dec8
commit c901b76a8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 4 deletions

View File

@ -105,11 +105,18 @@ describe('Grouping to Matrix', () => {
});
});
it('generates Matrix with empty entries', async () => {
it.each([
[undefined, ''],
[SpecialValue.Null, null],
[SpecialValue.False, false],
[SpecialValue.True, true],
[SpecialValue.Empty, ''],
[SpecialValue.Zero, 0],
])('generates Matrix with empty entries', async (emptyValue, expectedValue) => {
const cfg: DataTransformerConfig<GroupingToMatrixTransformerOptions> = {
id: DataTransformerID.groupingToMatrix,
options: {
emptyValue: SpecialValue.Null,
emptyValue: emptyValue,
},
};
@ -133,13 +140,13 @@ describe('Grouping to Matrix', () => {
{
name: '1000',
type: FieldType.number,
values: [1, null],
values: [1, expectedValue],
config: {},
},
{
name: '1001',
type: FieldType.number,
values: [null, 2],
values: [expectedValue, 2],
config: {},
},
];

View File

@ -183,6 +183,8 @@ function getSpecialValue(specialValue: SpecialValue) {
return true;
case SpecialValue.Null:
return null;
case SpecialValue.Zero:
return 0;
case SpecialValue.Empty:
default:
return '';

View File

@ -115,4 +115,5 @@ export enum SpecialValue {
False = 'false',
Null = 'null',
Empty = 'empty',
Zero = 'zero',
}

View File

@ -62,6 +62,7 @@ export const GroupingToMatrixTransformerEditor = ({
{ label: 'Null', value: SpecialValue.Null, description: 'Null value' },
{ label: 'True', value: SpecialValue.True, description: 'Boolean true value' },
{ label: 'False', value: SpecialValue.False, description: 'Boolean false value' },
{ label: 'Zero', value: SpecialValue.Zero, description: 'Number 0 value' },
{ label: 'Empty', value: SpecialValue.Empty, description: 'Empty string' },
];