metricsEventsDropdown.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import Feature from 'sentry/components/acl/feature';
  2. import CompactSelect from 'sentry/components/forms/compactSelect';
  3. import {t} from 'sentry/locale';
  4. import {
  5. AutoSampleState,
  6. MEPState,
  7. MetricsEnhancedSettingContext,
  8. useMEPSettingContext,
  9. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  10. interface MetricsEventsOption {
  11. label: string;
  12. prefix: string;
  13. value: MEPState;
  14. }
  15. const autoTextMap: Record<AutoSampleState, string> = {
  16. [AutoSampleState.unset]: t('Auto'),
  17. [AutoSampleState.metrics]: t('Auto (ingested)'),
  18. [AutoSampleState.transactions]: t('Auto (stored)'),
  19. };
  20. function getOptions(mepContext: MetricsEnhancedSettingContext): MetricsEventsOption[] {
  21. const autoText = autoTextMap[mepContext.autoSampleState];
  22. const prefix = t('Sample');
  23. return [
  24. {
  25. value: MEPState.auto,
  26. prefix,
  27. label: autoText,
  28. },
  29. {
  30. value: MEPState.metricsOnly,
  31. prefix,
  32. label: t('Ingested only'),
  33. },
  34. {
  35. value: MEPState.transactionsOnly,
  36. prefix,
  37. label: t('Stored only'),
  38. },
  39. ];
  40. }
  41. export function MetricsEventsDropdown() {
  42. return (
  43. <Feature features={['performance-use-metrics']}>
  44. <InnerDropdown />
  45. </Feature>
  46. );
  47. }
  48. function InnerDropdown() {
  49. const mepSetting = useMEPSettingContext();
  50. const options = getOptions(mepSetting);
  51. const currentOption =
  52. options.find(({value}) => value === mepSetting.metricSettingState) || options[0];
  53. return (
  54. <CompactSelect
  55. triggerProps={{prefix: currentOption.prefix}}
  56. value={currentOption.value}
  57. options={options}
  58. onChange={opt => mepSetting.setMetricSettingState(opt.value)}
  59. />
  60. );
  61. }