releaseCardStatsPeriod.tsx 1.9 KB

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