Chore: support empty/missing strings (#34027)

This commit is contained in:
Ryan McKinley
2021-05-12 16:51:20 -07:00
committed by GitHub
parent 7bcb938b80
commit 17750d3cdb
2 changed files with 9 additions and 0 deletions

View File

@@ -346,6 +346,11 @@ describe('Date display options', () => {
theme: createTheme(),
});
expect(processor('22.1122334455').text).toEqual('22.11');
// Support empty/missing strings
expect(processor(undefined).text).toEqual('');
expect(processor(null).text).toEqual('');
expect(processor('').text).toEqual('');
});
});
});

View File

@@ -137,6 +137,10 @@ export function getRawDisplayProcessor(): DisplayProcessor {
function getDefaultColorFunc(field: Field, scaleFunc: ScaleCalculator, theme: GrafanaTheme2) {
if (field.type === FieldType.string) {
return (value: any) => {
if (!value) {
return { color: theme.colors.background.primary, percent: 0 };
}
const hc = strHashCode(value as string);
return {
color: classicColors[Math.floor(hc % classicColors.length)],