detailsSidebar.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import ActorAvatar from 'sentry/components/avatar/actorAvatar';
  4. import {SectionHeading} from 'sentry/components/charts/styles';
  5. import {KeyValueTable, KeyValueTableRow} from 'sentry/components/keyValueTable';
  6. import QuestionTooltip from 'sentry/components/questionTooltip';
  7. import Text from 'sentry/components/text';
  8. import TimeSince from 'sentry/components/timeSince';
  9. import {Tooltip} from 'sentry/components/tooltip';
  10. import {IconCopy} from 'sentry/icons';
  11. import {t, tn} from 'sentry/locale';
  12. import {space} from 'sentry/styles/space';
  13. import {getFormattedDate} from 'sentry/utils/dates';
  14. import useCopyToClipboard from 'sentry/utils/useCopyToClipboard';
  15. import {
  16. DEFAULT_CHECKIN_MARGIN,
  17. DEFAULT_MAX_RUNTIME,
  18. } from 'sentry/views/monitors/components/monitorForm';
  19. import {MonitorIndicator} from 'sentry/views/monitors/components/monitorIndicator';
  20. import type {Monitor, MonitorEnvironment} from 'sentry/views/monitors/types';
  21. import {CheckInStatus, ScheduleType} from 'sentry/views/monitors/types';
  22. import {scheduleAsText} from 'sentry/views/monitors/utils/scheduleAsText';
  23. interface Props {
  24. monitor: Monitor;
  25. monitorEnv?: MonitorEnvironment;
  26. /**
  27. * Include the UNKNOWN status in the check-in type legend
  28. */
  29. showUnknownLegend?: boolean;
  30. }
  31. export default function DetailsSidebar({monitorEnv, monitor, showUnknownLegend}: Props) {
  32. const {checkin_margin, schedule, schedule_type, max_runtime, timezone} = monitor.config;
  33. const {onClick, label} = useCopyToClipboard({text: monitor.slug});
  34. const slug = (
  35. <Tooltip title={label}>
  36. <MonitorSlug onClick={onClick}>
  37. <SlugText>{monitor.slug}</SlugText>
  38. <IconCopy size="xs" />
  39. </MonitorSlug>
  40. </Tooltip>
  41. );
  42. return (
  43. <Fragment>
  44. <CheckIns>
  45. <SectionHeading>{t('Last Check-In')}</SectionHeading>
  46. <SectionHeading>{t('Next Check-In')}</SectionHeading>
  47. <div>
  48. {monitorEnv?.lastCheckIn ? (
  49. <TimeSince
  50. unitStyle="regular"
  51. liveUpdateInterval="second"
  52. date={monitorEnv.lastCheckIn}
  53. />
  54. ) : (
  55. '-'
  56. )}
  57. </div>
  58. <div>
  59. {monitor.status !== 'disabled' && monitorEnv?.nextCheckIn ? (
  60. <TimeSince
  61. unitStyle="regular"
  62. liveUpdateInterval="second"
  63. date={monitorEnv.nextCheckIn}
  64. />
  65. ) : (
  66. '-'
  67. )}
  68. </div>
  69. </CheckIns>
  70. <SectionHeading>{t('Schedule')}</SectionHeading>
  71. <Schedule>
  72. <Text>
  73. {scheduleAsText(monitor.config)}{' '}
  74. {schedule_type === ScheduleType.CRONTAB && `(${timezone})`}
  75. </Text>
  76. {schedule_type === ScheduleType.CRONTAB && (
  77. <CrontabText>({schedule})</CrontabText>
  78. )}
  79. </Schedule>
  80. <SectionHeading>{t('Legend')}</SectionHeading>
  81. <CheckInLegend>
  82. <CheckInLegendItem>
  83. <MonitorIndicator status={CheckInStatus.MISSED} size={12} />
  84. <Text>
  85. {tn(
  86. 'Check-in missed after %s min',
  87. 'Check-in missed after %s mins',
  88. checkin_margin ?? DEFAULT_CHECKIN_MARGIN
  89. )}
  90. </Text>
  91. </CheckInLegendItem>
  92. <CheckInLegendItem>
  93. <MonitorIndicator status={CheckInStatus.ERROR} size={12} />
  94. <Text>{t('Check-in reported as failed')}</Text>
  95. </CheckInLegendItem>
  96. <CheckInLegendItem>
  97. <MonitorIndicator status={CheckInStatus.TIMEOUT} size={12} />
  98. <Text>
  99. {tn(
  100. 'Check-in timed out after %s min',
  101. 'Check-in timed out after %s mins',
  102. max_runtime ?? DEFAULT_MAX_RUNTIME
  103. )}
  104. </Text>
  105. </CheckInLegendItem>
  106. {showUnknownLegend && (
  107. <CheckInLegendItem>
  108. <MonitorIndicator status={CheckInStatus.UNKNOWN} size={12} />
  109. <UnknownText>
  110. {t('Unknown Status')}
  111. <QuestionTooltip
  112. size="sm"
  113. title={t('Sentry was unable to determine the check-in status.')}
  114. />
  115. </UnknownText>
  116. </CheckInLegendItem>
  117. )}
  118. </CheckInLegend>
  119. <SectionHeading>{t('Cron Details')}</SectionHeading>
  120. <KeyValueTable>
  121. <KeyValueTableRow keyName={t('Monitor Slug')} value={slug} />
  122. <KeyValueTableRow
  123. keyName={t('Owner')}
  124. value={
  125. monitor.owner ? (
  126. <ActorAvatar size={24} actor={monitor.owner} />
  127. ) : (
  128. t('Unassigned')
  129. )
  130. }
  131. />
  132. <KeyValueTableRow
  133. keyName={t('Date created')}
  134. value={getFormattedDate(monitor.dateCreated, 'MMM D, YYYY')}
  135. />
  136. </KeyValueTable>
  137. </Fragment>
  138. );
  139. }
  140. const CheckIns = styled('div')`
  141. display: grid;
  142. grid-template-columns: 1fr 1fr;
  143. margin-bottom: ${space(2)};
  144. `;
  145. const Schedule = styled('div')`
  146. margin-bottom: ${space(2)};
  147. display: flex;
  148. flex-wrap: wrap;
  149. gap: ${space(1)};
  150. `;
  151. const CrontabText = styled(Text)`
  152. font-family: ${p => p.theme.text.familyMono};
  153. color: ${p => p.theme.subText};
  154. `;
  155. const CheckInLegend = styled('ul')`
  156. display: grid;
  157. grid-template-columns: max-content 1fr;
  158. margin-bottom: ${space(2)};
  159. padding: 0;
  160. gap: ${space(1)};
  161. `;
  162. const CheckInLegendItem = styled('li')`
  163. display: grid;
  164. grid-template-columns: subgrid;
  165. align-items: center;
  166. grid-column: 1 / -1;
  167. `;
  168. const UnknownText = styled(Text)`
  169. display: flex;
  170. gap: ${space(1)};
  171. align-items: center;
  172. `;
  173. const MonitorSlug = styled('button')`
  174. display: grid;
  175. grid-template-columns: 1fr max-content;
  176. align-items: center;
  177. gap: ${space(0.5)};
  178. background: transparent;
  179. border: none;
  180. &:hover {
  181. color: ${p => p.theme.textColor};
  182. }
  183. `;
  184. const SlugText = styled(Text)`
  185. white-space: nowrap;
  186. overflow: hidden;
  187. text-overflow: ellipsis;
  188. `;