times.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. function Times({lastSeen, firstSeen}: Props) {
  16. return (
  17. <Container>
  18. <FlexWrapper>
  19. {lastSeen && (
  20. <Fragment>
  21. <StyledIconClock legacySize="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. }
  35. const Container = styled('div')`
  36. flex-shrink: 1;
  37. min-width: 0; /* flex-hack for overflow-ellipsised children */
  38. `;
  39. const FlexWrapper = styled('div')`
  40. ${p => p.theme.overflowEllipsis}
  41. /* The following aligns the icon with the text, fixes bug in Firefox */
  42. display: flex;
  43. align-items: center;
  44. `;
  45. const StyledIconClock = styled(IconClock)`
  46. /* this is solely for optics, since TimeSince always begins
  47. with a number, and numbers do not have descenders */
  48. margin-right: ${space(0.5)};
  49. `;
  50. export default Times;