import React from 'react'; import capitalize from 'lodash/capitalize'; import without from 'lodash/without'; import { LegendOptions, PanelOptionsGroup, Switch, Input } from '@grafana/ui'; export interface GraphLegendEditorLegendOptions extends LegendOptions { stats?: string[]; decimals?: number; sortBy?: string; sortDesc?: boolean; } interface GraphLegendEditorProps { stats: string[]; options: GraphLegendEditorLegendOptions; onChange: (options: GraphLegendEditorLegendOptions) => void; } export const GraphLegendEditor: React.FunctionComponent = props => { const { stats, options, onChange } = props; const onStatToggle = (stat: string) => (event?: React.SyntheticEvent) => { let newStats; if (!event) { return; } // @ts-ignore if (event.target.checked) { newStats = (options.stats || []).concat([stat]); } else { newStats = without(options.stats, stat); } onChange({ ...options, stats: newStats, }); }; const onOptionToggle = (option: keyof LegendOptions) => (event?: React.SyntheticEvent) => { const newOption = {}; if (!event) { return; } // TODO: fix the ignores // @ts-ignore newOption[option] = event.target.checked; if (option === 'placement') { // @ts-ignore newOption[option] = event.target.checked ? 'right' : 'under'; } onChange({ ...options, ...newOption, }); }; return (

Options

Values

{stats.map(stat => { return ( -1} onChange={onStatToggle(stat)} key={stat} /> ); })}
Decimals
{ onChange({ ...options, decimals: parseInt(event.target.value, 10), }); }} />

Hidden series

{/* */}
); };