Commit 202c1362 by Torkel Ödegaard Committed by Ryan McKinley

FieldDisplay: Return field defaults when there are no data (#18357)

parent 7e89a93b
......@@ -135,4 +135,30 @@ describe('FieldDisplay', () => {
expect(field.thresholds!.length).toEqual(2);
expect(field.thresholds![0].value).toBe(-Infinity);
});
it('Should return field thresholds when there is no data', () => {
const options: GetFieldDisplayValuesOptions = {
data: [
{
name: 'No data',
fields: [],
rows: [],
},
],
replaceVariables: (value: string) => {
return value;
},
fieldOptions: {
calcs: [],
override: {},
defaults: {
thresholds: [{ color: '#F2495C', value: 50 }],
},
},
theme: getTheme(GrafanaThemeType.Dark),
};
const display = getFieldDisplayValues(options);
expect(display[0].field.thresholds!.length).toEqual(1);
});
});
......@@ -182,7 +182,10 @@ export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): Fi
if (values.length === 0) {
values.push({
field: { name: 'No Data' },
field: {
...defaults,
name: 'No Data',
},
display: {
numeric: 0,
text: 'No data',
......@@ -244,6 +247,7 @@ type PartialField = Partial<Field>;
export function getFieldProperties(...props: PartialField[]): Field {
let field = props[0] as Field;
for (let i = 1; i < props.length; i++) {
field = applyFieldProperties(field, props[i]);
}
......
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