mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Canvas: Button element (alpha) (#57491)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { AppEvents } from '@grafana/data/src';
|
||||
import { AppEvents, PluginState, SelectableValue } from '@grafana/data';
|
||||
import { hasAlphaPanels } from 'app/core/config';
|
||||
|
||||
import appEvents from '../../../core/app_events';
|
||||
import { CanvasElementItem, canvasElementRegistry, defaultElementItems } from '../../../features/canvas';
|
||||
import { advancedElementItems, CanvasElementItem, defaultElementItems } from '../../../features/canvas';
|
||||
import { ElementState } from '../../../features/canvas/runtime/element';
|
||||
import { FrameState } from '../../../features/canvas/runtime/frame';
|
||||
import { Scene, SelectionParams } from '../../../features/canvas/runtime/scene';
|
||||
@@ -25,13 +26,46 @@ export function doSelect(scene: Scene, element: ElementState | FrameState) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getElementTypes(
|
||||
shouldShowAdvancedTypes: boolean | undefined,
|
||||
current: string[] | undefined = undefined
|
||||
) {
|
||||
return shouldShowAdvancedTypes
|
||||
? canvasElementRegistry.selectOptions(current, (elementItem) => elementItem.id !== 'button').options
|
||||
: canvasElementRegistry.selectOptions(current, (elementItem: CanvasElementItem<any, any>) => {
|
||||
return !!defaultElementItems.filter((item) => item.id === elementItem.id).length;
|
||||
}).options;
|
||||
export function getElementTypes(shouldShowAdvancedTypes: boolean | undefined, current?: string): RegistrySelectInfo {
|
||||
if (shouldShowAdvancedTypes) {
|
||||
return getElementTypesOptions([...defaultElementItems, ...advancedElementItems], current);
|
||||
}
|
||||
|
||||
return getElementTypesOptions([...defaultElementItems], current);
|
||||
}
|
||||
|
||||
interface RegistrySelectInfo {
|
||||
options: Array<SelectableValue<string>>;
|
||||
current: Array<SelectableValue<string>>;
|
||||
}
|
||||
|
||||
export function getElementTypesOptions(
|
||||
items: Array<CanvasElementItem<any>>,
|
||||
current: string | undefined
|
||||
): RegistrySelectInfo {
|
||||
const selectables: RegistrySelectInfo = { options: [], current: [] };
|
||||
const alpha: Array<SelectableValue<string>> = [];
|
||||
|
||||
for (const item of items) {
|
||||
const option: SelectableValue<string> = { label: item.name, value: item.id, description: item.description };
|
||||
if (item.state === PluginState.alpha) {
|
||||
if (!hasAlphaPanels) {
|
||||
continue;
|
||||
}
|
||||
option.label = `${item.name} (Alpha)`;
|
||||
alpha.push(option);
|
||||
} else {
|
||||
selectables.options.push(option);
|
||||
}
|
||||
|
||||
if (item.id === current) {
|
||||
selectables.current.push(option);
|
||||
}
|
||||
}
|
||||
|
||||
for (const a of alpha) {
|
||||
selectables.options.push(a);
|
||||
}
|
||||
|
||||
return selectables;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user