timelineTableRow.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import {useState} from 'react';
  2. import {Link} from 'react-router';
  3. import {css} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import {Button} from 'sentry/components/button';
  6. import {openConfirmModal} from 'sentry/components/confirm';
  7. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  8. import {Tooltip} from 'sentry/components/tooltip';
  9. import {IconEllipsis} from 'sentry/icons';
  10. import {t, tct} from 'sentry/locale';
  11. import {fadeIn} from 'sentry/styles/animations';
  12. import {space} from 'sentry/styles/space';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import {Monitor, MonitorStatus} from 'sentry/views/monitors/types';
  15. import {scheduleAsText} from 'sentry/views/monitors/utils';
  16. import {statusIconColorMap} from 'sentry/views/monitors/utils/constants';
  17. import {CheckInTimeline, CheckInTimelineProps} from './checkInTimeline';
  18. import {TimelinePlaceholder} from './timelinePlaceholder';
  19. import {MonitorBucket} from './types';
  20. interface Props extends Omit<CheckInTimelineProps, 'bucketedData' | 'environment'> {
  21. monitor: Monitor;
  22. bucketedData?: MonitorBucket[];
  23. onDeleteEnvironment?: (env: string) => void;
  24. /**
  25. * Whether only one monitor is being rendered in a larger view with this component
  26. * turns off things like zebra striping, hover effect, and showing monitor name
  27. */
  28. singleMonitorView?: boolean;
  29. }
  30. const MAX_SHOWN_ENVIRONMENTS = 4;
  31. export function TimelineTableRow({
  32. monitor,
  33. bucketedData,
  34. singleMonitorView,
  35. onDeleteEnvironment,
  36. ...timelineProps
  37. }: Props) {
  38. const [isExpanded, setExpanded] = useState(
  39. monitor.environments.length <= MAX_SHOWN_ENVIRONMENTS
  40. );
  41. const environments = isExpanded
  42. ? monitor.environments
  43. : monitor.environments.slice(0, MAX_SHOWN_ENVIRONMENTS);
  44. return (
  45. <TimelineRow key={monitor.id} singleMonitorView={singleMonitorView}>
  46. {!singleMonitorView && <MonitorDetails monitor={monitor} />}
  47. <MonitorEnvContainer>
  48. {environments.map(({name, status}) => {
  49. const envStatus =
  50. monitor.status === MonitorStatus.DISABLED ? MonitorStatus.DISABLED : status;
  51. const {label, icon} = statusIconColorMap[envStatus];
  52. return (
  53. <EnvWithStatus key={name}>
  54. {onDeleteEnvironment && (
  55. <DropdownMenu
  56. size="sm"
  57. trigger={triggerProps => (
  58. <EnvActionButton
  59. {...triggerProps}
  60. aria-label={t('Monitor environment actions')}
  61. size="zero"
  62. icon={<IconEllipsis size="sm" />}
  63. />
  64. )}
  65. items={[
  66. {
  67. label: t('Delete Environment'),
  68. key: 'delete',
  69. onAction: () => {
  70. openConfirmModal({
  71. onConfirm: () => onDeleteEnvironment(name),
  72. header: t('Delete Environment?'),
  73. message: tct(
  74. 'Are you sure you want to permanently delete the "[envName]" environment?',
  75. {envName: name}
  76. ),
  77. confirmText: t('Delete'),
  78. priority: 'danger',
  79. });
  80. },
  81. },
  82. ]}
  83. />
  84. )}
  85. <MonitorEnvLabel status={envStatus}>{name}</MonitorEnvLabel>
  86. <Tooltip title={label} skipWrapper>
  87. {icon}
  88. </Tooltip>
  89. </EnvWithStatus>
  90. );
  91. })}
  92. {!isExpanded && (
  93. <Button size="xs" onClick={() => setExpanded(true)}>
  94. {tct('Show [num] More', {
  95. num: monitor.environments.length - MAX_SHOWN_ENVIRONMENTS,
  96. })}
  97. </Button>
  98. )}
  99. </MonitorEnvContainer>
  100. <TimelineContainer>
  101. {environments.map(({name}) => {
  102. return (
  103. <TimelineEnvOuterContainer key={name}>
  104. {!bucketedData ? (
  105. <TimelinePlaceholder />
  106. ) : (
  107. <TimelineEnvContainer>
  108. <CheckInTimeline
  109. {...timelineProps}
  110. bucketedData={bucketedData}
  111. environment={name}
  112. />
  113. </TimelineEnvContainer>
  114. )}
  115. </TimelineEnvOuterContainer>
  116. );
  117. })}
  118. </TimelineContainer>
  119. </TimelineRow>
  120. );
  121. }
  122. function MonitorDetails({monitor}: {monitor: Monitor}) {
  123. const organization = useOrganization();
  124. const schedule = scheduleAsText(monitor.config);
  125. const monitorDetailUrl = `/organizations/${organization.slug}/crons/${monitor.slug}/`;
  126. return (
  127. <DetailsContainer to={monitorDetailUrl}>
  128. <Name>{monitor.name}</Name>
  129. <Schedule>{schedule}</Schedule>
  130. </DetailsContainer>
  131. );
  132. }
  133. const TimelineRow = styled('div')<{singleMonitorView?: boolean}>`
  134. display: contents;
  135. ${p =>
  136. !p.singleMonitorView &&
  137. css`
  138. &:nth-child(odd) > * {
  139. background: ${p.theme.backgroundSecondary};
  140. }
  141. &:hover > * {
  142. background: ${p.theme.backgroundTertiary};
  143. }
  144. `}
  145. &:last-child > *:first-child {
  146. border-bottom-left-radius: ${p => p.theme.borderRadius};
  147. }
  148. &:last-child > *:last-child {
  149. border-bottom-right-radius: ${p => p.theme.borderRadius};
  150. }
  151. > * {
  152. transition: background 50ms ease-in-out;
  153. }
  154. `;
  155. const DetailsContainer = styled(Link)`
  156. color: ${p => p.theme.textColor};
  157. padding: ${space(3)};
  158. border-right: 1px solid ${p => p.theme.border};
  159. border-radius: 0;
  160. `;
  161. const Name = styled('h3')`
  162. font-size: ${p => p.theme.fontSizeLarge};
  163. margin-bottom: ${space(0.25)};
  164. `;
  165. const Schedule = styled('small')`
  166. color: ${p => p.theme.subText};
  167. font-size: ${p => p.theme.fontSizeSmall};
  168. `;
  169. const MonitorEnvContainer = styled('div')`
  170. display: flex;
  171. padding: ${space(3)} ${space(2)};
  172. gap: ${space(4)};
  173. flex-direction: column;
  174. border-right: 1px solid ${p => p.theme.innerBorder};
  175. text-align: right;
  176. `;
  177. const EnvActionButton = styled(Button)`
  178. padding: ${space(0.5)} ${space(1)};
  179. display: none;
  180. `;
  181. const EnvWithStatus = styled('div')`
  182. display: flex;
  183. gap: ${space(0.5)};
  184. align-items: center;
  185. height: calc(${p => p.theme.fontSizeLarge} * ${p => p.theme.text.lineHeightHeading});
  186. &:hover ${EnvActionButton} {
  187. display: block;
  188. }
  189. `;
  190. const MonitorEnvLabel = styled('div')<{status: MonitorStatus}>`
  191. text-overflow: ellipsis;
  192. overflow: hidden;
  193. white-space: nowrap;
  194. flex: 1;
  195. color: ${p => p.theme[statusIconColorMap[p.status].color]};
  196. `;
  197. const TimelineContainer = styled('div')`
  198. display: flex;
  199. padding: ${space(3)} 0;
  200. flex-direction: column;
  201. gap: ${space(4)};
  202. contain: content;
  203. `;
  204. const TimelineEnvOuterContainer = styled('div')`
  205. position: relative;
  206. height: calc(${p => p.theme.fontSizeLarge} * ${p => p.theme.text.lineHeightHeading});
  207. `;
  208. const TimelineEnvContainer = styled('div')`
  209. position: absolute;
  210. inset: 0;
  211. opacity: 0;
  212. animation: ${fadeIn} 1.5s ease-out forwards;
  213. contain: content;
  214. `;