ConvertFieldType: Handle undefined values in joinWith (#106712)

fix: escalation fix - groupBy with joinWith
pull/105426/head
Alex Spencer 3 weeks ago committed by GitHub
parent b1d3155b60
commit 3497c85593
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 29
      packages/grafana-data/src/transformations/transformers/convertFieldType.test.ts
  2. 2
      packages/grafana-data/src/transformations/transformers/convertFieldType.ts

@ -423,6 +423,35 @@ describe('field convert types transformer', () => {
]);
});
it('will support custom join separators for field type string, correctly handling undefined and null', () => {
const options = {
conversions: [{ targetField: 'mixed_values', destinationType: FieldType.string, joinWith: '&' }],
};
const mixedValues = toDataFrame({
fields: [
{
name: 'mixed_values',
type: FieldType.string,
values: [['a', 'b', 'c'], ['d', undefined, 'f'], undefined, 'regular string', null],
},
],
});
const stringified = convertFieldTypes(options, [mixedValues]);
expect(
stringified[0].fields.map(({ type, values }) => ({
type,
values,
}))
).toEqual([
{
type: FieldType.string,
values: ['a&b&c', 'd&&f', undefined, '"regular string"', 'null'],
},
]);
});
it('will convert time fields to strings', () => {
const options = {
conversions: [{ targetField: 'time', destinationType: FieldType.string, dateFormat: 'YYYY-MM' }],

@ -218,7 +218,7 @@ export function fieldToStringField(
if (joinWith?.length && Array.isArray(v)) {
return v.join(joinWith);
}
return field.type === FieldType.other ? JSON.stringify(v) : `${v}`;
return JSON.stringify(v);
});
break;

Loading…
Cancel
Save