import { DynamicConfigValue, FieldConfigOptionsRegistry, FieldConfigProperty, FieldOverrideContext, GrafanaTheme, } from '@grafana/data'; import React from 'react'; import { Counter, Field, HorizontalGroup, IconButton, Label, stylesFactory, useTheme } from '@grafana/ui'; import { css, cx } from '@emotion/css'; import { OptionsPaneCategory } from './OptionsPaneCategory'; interface DynamicConfigValueEditorProps { property: DynamicConfigValue; registry: FieldConfigOptionsRegistry; onChange: (value: DynamicConfigValue) => void; context: FieldOverrideContext; onRemove: () => void; isSystemOverride?: boolean; } export const DynamicConfigValueEditor: React.FC = ({ property, context, registry, onChange, onRemove, isSystemOverride, }) => { const theme = useTheme(); const styles = getStyles(theme); const item = registry?.getIfExists(property.id); if (!item) { return null; } const isCollapsible = Array.isArray(property.value) || property.id === FieldConfigProperty.Thresholds || property.id === FieldConfigProperty.Links || property.id === FieldConfigProperty.Mappings; const labelCategory = item.category?.filter((c) => c !== item.name); let editor; // eslint-disable-next-line react/display-name const renderLabel = (includeDescription = true, includeCounter = false) => (isExpanded = false) => ( {!isSystemOverride && (
)}
); if (isCollapsible) { editor = ( { onChange(value); }} item={item} context={context} /> ); } else { editor = (
{ onChange(value); }} item={item} context={context} />
); } return (
{editor}
); }; const getStyles = stylesFactory((theme: GrafanaTheme) => { return { collapsibleOverrideEditor: css` label: collapsibleOverrideEditor; & + .dynamicConfigValueEditor--nonCollapsible { margin-top: ${theme.spacing.formSpacingBase}px; } `, }; });