mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Initial commit * Progress * Update * Progress * updates * Minor fix * fixed ts issue * fixed e2e tests * More explorations * Making progress * Panel options and field options unified * With nested categories * Starting to find something * fix paddings * Progress * Breakthrough ux layout * Progress * Updates * New way of composing options with search * added regex search * Refactoring to react note tree * Show overrides * Adding overrides radio button support * Added popular view * Separate stat/gauge/bargauge options into value options and display options * Initial work on getting library panels into viz picker flow * Fixed issues switching to panel library panel * Move search input put of LibraryPanelsView * Changing design again to have content inside boxes * Style updates * Refactoring to fix scroll issue * Option category naming * Fixed FilterInput issue * Updated snapshots * Fix padding * Updated viz picker design * Unify library panel an viz picker card * Updated card with delete action * Major refactoring back to an object model instead of searching and filtering react node tree * More refactoring * Show option category in label when searching * Nice logic for categories rendering when searching or when only child * Make getSuggestions more lazy for DataLinksEditor * Add missing repeat options and handle conditional options * Prepping options category to be more flexibly and control state from outside * Added option count to search result * Minor style tweak * Added button to close viz picker * Rewrote overrides to enable searching overrides * New search engine and tests * Searching overrides works * Hide radio buttons while searching * Added angular options back * Added memoize for all options so they are not rebuilt for every search key stroke * Added back support for category counters * Started unit test work * Refactoring and base popular options list * Initial update to e2e test, more coming to add e2e test for search features * Minor fix * Review updates * Fixing category open states * Unit test progress * Do not show visualization list mode radio button if library panels is not enabled * Use boolean * More unit tests * Increase library panels per page count and give search focus when switching list mode * field config change test and search test * Feedback updates * Minor tweaks * Minor refactorings * More minimal override collapse state
119 lines
3.8 KiB
TypeScript
119 lines
3.8 KiB
TypeScript
import React from 'react';
|
|
import { StandardEditorContext, VariableSuggestionsScope } from '@grafana/data';
|
|
import { get as lodashGet, set as lodashSet } from 'lodash';
|
|
import { getPanelOptionsVariableSuggestions } from 'app/features/panel/panellinks/link_srv';
|
|
import { OptionPaneRenderProps } from './types';
|
|
import { updateDefaultFieldConfigValue } from './utils';
|
|
import { OptionsPaneItemDescriptor } from './OptionsPaneItemDescriptor';
|
|
import { OptionsPaneCategoryDescriptor } from './OptionsPaneCategoryDescriptor';
|
|
|
|
export function getVizualizationOptions(props: OptionPaneRenderProps): OptionsPaneCategoryDescriptor[] {
|
|
const { plugin, panel, onPanelOptionsChanged, onFieldConfigsChange, data, dashboard } = props;
|
|
const currentOptions = panel.getOptions();
|
|
const currentFieldConfig = panel.fieldConfig;
|
|
const categoryIndex: Record<string, OptionsPaneCategoryDescriptor> = {};
|
|
|
|
const context: StandardEditorContext<any> = {
|
|
data: data?.series || [],
|
|
replaceVariables: panel.replaceVariables,
|
|
options: currentOptions,
|
|
eventBus: dashboard.events,
|
|
getSuggestions: (scope?: VariableSuggestionsScope) => {
|
|
return getPanelOptionsVariableSuggestions(plugin, data?.series);
|
|
},
|
|
};
|
|
|
|
const getOptionsPaneCategory = (categoryNames?: string[]): OptionsPaneCategoryDescriptor => {
|
|
const categoryName = (categoryNames && categoryNames[0]) ?? `${plugin.meta.name}`;
|
|
const category = categoryIndex[categoryName];
|
|
|
|
if (category) {
|
|
return category;
|
|
}
|
|
|
|
return (categoryIndex[categoryName] = new OptionsPaneCategoryDescriptor({
|
|
title: categoryName,
|
|
id: categoryName,
|
|
}));
|
|
};
|
|
|
|
/**
|
|
* Panel options
|
|
*/
|
|
for (const pluginOption of plugin.optionEditors.list()) {
|
|
const category = getOptionsPaneCategory(pluginOption.category);
|
|
const Editor = pluginOption.editor;
|
|
|
|
category.addItem(
|
|
new OptionsPaneItemDescriptor({
|
|
title: pluginOption.name,
|
|
description: pluginOption.description,
|
|
Component: function renderEditor() {
|
|
const onChange = (value: any) => {
|
|
const newOptions = lodashSet({ ...currentOptions }, pluginOption.path, value);
|
|
onPanelOptionsChanged(newOptions);
|
|
};
|
|
|
|
return (
|
|
<Editor
|
|
value={lodashGet(currentOptions, pluginOption.path)}
|
|
onChange={onChange}
|
|
item={pluginOption}
|
|
context={context}
|
|
/>
|
|
);
|
|
},
|
|
})
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Field options
|
|
*/
|
|
for (const fieldOption of plugin.fieldConfigRegistry.list()) {
|
|
if (
|
|
fieldOption.isCustom &&
|
|
fieldOption.showIf &&
|
|
!fieldOption.showIf(currentFieldConfig.defaults.custom, data?.series)
|
|
) {
|
|
continue;
|
|
}
|
|
|
|
if (fieldOption.hideFromDefaults) {
|
|
continue;
|
|
}
|
|
|
|
const category = getOptionsPaneCategory(fieldOption.category);
|
|
const Editor = fieldOption.editor;
|
|
|
|
const defaults = currentFieldConfig.defaults;
|
|
const value = fieldOption.isCustom
|
|
? defaults.custom
|
|
? lodashGet(defaults.custom, fieldOption.path)
|
|
: undefined
|
|
: lodashGet(defaults, fieldOption.path);
|
|
|
|
if (fieldOption.getItemsCount) {
|
|
category.props.itemsCount = fieldOption.getItemsCount(value);
|
|
}
|
|
|
|
category.addItem(
|
|
new OptionsPaneItemDescriptor({
|
|
title: fieldOption.name,
|
|
description: fieldOption.description,
|
|
Component: function renderEditor() {
|
|
const onChange = (v: any) => {
|
|
onFieldConfigsChange(
|
|
updateDefaultFieldConfigValue(currentFieldConfig, fieldOption.path, v, fieldOption.isCustom)
|
|
);
|
|
};
|
|
|
|
return <Editor value={value} onChange={onChange} item={fieldOption} context={context} />;
|
|
},
|
|
})
|
|
);
|
|
}
|
|
|
|
return Object.values(categoryIndex);
|
|
}
|