deviceClassSelector.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import type {ComponentProps} from 'react';
  2. import {CompactSelect} from 'sentry/components/compactSelect';
  3. import {t} from 'sentry/locale';
  4. import {trackAnalytics} from 'sentry/utils/analytics';
  5. import {decodeScalar} from 'sentry/utils/queryString';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import {useNavigate} from 'sentry/utils/useNavigate';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import {MobileCursors} from 'sentry/views/insights/mobile/screenload/constants';
  10. import {ModuleName} from 'sentry/views/insights/types';
  11. interface Props {
  12. clearSpansTableCursor?: boolean;
  13. moduleName?: ModuleName;
  14. size?: ComponentProps<typeof CompactSelect>['size'];
  15. }
  16. export function DeviceClassSelector({
  17. size = 'xs',
  18. clearSpansTableCursor,
  19. moduleName = ModuleName.OTHER,
  20. }: Props) {
  21. const navigate = useNavigate();
  22. const location = useLocation();
  23. const organization = useOrganization();
  24. const value = decodeScalar(location.query['device.class']) ?? '';
  25. const options = [
  26. {value: '', label: t('All')},
  27. {value: 'high', label: t('High')},
  28. {value: 'medium', label: t('Medium')},
  29. {value: 'low', label: t('Low')},
  30. {value: 'Unknown', label: t('Unknown')},
  31. ];
  32. return (
  33. <CompactSelect
  34. size={size}
  35. triggerProps={{prefix: t('Device Class')}}
  36. value={value}
  37. options={options ?? []}
  38. onChange={newValue => {
  39. if (moduleName === ModuleName.APP_START) {
  40. trackAnalytics('insight.app_start.spans.filter_by_device_class', {
  41. organization,
  42. filter: newValue.value,
  43. });
  44. } else if (moduleName === ModuleName.SCREEN_LOAD) {
  45. trackAnalytics('insight.screen_load.spans.filter_by_device_class', {
  46. organization,
  47. filter: newValue.value,
  48. });
  49. }
  50. navigate({
  51. ...location,
  52. query: {
  53. ...location.query,
  54. ['device.class']: newValue.value,
  55. [MobileCursors.RELEASE_1_EVENT_SAMPLE_TABLE]: undefined,
  56. [MobileCursors.RELEASE_2_EVENT_SAMPLE_TABLE]: undefined,
  57. ...(clearSpansTableCursor ? {[MobileCursors.SPANS_TABLE]: undefined} : {}),
  58. },
  59. });
  60. }}
  61. />
  62. );
  63. }