import React, { FunctionComponent } from 'react'; import { SelectableStrings } from '../types'; import { SelectableValue } from '@grafana/data'; import { Segment } from '@grafana/ui'; export interface Props { values: string[]; onChange: (values: string[]) => void; variableOptionGroup: SelectableValue; stats: SelectableStrings; } const removeText = '-- remove stat --'; const removeOption: SelectableValue = { label: removeText, value: removeText }; export const Stats: FunctionComponent = ({ stats, values, onChange, variableOptionGroup }) => ( <> {values && values.map((value, index) => ( onChange( value === removeText ? values.filter((_, i) => i !== index) : values.map((v, i) => (i === index ? value : v)) ) } /> ))} {values.length !== stats.length && ( } allowCustomValue onChange={({ value }) => onChange([...values, value])} options={[...stats.filter(({ value }) => !values.includes(value)), variableOptionGroup]} /> )} );