deviceClassSelector.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 {browserHistory} from 'sentry/utils/browserHistory';
  6. import {decodeScalar} from 'sentry/utils/queryString';
  7. import {useLocation} from 'sentry/utils/useLocation';
  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 location = useLocation();
  22. const organization = useOrganization();
  23. const value = decodeScalar(location.query['device.class']) ?? '';
  24. const options = [
  25. {value: '', label: t('All')},
  26. {value: 'high', label: t('High')},
  27. {value: 'medium', label: t('Medium')},
  28. {value: 'low', label: t('Low')},
  29. {value: 'Unknown', label: t('Unknown')},
  30. ];
  31. return (
  32. <CompactSelect
  33. size={size}
  34. triggerProps={{prefix: t('Device Class')}}
  35. value={value}
  36. options={options ?? []}
  37. onChange={newValue => {
  38. if (moduleName === ModuleName.APP_START) {
  39. trackAnalytics('insight.app_start.spans.filter_by_device_class', {
  40. organization,
  41. filter: newValue.value,
  42. });
  43. } else if (moduleName === ModuleName.SCREEN_LOAD) {
  44. trackAnalytics('insight.screen_load.spans.filter_by_device_class', {
  45. organization,
  46. filter: newValue.value,
  47. });
  48. }
  49. browserHistory.push({
  50. ...location,
  51. query: {
  52. ...location.query,
  53. ['device.class']: newValue.value,
  54. [MobileCursors.RELEASE_1_EVENT_SAMPLE_TABLE]: undefined,
  55. [MobileCursors.RELEASE_2_EVENT_SAMPLE_TABLE]: undefined,
  56. ...(clearSpansTableCursor ? {[MobileCursors.SPANS_TABLE]: undefined} : {}),
  57. },
  58. });
  59. }}
  60. />
  61. );
  62. }