detailsSidebar.tsx 4.5 KB

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