Transformations: Keep original field.labels.name when joining frames (#88873)

This commit is contained in:
Leon Sorokin 2024-06-10 09:16:58 -05:00 committed by GitHub
parent 03a000e1b5
commit 89a0bec208
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 2 deletions

View File

@ -477,6 +477,38 @@ describe('align frames', () => {
`);
});
it('add frame.name as field.labels.name only when field.labels.name does not exist', () => {
const series1 = toDataFrame({
name: 'Frame A',
fields: [
{ name: 'Time', type: FieldType.time, values: [1000, 2000] },
{ name: 'Metric 1', type: FieldType.number, values: [1, 100], labels: { name: 'bar' } },
],
});
const series2 = toDataFrame({
name: 'Frame B',
fields: [
{ name: 'Time', type: FieldType.time, values: [1000] },
{ name: 'Metric 2', type: FieldType.number, values: [150] },
],
});
const series3 = toDataFrame({
name: 'Frame C',
fields: [
{ name: 'Time', type: FieldType.time, values: [1000] },
{ name: 'Value', type: FieldType.number, values: [150] }, // weird that in this "Value" case it doesnt get moved into field.labels.name
],
});
const out = joinDataFrames({ frames: [series1, series2, series3] })!;
expect(out.fields[1].labels).toEqual({ name: 'bar' });
expect(out.fields[2].labels).toEqual({ name: 'Frame B' });
expect(out.fields[3].labels).toEqual({});
});
it('supports duplicate times', () => {
//----------
// NOTE!!!

View File

@ -203,7 +203,8 @@ export function joinDataFrames(options: JoinOptions): DataFrame | undefined {
if (frame.name) {
if (field.name === TIME_SERIES_VALUE_FIELD_NAME) {
name = frame.name;
} else {
} else if (labels.name == null) {
// add the name label from frame
labels = { ...labels, name: frame.name };
}
}
@ -211,7 +212,7 @@ export function joinDataFrames(options: JoinOptions): DataFrame | undefined {
fields.push({
...field,
name,
labels, // add the name label from frame
labels,
});
}