overviewRow.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import pick from 'lodash/pick';
  4. import type {TimeWindowConfig} from 'sentry/components/checkInTimeline/types';
  5. import ActorBadge from 'sentry/components/idBadge/actorBadge';
  6. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  7. import Link from 'sentry/components/links/link';
  8. import {IconTimer, IconUser} from 'sentry/icons';
  9. import {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import getDuration from 'sentry/utils/duration/getDuration';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import useProjectFromSlug from 'sentry/utils/useProjectFromSlug';
  15. import type {UptimeAlert} from 'sentry/views/alerts/types';
  16. interface Props {
  17. timeWindowConfig: TimeWindowConfig;
  18. uptimeAlert: UptimeAlert;
  19. }
  20. export function OverviewRow({uptimeAlert}: Props) {
  21. const organization = useOrganization();
  22. const project = useProjectFromSlug({
  23. organization,
  24. projectSlug: uptimeAlert.projectSlug,
  25. });
  26. const location = useLocation();
  27. const query = pick(location.query, ['start', 'end', 'statsPeriod', 'environment']);
  28. return (
  29. <TimelineRow key={uptimeAlert.id}>
  30. <DetailsArea>
  31. <DetailsLink
  32. to={{
  33. pathname: `/organizations/${organization.slug}/alerts/rules/uptime/${uptimeAlert.projectSlug}/${uptimeAlert.id}/details/`,
  34. query,
  35. }}
  36. >
  37. <DetailsHeadline>
  38. <Name>{uptimeAlert.name}</Name>
  39. </DetailsHeadline>
  40. <DetailsContainer>
  41. <OwnershipDetails>
  42. {project && <ProjectBadge project={project} avatarSize={12} disableLink />}
  43. {uptimeAlert.owner ? (
  44. <ActorBadge actor={uptimeAlert.owner} avatarSize={12} />
  45. ) : (
  46. <UnassignedLabel>
  47. <IconUser size="xs" />
  48. {t('Unassigned')}
  49. </UnassignedLabel>
  50. )}
  51. </OwnershipDetails>
  52. <ScheduleDetails>
  53. <IconTimer size="xs" />
  54. {t('Checked every %s', getDuration(uptimeAlert.intervalSeconds))}
  55. </ScheduleDetails>
  56. </DetailsContainer>
  57. </DetailsLink>
  58. </DetailsArea>
  59. <TimelineContainer />
  60. </TimelineRow>
  61. );
  62. }
  63. const DetailsLink = styled(Link)`
  64. display: block;
  65. padding: ${space(3)};
  66. color: ${p => p.theme.textColor};
  67. &:focus-visible {
  68. outline: none;
  69. }
  70. `;
  71. const DetailsArea = styled('div')`
  72. border-right: 1px solid ${p => p.theme.border};
  73. border-radius: 0;
  74. position: relative;
  75. `;
  76. const DetailsHeadline = styled('div')`
  77. display: grid;
  78. gap: ${space(1)};
  79. grid-template-columns: 1fr minmax(30px, max-content);
  80. `;
  81. const DetailsContainer = styled('div')`
  82. display: flex;
  83. flex-direction: column;
  84. gap: ${space(0.5)};
  85. `;
  86. const OwnershipDetails = styled('div')`
  87. display: flex;
  88. gap: ${space(0.75)};
  89. align-items: center;
  90. color: ${p => p.theme.subText};
  91. font-size: ${p => p.theme.fontSizeSmall};
  92. `;
  93. const UnassignedLabel = styled('div')`
  94. display: flex;
  95. gap: ${space(0.5)};
  96. align-items: center;
  97. `;
  98. const Name = styled('h3')`
  99. font-size: ${p => p.theme.fontSizeLarge};
  100. word-break: break-word;
  101. margin-bottom: ${space(0.5)};
  102. `;
  103. const ScheduleDetails = styled('small')`
  104. display: flex;
  105. gap: ${space(0.5)};
  106. align-items: center;
  107. color: ${p => p.theme.subText};
  108. font-size: ${p => p.theme.fontSizeSmall};
  109. `;
  110. interface TimelineRowProps {
  111. isDisabled?: boolean;
  112. singleMonitorView?: boolean;
  113. }
  114. const TimelineRow = styled('li')<TimelineRowProps>`
  115. grid-column: 1/-1;
  116. display: grid;
  117. grid-template-columns: subgrid;
  118. ${p =>
  119. !p.singleMonitorView &&
  120. css`
  121. transition: background 50ms ease-in-out;
  122. &:nth-child(odd) {
  123. background: ${p.theme.backgroundSecondary};
  124. }
  125. &:hover {
  126. background: ${p.theme.backgroundTertiary};
  127. }
  128. &:has(*:focus-visible) {
  129. background: ${p.theme.backgroundTertiary};
  130. }
  131. `}
  132. /* Disabled monitors become more opaque */
  133. --disabled-opacity: ${p => (p.isDisabled ? '0.6' : 'unset')};
  134. &:last-child {
  135. border-bottom-left-radius: ${p => p.theme.borderRadius};
  136. border-bottom-right-radius: ${p => p.theme.borderRadius};
  137. }
  138. `;
  139. const TimelineContainer = styled('div')`
  140. display: flex;
  141. padding: ${space(3)} 0;
  142. flex-direction: column;
  143. gap: ${space(4)};
  144. contain: content;
  145. grid-column: 2/-1;
  146. `;