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

* Add support for 0 empty value

* Remove only

* Add zero option
pull/98224/head
Tobias Skarhed 6 months ago committed by GitHub
parent e0af98dec8
commit c901b76a8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      packages/grafana-data/src/transformations/transformers/groupingToMatrix.test.ts
  2. 2
      packages/grafana-data/src/transformations/transformers/groupingToMatrix.ts
  3. 1
      packages/grafana-data/src/types/transformations.ts
  4. 1
      public/app/features/transformers/editors/GroupingToMatrixTransformerEditor.tsx

@ -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: {},
},
];

@ -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 '';

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

@ -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' },
];

Loading…
Cancel
Save