times.tsx 1.4 KB

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