eventCreatedTooltip.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import moment from 'moment-timezone';
  4. import {t} from 'sentry/locale';
  5. import ConfigStore from 'sentry/stores/configStore';
  6. import {space} from 'sentry/styles/space';
  7. import {Event} from 'sentry/types/event';
  8. const formatDateDelta = (reference: moment.Moment, observed: moment.Moment) => {
  9. const duration = moment.duration(Math.abs(+observed - +reference));
  10. const hours = Math.floor(+duration / (60 * 60 * 1000));
  11. const minutes = duration.minutes();
  12. const results: string[] = [];
  13. if (hours) {
  14. results.push(`${hours} hour${hours !== 1 ? 's' : ''}`);
  15. }
  16. if (minutes) {
  17. results.push(`${minutes} minute${minutes !== 1 ? 's' : ''}`);
  18. }
  19. if (results.length === 0) {
  20. results.push('a few seconds');
  21. }
  22. return results.join(', ');
  23. };
  24. type Props = {
  25. event: Event;
  26. };
  27. export default function EventCreatedTooltip({event}: Props) {
  28. const user = ConfigStore.get('user');
  29. const options = user?.options ?? {};
  30. const format = options.clock24Hours ? 'HH:mm:ss z' : 'LTS z';
  31. const dateCreated = event.dateCreated ? moment(event.dateCreated) : null;
  32. const dateReceived = event.dateReceived ? moment(event.dateReceived) : null;
  33. return (
  34. <DescriptionList>
  35. <dt>{t('Occurred')}</dt>
  36. <dd>
  37. {dateCreated ? (
  38. <Fragment>
  39. {dateCreated.format('ll')} {dateCreated.format(format)}
  40. </Fragment>
  41. ) : (
  42. <NotApplicableText>{t('n/a')}</NotApplicableText>
  43. )}
  44. </dd>
  45. {dateReceived && (
  46. <Fragment>
  47. <dt>{t('Received')}</dt>
  48. <dd>
  49. {dateReceived.format('ll')} {dateReceived.format(format)}
  50. </dd>
  51. <dt>{t('Latency')}</dt>
  52. <dd>
  53. {dateCreated ? (
  54. formatDateDelta(dateCreated, dateReceived)
  55. ) : (
  56. <NotApplicableText>{t('n/a')}</NotApplicableText>
  57. )}
  58. </dd>
  59. </Fragment>
  60. )}
  61. </DescriptionList>
  62. );
  63. }
  64. const DescriptionList = styled('dl')`
  65. display: grid;
  66. grid-template-columns: max-content 1fr;
  67. gap: ${space(0.75)} ${space(1)};
  68. text-align: left;
  69. margin: 0;
  70. `;
  71. const NotApplicableText = styled('span')`
  72. color: ${p => p.theme.subText};
  73. `;