QueryHeader.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import React, { useCallback } from 'react';
  2. import { SelectableValue } from '@grafana/data';
  3. import { EditorHeader, InlineSelect } from '@grafana/experimental';
  4. import { AzureMonitorQuery, AzureQueryType } from '../types';
  5. interface QueryTypeFieldProps {
  6. query: AzureMonitorQuery;
  7. onQueryChange: (newQuery: AzureMonitorQuery) => void;
  8. }
  9. export const QueryHeader: React.FC<QueryTypeFieldProps> = ({ query, onQueryChange }) => {
  10. const queryTypes: Array<{ value: AzureQueryType; label: string }> = [
  11. { value: AzureQueryType.AzureMonitor, label: 'Metrics' },
  12. { value: AzureQueryType.LogAnalytics, label: 'Logs' },
  13. { value: AzureQueryType.AzureResourceGraph, label: 'Azure Resource Graph' },
  14. ];
  15. const handleChange = useCallback(
  16. (change: SelectableValue<AzureQueryType>) => {
  17. change.value &&
  18. onQueryChange({
  19. ...query,
  20. queryType: change.value,
  21. });
  22. },
  23. [onQueryChange, query]
  24. );
  25. return (
  26. <span data-testid="azure-monitor-experimental-header">
  27. <EditorHeader>
  28. <InlineSelect
  29. label="Service"
  30. value={query.queryType}
  31. placeholder="Service..."
  32. allowCustomValue
  33. options={queryTypes}
  34. onChange={handleChange}
  35. />
  36. </EditorHeader>
  37. </span>
  38. );
  39. };