detailsSidebar.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import {SectionHeading} from 'sentry/components/charts/styles';
  4. import Clipboard from 'sentry/components/clipboard';
  5. import {KeyValueTable, KeyValueTableRow} from 'sentry/components/keyValueTable';
  6. import Text from 'sentry/components/text';
  7. import TimeSince from 'sentry/components/timeSince';
  8. import {IconCopy} from 'sentry/icons';
  9. import {t, tn} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import {defined} from 'sentry/utils';
  12. import {getFormattedDate} from 'sentry/utils/dates';
  13. import {DEFAULT_MAX_RUNTIME} from 'sentry/views/monitors/components/monitorForm';
  14. import MonitorIcon from 'sentry/views/monitors/components/monitorIcon';
  15. import {
  16. Monitor,
  17. MonitorEnvironment,
  18. MonitorStatus,
  19. ScheduleType,
  20. } from 'sentry/views/monitors/types';
  21. import {scheduleAsText} from 'sentry/views/monitors/utils';
  22. interface Props {
  23. monitor: Monitor;
  24. monitorEnv?: MonitorEnvironment;
  25. }
  26. export default function DetailsSidebar({monitorEnv, monitor}: Props) {
  27. const {checkin_margin, schedule, schedule_type, max_runtime, timezone} = monitor.config;
  28. const slug = (
  29. <Clipboard value={monitor.slug}>
  30. <MonitorSlug>
  31. <SlugText>{monitor.slug}</SlugText>
  32. <IconCopy size="xs" />
  33. </MonitorSlug>
  34. </Clipboard>
  35. );
  36. return (
  37. <React.Fragment>
  38. <CheckIns>
  39. <SectionHeading>{t('Last Check-In')}</SectionHeading>
  40. <SectionHeading>{t('Next Check-In')}</SectionHeading>
  41. <div>
  42. {monitorEnv?.lastCheckIn ? (
  43. <TimeSince
  44. unitStyle="regular"
  45. liveUpdateInterval="second"
  46. date={monitorEnv.lastCheckIn}
  47. />
  48. ) : (
  49. '-'
  50. )}
  51. </div>
  52. <div>
  53. {monitorEnv?.nextCheckIn ? (
  54. <TimeSince
  55. unitStyle="regular"
  56. liveUpdateInterval="second"
  57. date={monitorEnv.nextCheckIn}
  58. />
  59. ) : (
  60. '-'
  61. )}
  62. </div>
  63. </CheckIns>
  64. <SectionHeading>{t('Schedule')}</SectionHeading>
  65. <Schedule>
  66. <Text>{scheduleAsText(monitor.config)}</Text>
  67. {schedule_type === ScheduleType.CRONTAB && (
  68. <CrontabText>({schedule})</CrontabText>
  69. )}
  70. </Schedule>
  71. <SectionHeading>{t('Thresholds')}</SectionHeading>
  72. <Thresholds>
  73. <MonitorIcon status={MonitorStatus.MISSED_CHECKIN} size={12} />
  74. <Text>
  75. {defined(checkin_margin)
  76. ? tn('Check-ins %s min late', 'Check-ins %s mins late', checkin_margin)
  77. : t('Check-ins that are late')}
  78. </Text>
  79. <MonitorIcon status={MonitorStatus.ERROR} size={12} />
  80. <Text>
  81. {tn(
  82. 'Check-ins longer than %s min or errors',
  83. 'Check-ins longer than %s mins or errors',
  84. max_runtime ?? DEFAULT_MAX_RUNTIME
  85. )}
  86. </Text>
  87. </Thresholds>
  88. <SectionHeading>{t('Cron Details')}</SectionHeading>
  89. <KeyValueTable>
  90. <KeyValueTableRow keyName={t('Monitor Slug')} value={slug} />
  91. {schedule_type === ScheduleType.CRONTAB && (
  92. <KeyValueTableRow keyName={t('Timezone')} value={timezone} />
  93. )}
  94. <KeyValueTableRow
  95. keyName={t('Date created')}
  96. value={getFormattedDate(monitor.dateCreated, 'MMM D, YYYY')}
  97. />
  98. </KeyValueTable>
  99. </React.Fragment>
  100. );
  101. }
  102. const CheckIns = styled('div')`
  103. display: grid;
  104. grid-template-columns: 1fr 1fr;
  105. margin-bottom: ${space(2)};
  106. `;
  107. const Schedule = styled('div')`
  108. margin-bottom: ${space(2)};
  109. display: flex;
  110. flex-wrap: wrap;
  111. gap: ${space(1)};
  112. `;
  113. const CrontabText = styled(Text)`
  114. font-family: ${p => p.theme.text.familyMono};
  115. color: ${p => p.theme.subText};
  116. `;
  117. const Thresholds = styled('div')`
  118. display: grid;
  119. grid-template-columns: max-content 1fr;
  120. margin-bottom: ${space(2)};
  121. align-items: center;
  122. gap: ${space(1)};
  123. `;
  124. const MonitorSlug = styled('div')`
  125. display: grid;
  126. grid-template-columns: 1fr max-content;
  127. align-items: center;
  128. gap: ${space(0.5)};
  129. cursor: pointer;
  130. `;
  131. const SlugText = styled(Text)`
  132. white-space: nowrap;
  133. overflow: hidden;
  134. text-overflow: ellipsis;
  135. `;