mirror of
https://github.com/grafana/grafana.git
synced 2025-01-09 23:53:25 -06:00
Transformations: Keep original field.labels.name
when joining frames (#88873)
This commit is contained in:
parent
03a000e1b5
commit
89a0bec208
@ -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!!!
|
||||
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user