detailsSidebar.tsx 6.2 KB

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