grafana/k6-cloud-grafana-datasource

View on GitHub
src/components/QueryEditor/MetricSelect.tsx

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
import React, { FC, useMemo } from 'react';
import { SelectableValue } from '@grafana/data';
import { FieldSelect } from './FieldSelect';

interface MetricSelectProps {
  metrics: string[];
  value?: string;
  onChange: (value: SelectableValue<string>) => void;
  width?: number;
}

export const MetricSelect: FC<MetricSelectProps> = ({ metrics = [], value = '', onChange, width = 4 }) => {
  const options = useMemo(
    () =>
      metrics.map((item) => ({
        label: item,
        value: item,
      })),
    [metrics]
  );

  return <FieldSelect label="Metric" options={options} value={value} onChange={onChange} width={width} />;
};