Commit 7d72837d by Torkel Ödegaard Committed by GitHub

DataFrame: Data source field naming control that does not use field.config.displayName (#27186)

* Field naming simple fix

* fixed unit tests

* Updated to use displayNameDS config

* Update packages/grafana-data/src/types/dataFrame.ts

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>

* Updated name

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
parent 57b2d087
......@@ -95,7 +95,7 @@ function convertTimeSeriesToDataFrame(timeSeries: TimeSeries): DataFrame {
];
if (timeSeries.title) {
(fields[1].config as FieldConfig).displayName = timeSeries.title;
(fields[1].config as FieldConfig).displayNameFromDS = timeSeries.title;
}
return {
......
......@@ -58,6 +58,10 @@ function calculateFieldDisplayName(field: Field, frame?: DataFrame, allFrames?:
return displayName;
}
if (frame && field.config?.displayNameFromDS) {
return field.config.displayNameFromDS;
}
// This is an ugly exception for time field
// For time series we should normally treat time field with same name
// But in case it has a join source we should handle it as normal field
......
......@@ -23,7 +23,20 @@ export enum FieldType {
* Plugins may extend this with additional properties. Something like series overrides
*/
export interface FieldConfig<TOptions extends object = any> {
displayName?: string; // The display value for this field. This supports template variables blank is auto
/**
* The display value for this field. This supports template variables blank is auto
*/
displayName?: string;
/**
* This can be used by data sources that return and explicit naming structure for values and labels
* When this property is configured, this value is used rather than the default naming strategy.
*/
displayNameFromDS?: string;
/**
* True if data source field supports ad-hoc filters
*/
filterable?: boolean;
// Numeric Options
......
......@@ -625,7 +625,7 @@ describe('PrometheusDatasource', () => {
it('should return series list', async () => {
const frame = toDataFrame(results.data[0]);
expect(results.data.length).toBe(1);
expect(getFieldDisplayName(frame.fields[1])).toBe('test{job="testjob"}');
expect(getFieldDisplayName(frame.fields[1], frame)).toBe('test{job="testjob"}');
});
});
......@@ -771,7 +771,7 @@ describe('PrometheusDatasource', () => {
const frame = toDataFrame(results.data[0]);
expect(results.data.length).toBe(1);
expect(frame.name).toBe('test{job="testjob"}');
expect(getFieldDisplayName(frame.fields[1])).toBe('test{job="testjob"}');
expect(getFieldDisplayName(frame.fields[1], frame)).toBe('test{job="testjob"}');
});
});
......@@ -1721,7 +1721,7 @@ describe('PrometheusDatasource for POST', () => {
it('should return series list', () => {
const frame = toDataFrame(results.data[0]);
expect(results.data.length).toBe(1);
expect(getFieldDisplayName(frame.fields[1])).toBe('test{job="testjob"}');
expect(getFieldDisplayName(frame.fields[1], frame)).toBe('test{job="testjob"}');
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment