detailsSidebar.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 Text from 'sentry/components/text';
  7. import TimeSince from 'sentry/components/timeSince';
  8. import {Tooltip} from 'sentry/components/tooltip';
  9. import {IconCopy} from 'sentry/icons';
  10. import {t, tn} from 'sentry/locale';
  11. import {space} from 'sentry/styles/space';
  12. import {defined} from 'sentry/utils';
  13. import {getFormattedDate} from 'sentry/utils/dates';
  14. import useCopyToClipboard from 'sentry/utils/useCopyToClipboard';
  15. import {DEFAULT_MAX_RUNTIME} from 'sentry/views/monitors/components/monitorForm';
  16. import {MonitorIndicator} from 'sentry/views/monitors/components/monitorIndicator';
  17. import type {Monitor, MonitorEnvironment} from 'sentry/views/monitors/types';
  18. import {ScheduleType} from 'sentry/views/monitors/types';
  19. import {scheduleAsText} from 'sentry/views/monitors/utils/scheduleAsText';
  20. interface Props {
  21. monitor: Monitor;
  22. monitorEnv?: MonitorEnvironment;
  23. }
  24. export default function DetailsSidebar({monitorEnv, monitor}: Props) {
  25. const {checkin_margin, schedule, schedule_type, max_runtime, timezone} = monitor.config;
  26. const {onClick, label} = useCopyToClipboard({text: monitor.slug});
  27. const slug = (
  28. <Tooltip title={label}>
  29. <MonitorSlug onClick={onClick}>
  30. <SlugText>{monitor.slug}</SlugText>
  31. <IconCopy size="xs" />
  32. </MonitorSlug>
  33. </Tooltip>
  34. );
  35. return (
  36. <Fragment>
  37. <CheckIns>
  38. <SectionHeading>{t('Last Check-In')}</SectionHeading>
  39. <SectionHeading>{t('Next Check-In')}</SectionHeading>
  40. <div>
  41. {monitorEnv?.lastCheckIn ? (
  42. <TimeSince
  43. unitStyle="regular"
  44. liveUpdateInterval="second"
  45. date={monitorEnv.lastCheckIn}
  46. />
  47. ) : (
  48. '-'
  49. )}
  50. </div>
  51. <div>
  52. {monitor.status !== 'disabled' && monitorEnv?.nextCheckIn ? (
  53. <TimeSince
  54. unitStyle="regular"
  55. liveUpdateInterval="second"
  56. date={monitorEnv.nextCheckIn}
  57. />
  58. ) : (
  59. '-'
  60. )}
  61. </div>
  62. </CheckIns>
  63. <SectionHeading>{t('Schedule')}</SectionHeading>
  64. <Schedule>
  65. <Text>{scheduleAsText(monitor.config)}</Text>
  66. {schedule_type === ScheduleType.CRONTAB && (
  67. <CrontabText>({schedule})</CrontabText>
  68. )}
  69. </Schedule>
  70. <SectionHeading>{t('Margins')}</SectionHeading>
  71. <Thresholds>
  72. <MonitorIndicator status="warning" size={12} />
  73. <Text>
  74. {defined(checkin_margin)
  75. ? tn(
  76. 'Check-ins missed after %s min',
  77. 'Check-ins missed after %s mins',
  78. checkin_margin
  79. )
  80. : t('Check-ins that are missed')}
  81. </Text>
  82. <MonitorIndicator status="error" size={12} />
  83. <Text>
  84. {tn(
  85. 'Check-ins longer than %s min or errors',
  86. 'Check-ins longer than %s mins or errors',
  87. max_runtime ?? DEFAULT_MAX_RUNTIME
  88. )}
  89. </Text>
  90. </Thresholds>
  91. <SectionHeading>{t('Cron Details')}</SectionHeading>
  92. <KeyValueTable>
  93. <KeyValueTableRow keyName={t('Monitor Slug')} value={slug} />
  94. {schedule_type === ScheduleType.CRONTAB && (
  95. <KeyValueTableRow keyName={t('Timezone')} value={timezone} />
  96. )}
  97. <KeyValueTableRow
  98. keyName={t('Owner')}
  99. value={
  100. monitor.owner ? (
  101. <ActorAvatar size={24} actor={monitor.owner} />
  102. ) : (
  103. t('Unassigned')
  104. )
  105. }
  106. />
  107. <KeyValueTableRow
  108. keyName={t('Date created')}
  109. value={getFormattedDate(monitor.dateCreated, 'MMM D, YYYY')}
  110. />
  111. </KeyValueTable>
  112. </Fragment>
  113. );
  114. }
  115. const CheckIns = styled('div')`
  116. display: grid;
  117. grid-template-columns: 1fr 1fr;
  118. margin-bottom: ${space(2)};
  119. `;
  120. const Schedule = styled('div')`
  121. margin-bottom: ${space(2)};
  122. display: flex;
  123. flex-wrap: wrap;
  124. gap: ${space(1)};
  125. `;
  126. const CrontabText = styled(Text)`
  127. font-family: ${p => p.theme.text.familyMono};
  128. color: ${p => p.theme.subText};
  129. `;
  130. const Thresholds = styled('div')`
  131. display: grid;
  132. grid-template-columns: max-content 1fr;
  133. margin-bottom: ${space(2)};
  134. align-items: center;
  135. gap: ${space(1)};
  136. `;
  137. const MonitorSlug = styled('button')`
  138. display: grid;
  139. grid-template-columns: 1fr max-content;
  140. align-items: center;
  141. gap: ${space(0.5)};
  142. background: transparent;
  143. border: none;
  144. &:hover {
  145. color: ${p => p.theme.textColor};
  146. }
  147. `;
  148. const SlugText = styled(Text)`
  149. white-space: nowrap;
  150. overflow: hidden;
  151. text-overflow: ellipsis;
  152. `;