detailsSidebar.tsx 5.0 KB

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