Canvas: Fix setting icon from field data #58499

This commit is contained in:
Nathan Marrs 2022-11-10 10:56:31 -08:00 committed by GitHub
parent 41c491e2db
commit 47055561ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 12 deletions

View File

@ -3870,12 +3870,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/features/dimensions/resource.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
],
"public/app/features/dimensions/scale.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],

View File

@ -10,7 +10,7 @@ export function getPublicOrAbsoluteUrl(v: string): string {
if (!v) {
return '';
}
return v.indexOf(':/') > 0 ? v : (window as any).__grafana_public_path__ + v;
return v.indexOf(':/') > 0 ? v : window.__grafana_public_path__ + v;
}
export function getResourceDimension(
@ -19,7 +19,7 @@ export function getResourceDimension(
): DimensionSupplier<string> {
const mode = config.mode ?? ResourceDimensionMode.Fixed;
if (mode === ResourceDimensionMode.Fixed) {
const v = getPublicOrAbsoluteUrl(config.fixed!);
const v = getPublicOrAbsoluteUrl(config.fixed);
return {
isAssumed: !Boolean(v),
fixed: v,
@ -40,7 +40,7 @@ export function getResourceDimension(
}
if (mode === ResourceDimensionMode.Mapping) {
const mapper = (v: any) => getPublicOrAbsoluteUrl(`${v}`);
const mapper = (v: string) => getPublicOrAbsoluteUrl(`${v}`);
return {
field,
get: (i) => mapper(field.values.get(i)),
@ -48,9 +48,10 @@ export function getResourceDimension(
};
}
const getIcon = (value: any): string => {
const disp = field.display!;
return getPublicOrAbsoluteUrl(disp(value).icon ?? '');
// mode === ResourceDimensionMode.Field case
const getIcon = (value: string): string => {
const display = field.display!;
return getPublicOrAbsoluteUrl(display(value).icon ?? value ?? '');
};
return {