mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 02:10:45 -06:00
Transformers: fixes column names generated by seriesToColumn transformer (#23642)
This commit is contained in:
parent
6c021f7bb9
commit
0205c42bfa
@ -2,6 +2,7 @@ import {
|
||||
ArrayVector,
|
||||
DataTransformerConfig,
|
||||
DataTransformerID,
|
||||
Field,
|
||||
FieldType,
|
||||
toDataFrame,
|
||||
transformDataFrame,
|
||||
@ -178,4 +179,58 @@ describe('SeriesToColumns Transformer', () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
describe('Field names', () => {
|
||||
const seriesWithSameFieldAndDataFrameName = toDataFrame({
|
||||
name: 'temperature',
|
||||
fields: [
|
||||
{ name: 'time', type: FieldType.time, values: [1000, 2000, 3000, 4000] },
|
||||
{ name: 'temperature', type: FieldType.number, values: [1, 3, 5, 7] },
|
||||
],
|
||||
});
|
||||
|
||||
const seriesB = toDataFrame({
|
||||
name: 'B',
|
||||
fields: [
|
||||
{ name: 'time', type: FieldType.time, values: [1000, 2000, 3000, 4000] },
|
||||
{ name: 'temperature', type: FieldType.number, values: [2, 4, 6, 8] },
|
||||
],
|
||||
});
|
||||
|
||||
it('when dataframe and field share the same name then use the field name', () => {
|
||||
const cfg: DataTransformerConfig<SeriesToColumnsOptions> = {
|
||||
id: DataTransformerID.seriesToColumns,
|
||||
options: {
|
||||
byField: 'time',
|
||||
},
|
||||
};
|
||||
|
||||
const filtered = transformDataFrame([cfg], [seriesWithSameFieldAndDataFrameName, seriesB])[0];
|
||||
const expected: Field[] = [
|
||||
{
|
||||
name: 'time',
|
||||
type: FieldType.time,
|
||||
values: new ArrayVector([1000, 2000, 3000, 4000]),
|
||||
config: {},
|
||||
labels: { origin: 'temperature,B' },
|
||||
},
|
||||
{
|
||||
name: 'temperature',
|
||||
type: FieldType.number,
|
||||
values: new ArrayVector([1, 3, 5, 7]),
|
||||
config: {},
|
||||
labels: { origin: 'temperature' },
|
||||
},
|
||||
{
|
||||
name: 'temperature {B}',
|
||||
type: FieldType.number,
|
||||
values: new ArrayVector([2, 4, 6, 8]),
|
||||
config: {},
|
||||
labels: { origin: 'B' },
|
||||
},
|
||||
];
|
||||
|
||||
expect(filtered.fields).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -111,9 +111,10 @@ export const seriesToColumnsTransformer: DataTransformerInfo<SeriesToColumnsOpti
|
||||
|
||||
const getColumnName = (frames: DataFrame[], frameIndex: number, fieldIndex: number, isKeyField = false) => {
|
||||
const frame = frames[frameIndex];
|
||||
const field = frame.fields[fieldIndex];
|
||||
const frameName = frame.name || `${frameIndex}`;
|
||||
const fieldName = frame.fields[fieldIndex].name;
|
||||
const seriesName = isKeyField ? fieldName : `${fieldName} {${frameName}}`;
|
||||
const fieldName = field.name;
|
||||
const seriesName = isKeyField ? fieldName : fieldName === frameName ? fieldName : `${fieldName} {${frameName}}`;
|
||||
|
||||
return seriesName;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user