resolutionSelector.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {TimeWindow} from 'sentry/components/checkInTimeline/types';
  4. import {SegmentedControl} from 'sentry/components/segmentedControl';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import {useNavigate} from 'sentry/utils/useNavigate';
  9. interface Props {
  10. className?: string;
  11. }
  12. export function ResolutionSelector({className}: Props) {
  13. const location = useLocation();
  14. const navigate = useNavigate();
  15. const handleResolutionChange = useCallback(
  16. (value: TimeWindow) =>
  17. navigate(
  18. {...location, query: {...location.query, timeWindow: value}},
  19. {replace: true}
  20. ),
  21. [location, navigate]
  22. );
  23. const timeWindow = (location.query?.timeWindow as TimeWindow) ?? '24h';
  24. return (
  25. <ListFilters className={className}>
  26. <SegmentedControl<TimeWindow>
  27. value={timeWindow}
  28. onChange={handleResolutionChange}
  29. size="xs"
  30. aria-label={t('Time Scale')}
  31. >
  32. <SegmentedControl.Item key="1h">{t('Hour')}</SegmentedControl.Item>
  33. <SegmentedControl.Item key="24h">{t('Day')}</SegmentedControl.Item>
  34. <SegmentedControl.Item key="7d">{t('Week')}</SegmentedControl.Item>
  35. <SegmentedControl.Item key="30d">{t('Month')}</SegmentedControl.Item>
  36. </SegmentedControl>
  37. </ListFilters>
  38. );
  39. }
  40. const ListFilters = styled('div')`
  41. display: flex;
  42. gap: ${space(1)};
  43. `;