[release-11.6.4] ConvertFieldType: Handle undefined values in joinWith (#107417)

ConvertFieldType: Handle undefined values in joinWith (#106712)

fix: escalation fix - groupBy with joinWith
(cherry picked from commit 3497c85593)

Co-authored-by: Alex Spencer <52186778+alexjonspencer1@users.noreply.github.com>
This commit is contained in:
grafana-delivery-bot[bot]
2025-06-30 13:18:31 -07:00
committed by GitHub
co-authored by Alex Spencer
parent 5475b41e21
commit 75ad767aae
2 changed files with 30 additions and 1 deletions
@@ -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;