import { set, get as lodashGet } from 'lodash'; import { StandardEditorContext, TransformerUIProps, PanelOptionsEditorBuilder } from '@grafana/data'; import { PanelOptionsSupplier } from '@grafana/data/src/panel/PanelPlugin'; import { NestedValueAccess } from '@grafana/data/src/utils/OptionsUIBuilders'; import { OptionsPaneCategoryDescriptor } from 'app/features/dashboard/components/PanelEditor/OptionsPaneCategoryDescriptor'; import { fillOptionsPaneItems } from 'app/features/dashboard/components/PanelEditor/getVisualizationOptions'; import { setOptionImmutably } from 'app/features/dashboard/components/PanelEditor/utils'; export function getTransformerOptionPane( props: TransformerUIProps, supplier: PanelOptionsSupplier ): OptionsPaneCategoryDescriptor { const context: StandardEditorContext = { data: props.input, options: props.options, }; const root = new OptionsPaneCategoryDescriptor({ id: 'root', title: 'root' }); const getOptionsPaneCategory = (categoryNames?: string[]): OptionsPaneCategoryDescriptor => { if (categoryNames?.length) { const key = categoryNames[0]; let sub = root.categories.find((v) => v.props.id === key); if (!sub) { sub = new OptionsPaneCategoryDescriptor({ id: key, title: key }); root.categories.push(sub); } return sub; } return root; }; const access: NestedValueAccess = { getValue: (path: string) => lodashGet(props.options, path), onChange: (path: string, value: any) => { props.onChange(setOptionImmutably(props.options as any, path, value)); }, }; // Use the panel options loader fillOptionsPaneItems(supplier, access, getOptionsPaneCategory, context); return root; } export function getDefaultOptions(supplier: PanelOptionsSupplier): T { const context: StandardEditorContext = { data: [], options: {} as T, }; const results = {}; const builder = new PanelOptionsEditorBuilder(); supplier(builder, context); for (const item of builder.getItems()) { if (item.defaultValue != null) { set(results, item.path, item.defaultValue); } } return results as T; }