releaseCardStatsPeriod.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import styled from '@emotion/styled';
  2. import {Location} from 'history';
  3. import Link from 'sentry/components/links/link';
  4. import {t} from 'sentry/locale';
  5. import {space} from 'sentry/styles/space';
  6. import {HealthStatsPeriodOption, PageFilters} from 'sentry/types';
  7. import withPageFilters from 'sentry/utils/withPageFilters';
  8. type Props = {
  9. location: Location;
  10. selection: PageFilters;
  11. };
  12. function ReleaseCardStatsPeriod({location, selection}: Props) {
  13. const activePeriod =
  14. location.query.healthStatsPeriod || HealthStatsPeriodOption.TWENTY_FOUR_HOURS;
  15. const {pathname, query} = location;
  16. return (
  17. <Wrapper>
  18. {selection.datetime.period !== HealthStatsPeriodOption.TWENTY_FOUR_HOURS && (
  19. <Period
  20. to={{
  21. pathname,
  22. query: {
  23. ...query,
  24. healthStatsPeriod: HealthStatsPeriodOption.TWENTY_FOUR_HOURS,
  25. },
  26. }}
  27. selected={activePeriod === HealthStatsPeriodOption.TWENTY_FOUR_HOURS}
  28. >
  29. {t('24h')}
  30. </Period>
  31. )}
  32. <Period
  33. to={{
  34. pathname,
  35. query: {...query, healthStatsPeriod: HealthStatsPeriodOption.AUTO},
  36. }}
  37. selected={activePeriod === HealthStatsPeriodOption.AUTO}
  38. >
  39. {selection.datetime.start ? t('Custom') : selection.datetime.period ?? t('14d')}
  40. </Period>
  41. </Wrapper>
  42. );
  43. }
  44. const Wrapper = styled('div')`
  45. display: grid;
  46. grid-auto-flow: column;
  47. grid-column-gap: ${space(0.75)};
  48. flex: 1;
  49. justify-content: flex-end;
  50. text-align: right;
  51. margin-left: ${space(0.5)};
  52. `;
  53. const Period = styled(Link)<{selected: boolean}>`
  54. color: ${p => (p.selected ? p.theme.gray400 : p.theme.gray300)};
  55. &:hover,
  56. &:focus {
  57. color: ${p => (p.selected ? p.theme.gray400 : p.theme.gray300)};
  58. }
  59. `;
  60. export default withPageFilters(ReleaseCardStatsPeriod);