deviceClassSelector.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import type {ComponentProps} from 'react';
  2. import {CompactSelect} from 'sentry/components/compactSelect';
  3. import {t} from 'sentry/locale';
  4. import {browserHistory} from 'sentry/utils/browserHistory';
  5. import {decodeScalar} from 'sentry/utils/queryString';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import {MobileCursors} from 'sentry/views/performance/mobile/screenload/screens/constants';
  8. interface Props {
  9. clearSpansTableCursor?: boolean;
  10. size?: ComponentProps<typeof CompactSelect>['size'];
  11. }
  12. export function DeviceClassSelector({size = 'xs', clearSpansTableCursor}: Props) {
  13. const location = useLocation();
  14. const value = decodeScalar(location.query['device.class']) ?? '';
  15. const options = [
  16. {value: '', label: t('All')},
  17. {value: 'high', label: t('High')},
  18. {value: 'medium', label: t('Medium')},
  19. {value: 'low', label: t('Low')},
  20. {value: 'Unknown', label: t('Unknown')},
  21. ];
  22. return (
  23. <CompactSelect
  24. size={size}
  25. triggerProps={{prefix: t('Device Class')}}
  26. value={value}
  27. options={options ?? []}
  28. onChange={newValue => {
  29. browserHistory.push({
  30. ...location,
  31. query: {
  32. ...location.query,
  33. ['device.class']: newValue.value,
  34. [MobileCursors.RELEASE_1_EVENT_SAMPLE_TABLE]: undefined,
  35. [MobileCursors.RELEASE_2_EVENT_SAMPLE_TABLE]: undefined,
  36. ...(clearSpansTableCursor ? {[MobileCursors.SPANS_TABLE]: undefined} : {}),
  37. },
  38. });
  39. }}
  40. />
  41. );
  42. }