ExemplarsSettings.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { selectors } from '@grafana/e2e-selectors';
  4. import { Button } from '@grafana/ui';
  5. import { ExemplarTraceIdDestination } from '../types';
  6. import ExemplarSetting from './ExemplarSetting';
  7. type Props = {
  8. options?: ExemplarTraceIdDestination[];
  9. onChange: (value: ExemplarTraceIdDestination[]) => void;
  10. };
  11. export function ExemplarsSettings({ options, onChange }: Props) {
  12. return (
  13. <>
  14. <h3 className="page-heading">Exemplars</h3>
  15. {options &&
  16. options.map((option, index) => {
  17. return (
  18. <ExemplarSetting
  19. key={index}
  20. value={option}
  21. onChange={(newField) => {
  22. const newOptions = [...options];
  23. newOptions.splice(index, 1, newField);
  24. onChange(newOptions);
  25. }}
  26. onDelete={() => {
  27. const newOptions = [...options];
  28. newOptions.splice(index, 1);
  29. onChange(newOptions);
  30. }}
  31. />
  32. );
  33. })}
  34. <Button
  35. variant="secondary"
  36. aria-label={selectors.components.DataSource.Prometheus.configPage.exemplarsAddButton}
  37. className={css`
  38. margin-bottom: 10px;
  39. `}
  40. icon="plus"
  41. onClick={(event) => {
  42. event.preventDefault();
  43. const newOptions = [...(options || []), { name: 'traceID' }];
  44. onChange(newOptions);
  45. }}
  46. >
  47. Add
  48. </Button>
  49. </>
  50. );
  51. }