eventCreatedTooltip.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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')}
  40. <br />
  41. {dateCreated.format(format)}
  42. </Fragment>
  43. ) : (
  44. <NotApplicableText>{t('n/a')}</NotApplicableText>
  45. )}
  46. </dd>
  47. {dateReceived && (
  48. <Fragment>
  49. <dt>{t('Received')}</dt>
  50. <dd>
  51. {dateReceived.format('ll')}
  52. <br />
  53. {dateReceived.format(format)}
  54. </dd>
  55. <dt>{t('Latency')}</dt>
  56. <dd>
  57. {dateCreated ? (
  58. formatDateDelta(dateCreated, dateReceived)
  59. ) : (
  60. <NotApplicableText>{t('n/a')}</NotApplicableText>
  61. )}
  62. </dd>
  63. </Fragment>
  64. )}
  65. </DescriptionList>
  66. );
  67. }
  68. const DescriptionList = styled('dl')`
  69. display: grid;
  70. grid-template-columns: max-content 1fr;
  71. gap: ${space(0.75)} ${space(1)};
  72. text-align: left;
  73. margin: 0;
  74. `;
  75. const NotApplicableText = styled('span')`
  76. color: ${p => p.theme.subText};
  77. `;