platformSelector.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {PlatformIcon} from 'platformicons';
  2. import {Flex} from 'sentry/components/container/flex';
  3. import {SegmentedControl} from 'sentry/components/segmentedControl';
  4. import {t} from 'sentry/locale';
  5. import {browserHistory} from 'sentry/utils/browserHistory';
  6. import localStorage from 'sentry/utils/localStorage';
  7. import {decodeScalar} from 'sentry/utils/queryString';
  8. import {useLocation} from 'sentry/utils/useLocation';
  9. import {
  10. DEFAULT_PLATFORM,
  11. PLATFORM_LOCAL_STORAGE_KEY,
  12. PLATFORM_QUERY_PARAM,
  13. } from 'sentry/views/insights/mobile/common/queries/useCrossPlatformProject';
  14. import {MobileCursors} from 'sentry/views/insights/mobile/screenload/constants';
  15. export function PlatformSelector() {
  16. const {query, pathname} = useLocation();
  17. const platform =
  18. decodeScalar(query[PLATFORM_QUERY_PARAM]) ??
  19. localStorage.getItem(PLATFORM_LOCAL_STORAGE_KEY) ??
  20. DEFAULT_PLATFORM;
  21. return (
  22. <Flex>
  23. <SegmentedControl
  24. size="md"
  25. value={platform}
  26. aria-label={t('Filter platform')}
  27. onChange={val => {
  28. localStorage.setItem(PLATFORM_LOCAL_STORAGE_KEY, val);
  29. browserHistory.push({
  30. pathname,
  31. query: {
  32. ...query,
  33. [MobileCursors.SCREENS_TABLE]: undefined,
  34. [PLATFORM_QUERY_PARAM]: val,
  35. },
  36. });
  37. }}
  38. >
  39. <SegmentedControl.Item
  40. key="Android"
  41. aria-label={t('Android')}
  42. icon={<PlatformIcon format="lg" size={28} platform="android" />}
  43. />
  44. <SegmentedControl.Item
  45. key="iOS"
  46. aria-label={t('iOS')}
  47. icon={
  48. <PlatformIcon format="lg" size={28} platform="apple" aria-label={t('iOS')} />
  49. }
  50. />
  51. </SegmentedControl>
  52. </Flex>
  53. );
  54. }