detailsSidebar.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import React 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. <React.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. {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('Thresholds')}</SectionHeading>
  74. <Thresholds>
  75. <MonitorIcon status={MonitorStatus.MISSED_CHECKIN} size={12} />
  76. <Text>
  77. {defined(checkin_margin)
  78. ? tn('Check-ins %s min late', 'Check-ins %s mins late', checkin_margin)
  79. : t('Check-ins that are late')}
  80. </Text>
  81. <MonitorIcon status={MonitorStatus.ERROR} size={12} />
  82. <Text>
  83. {tn(
  84. 'Check-ins longer than %s min or errors',
  85. 'Check-ins longer than %s mins or errors',
  86. max_runtime ?? DEFAULT_MAX_RUNTIME
  87. )}
  88. </Text>
  89. </Thresholds>
  90. <SectionHeading>{t('Cron Details')}</SectionHeading>
  91. <KeyValueTable>
  92. <KeyValueTableRow keyName={t('Monitor Slug')} value={slug} />
  93. {schedule_type === ScheduleType.CRONTAB && (
  94. <KeyValueTableRow keyName={t('Timezone')} value={timezone} />
  95. )}
  96. <KeyValueTableRow
  97. keyName={t('Date created')}
  98. value={getFormattedDate(monitor.dateCreated, 'MMM D, YYYY')}
  99. />
  100. </KeyValueTable>
  101. </React.Fragment>
  102. );
  103. }
  104. const CheckIns = styled('div')`
  105. display: grid;
  106. grid-template-columns: 1fr 1fr;
  107. margin-bottom: ${space(2)};
  108. `;
  109. const Schedule = styled('div')`
  110. margin-bottom: ${space(2)};
  111. display: flex;
  112. flex-wrap: wrap;
  113. gap: ${space(1)};
  114. `;
  115. const CrontabText = styled(Text)`
  116. font-family: ${p => p.theme.text.familyMono};
  117. color: ${p => p.theme.subText};
  118. `;
  119. const Thresholds = styled('div')`
  120. display: grid;
  121. grid-template-columns: max-content 1fr;
  122. margin-bottom: ${space(2)};
  123. align-items: center;
  124. gap: ${space(1)};
  125. `;
  126. const MonitorSlug = styled('button')`
  127. display: grid;
  128. grid-template-columns: 1fr max-content;
  129. align-items: center;
  130. gap: ${space(0.5)};
  131. background: transparent;
  132. border: none;
  133. &:hover {
  134. color: ${p => p.theme.textColor};
  135. }
  136. `;
  137. const SlugText = styled(Text)`
  138. white-space: nowrap;
  139. overflow: hidden;
  140. text-overflow: ellipsis;
  141. `;