detailsSidebar.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 {MonitorIndicator} from 'sentry/views/monitors/components/monitorIndicator';
  16. import type {Monitor, MonitorEnvironment} from 'sentry/views/monitors/types';
  17. import {ScheduleType} from 'sentry/views/monitors/types';
  18. import {scheduleAsText} from 'sentry/views/monitors/utils';
  19. interface Props {
  20. monitor: Monitor;
  21. monitorEnv?: MonitorEnvironment;
  22. }
  23. export default function DetailsSidebar({monitorEnv, monitor}: Props) {
  24. const {checkin_margin, schedule, schedule_type, max_runtime, timezone} = monitor.config;
  25. const {onClick, label} = useCopyToClipboard({text: monitor.slug});
  26. const slug = (
  27. <Tooltip title={label}>
  28. <MonitorSlug onClick={onClick}>
  29. <SlugText>{monitor.slug}</SlugText>
  30. <IconCopy size="xs" />
  31. </MonitorSlug>
  32. </Tooltip>
  33. );
  34. return (
  35. <Fragment>
  36. <CheckIns>
  37. <SectionHeading>{t('Last Check-In')}</SectionHeading>
  38. <SectionHeading>{t('Next Check-In')}</SectionHeading>
  39. <div>
  40. {monitorEnv?.lastCheckIn ? (
  41. <TimeSince
  42. unitStyle="regular"
  43. liveUpdateInterval="second"
  44. date={monitorEnv.lastCheckIn}
  45. />
  46. ) : (
  47. '-'
  48. )}
  49. </div>
  50. <div>
  51. {monitor.status !== 'disabled' && monitorEnv?.nextCheckIn ? (
  52. <TimeSince
  53. unitStyle="regular"
  54. liveUpdateInterval="second"
  55. date={monitorEnv.nextCheckIn}
  56. />
  57. ) : (
  58. '-'
  59. )}
  60. </div>
  61. </CheckIns>
  62. <SectionHeading>{t('Schedule')}</SectionHeading>
  63. <Schedule>
  64. <Text>{scheduleAsText(monitor.config)}</Text>
  65. {schedule_type === ScheduleType.CRONTAB && (
  66. <CrontabText>({schedule})</CrontabText>
  67. )}
  68. </Schedule>
  69. <SectionHeading>{t('Margins')}</SectionHeading>
  70. <Thresholds>
  71. <MonitorIndicator status="warning" size={12} />
  72. <Text>
  73. {defined(checkin_margin)
  74. ? tn(
  75. 'Check-ins missed after %s min',
  76. 'Check-ins missed after %s mins',
  77. checkin_margin
  78. )
  79. : t('Check-ins that are missed')}
  80. </Text>
  81. <MonitorIndicator status="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. </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. `;