times.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import TimeSince from 'sentry/components/timeSince';
  4. import {IconClock} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import overflowEllipsis from 'sentry/styles/overflowEllipsis';
  7. import space from 'sentry/styles/space';
  8. /**
  9. * Renders the first & last seen times for a group or event with
  10. * a clock icon.
  11. */
  12. type Props = {
  13. lastSeen: string;
  14. firstSeen: string;
  15. };
  16. const Times = ({lastSeen, firstSeen}: Props) => (
  17. <Container>
  18. <FlexWrapper>
  19. {lastSeen && (
  20. <Fragment>
  21. <StyledIconClock size="11px" />
  22. <TimeSince date={lastSeen} suffix={t('ago')} />
  23. </Fragment>
  24. )}
  25. {firstSeen && lastSeen && (
  26. <span className="hidden-xs hidden-sm">&nbsp;—&nbsp;</span>
  27. )}
  28. {firstSeen && (
  29. <TimeSince date={firstSeen} suffix={t('old')} className="hidden-xs hidden-sm" />
  30. )}
  31. </FlexWrapper>
  32. </Container>
  33. );
  34. const Container = styled('div')`
  35. flex-shrink: 1;
  36. min-width: 0; /* flex-hack for overflow-ellipsised children */
  37. `;
  38. const FlexWrapper = styled('div')`
  39. ${overflowEllipsis}
  40. /* The following aligns the icon with the text, fixes bug in Firefox */
  41. display: flex;
  42. align-items: center;
  43. `;
  44. const StyledIconClock = styled(IconClock)`
  45. /* this is solely for optics, since TimeSince always begins
  46. with a number, and numbers do not have descenders */
  47. margin-right: ${space(0.5)};
  48. `;
  49. export default Times;