mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Canvas: Add icon value mapping (#59013)
This commit is contained in:
parent
51359fe90d
commit
e157ef1171
19
public/app/features/dimensions/resource.test.ts
Normal file
19
public/app/features/dimensions/resource.test.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { getResourceDimension } from './resource';
|
||||
import { ResourceDimensionMode } from './types';
|
||||
|
||||
describe('getResourceDimension', () => {
|
||||
const publicPath = '/public/';
|
||||
beforeAll(() => {
|
||||
window.__grafana_public_path__ = publicPath;
|
||||
});
|
||||
|
||||
it('fixed mode', () => {
|
||||
const frame = undefined;
|
||||
const fixedValue = 'img/icons/unicons/question-circle.svg';
|
||||
const config = { mode: ResourceDimensionMode.Fixed, fixed: fixedValue };
|
||||
|
||||
expect(getResourceDimension(frame, config).fixed).toEqual(publicPath + fixedValue);
|
||||
});
|
||||
|
||||
// TODO: write tests for field and mapping modes
|
||||
});
|
@ -50,8 +50,12 @@ export function getResourceDimension(
|
||||
|
||||
// mode === ResourceDimensionMode.Field case
|
||||
const getIcon = (value: string): string => {
|
||||
const display = field.display!;
|
||||
return getPublicOrAbsoluteUrl(display(value).icon ?? value ?? '');
|
||||
if (field && field.display) {
|
||||
const icon = field.display(value).icon;
|
||||
return getPublicOrAbsoluteUrl(icon ?? '');
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
return {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { PanelOptionsEditorBuilder, PanelPlugin } from '@grafana/data';
|
||||
import { FieldConfigProperty, PanelOptionsEditorBuilder, PanelPlugin } from '@grafana/data';
|
||||
import { FrameState } from 'app/features/canvas/runtime/frame';
|
||||
|
||||
import { CanvasPanel, InstanceState } from './CanvasPanel';
|
||||
@ -25,7 +25,15 @@ export const addStandardCanvasEditorOptions = (builder: PanelOptionsEditorBuilde
|
||||
|
||||
export const plugin = new PanelPlugin<PanelOptions>(CanvasPanel)
|
||||
.setNoPadding() // extend to panel edges
|
||||
.useFieldConfig()
|
||||
.useFieldConfig({
|
||||
standardOptions: {
|
||||
[FieldConfigProperty.Mappings]: {
|
||||
settings: {
|
||||
icon: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
.setMigrationHandler(canvasMigrationHandler)
|
||||
.setPanelOptions((builder, context) => {
|
||||
const state: InstanceState = context.instanceState;
|
||||
|
Loading…
Reference in New Issue
Block a user