mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 21:43:09 +08:00
Transformations: GroupToMatrix add 0 as special value (#97642)
* Add support for 0 empty value * Remove only * Add zero option
This commit is contained in:
@ -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> = {
|
const cfg: DataTransformerConfig<GroupingToMatrixTransformerOptions> = {
|
||||||
id: DataTransformerID.groupingToMatrix,
|
id: DataTransformerID.groupingToMatrix,
|
||||||
options: {
|
options: {
|
||||||
emptyValue: SpecialValue.Null,
|
emptyValue: emptyValue,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -133,13 +140,13 @@ describe('Grouping to Matrix', () => {
|
|||||||
{
|
{
|
||||||
name: '1000',
|
name: '1000',
|
||||||
type: FieldType.number,
|
type: FieldType.number,
|
||||||
values: [1, null],
|
values: [1, expectedValue],
|
||||||
config: {},
|
config: {},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '1001',
|
name: '1001',
|
||||||
type: FieldType.number,
|
type: FieldType.number,
|
||||||
values: [null, 2],
|
values: [expectedValue, 2],
|
||||||
config: {},
|
config: {},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -183,6 +183,8 @@ function getSpecialValue(specialValue: SpecialValue) {
|
|||||||
return true;
|
return true;
|
||||||
case SpecialValue.Null:
|
case SpecialValue.Null:
|
||||||
return null;
|
return null;
|
||||||
|
case SpecialValue.Zero:
|
||||||
|
return 0;
|
||||||
case SpecialValue.Empty:
|
case SpecialValue.Empty:
|
||||||
default:
|
default:
|
||||||
return '';
|
return '';
|
||||||
|
@ -115,4 +115,5 @@ export enum SpecialValue {
|
|||||||
False = 'false',
|
False = 'false',
|
||||||
Null = 'null',
|
Null = 'null',
|
||||||
Empty = 'empty',
|
Empty = 'empty',
|
||||||
|
Zero = 'zero',
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ export const GroupingToMatrixTransformerEditor = ({
|
|||||||
{ label: 'Null', value: SpecialValue.Null, description: 'Null value' },
|
{ label: 'Null', value: SpecialValue.Null, description: 'Null value' },
|
||||||
{ label: 'True', value: SpecialValue.True, description: 'Boolean true value' },
|
{ label: 'True', value: SpecialValue.True, description: 'Boolean true value' },
|
||||||
{ label: 'False', value: SpecialValue.False, description: 'Boolean false 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' },
|
{ label: 'Empty', value: SpecialValue.Empty, description: 'Empty string' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user