metricsEventsDropdown.tsx 1.8 KB

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