timelineTableRow.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {useState} from 'react';
  2. import {Link} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Button} from 'sentry/components/button';
  5. import Placeholder from 'sentry/components/placeholder';
  6. import {tct} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import {Monitor} from 'sentry/views/monitors/types';
  10. import {scheduleAsText} from 'sentry/views/monitors/utils';
  11. import {statusIconMap} from 'sentry/views/monitors/utils/constants';
  12. import {CheckInTimeline, CheckInTimelineProps} from './checkInTimeline';
  13. import {MonitorBucket} from './types';
  14. interface Props extends Omit<CheckInTimelineProps, 'bucketedData' | 'environment'> {
  15. monitor: Monitor;
  16. bucketedData?: MonitorBucket[];
  17. }
  18. const MAX_SHOWN_ENVIRONMENTS = 4;
  19. export function TimelineTableRow({monitor, bucketedData, ...timelineProps}: Props) {
  20. const [isExpanded, setExpanded] = useState(
  21. monitor.environments.length <= MAX_SHOWN_ENVIRONMENTS
  22. );
  23. const environments = isExpanded
  24. ? monitor.environments
  25. : monitor.environments.slice(0, MAX_SHOWN_ENVIRONMENTS);
  26. return (
  27. <TimelineRow key={monitor.id}>
  28. <MonitorDetails monitor={monitor} />
  29. <MonitorEnvContainer>
  30. {environments.map(({name, status}) => (
  31. <EnvWithStatus key={name}>
  32. <MonitorEnvLabel>{name}</MonitorEnvLabel>
  33. {statusIconMap[status]}
  34. </EnvWithStatus>
  35. ))}
  36. {!isExpanded && (
  37. <Button size="xs" onClick={() => setExpanded(true)}>
  38. {tct('Show [num] More', {
  39. num: monitor.environments.length - MAX_SHOWN_ENVIRONMENTS,
  40. })}
  41. </Button>
  42. )}
  43. </MonitorEnvContainer>
  44. {!bucketedData ? (
  45. <TimelinePlaceholder />
  46. ) : (
  47. <TimelineContainer>
  48. {environments.map(({name}) => {
  49. return (
  50. <CheckInTimeline
  51. key={name}
  52. {...timelineProps}
  53. bucketedData={bucketedData}
  54. environment={name}
  55. />
  56. );
  57. })}
  58. </TimelineContainer>
  59. )}
  60. </TimelineRow>
  61. );
  62. }
  63. function MonitorDetails({monitor}: {monitor: Monitor}) {
  64. const organization = useOrganization();
  65. const schedule = scheduleAsText(monitor.config);
  66. const monitorDetailUrl = `/organizations/${organization.slug}/crons/${monitor.slug}/`;
  67. return (
  68. <DetailsContainer to={monitorDetailUrl}>
  69. <Name>{monitor.name}</Name>
  70. <Schedule>{schedule}</Schedule>
  71. </DetailsContainer>
  72. );
  73. }
  74. const TimelineRow = styled('div')`
  75. display: contents;
  76. &:nth-child(odd) > * {
  77. background: ${p => p.theme.backgroundSecondary};
  78. }
  79. &:hover > * {
  80. background: ${p => p.theme.backgroundTertiary};
  81. }
  82. > * {
  83. transition: background 50ms ease-in-out;
  84. }
  85. `;
  86. const DetailsContainer = styled(Link)`
  87. color: ${p => p.theme.textColor};
  88. padding: ${space(3)};
  89. border-right: 1px solid ${p => p.theme.border};
  90. border-radius: 0;
  91. `;
  92. const Name = styled('h3')`
  93. font-size: ${p => p.theme.fontSizeLarge};
  94. margin-bottom: ${space(0.25)};
  95. `;
  96. const Schedule = styled('small')`
  97. color: ${p => p.theme.subText};
  98. font-size: ${p => p.theme.fontSizeSmall};
  99. `;
  100. const MonitorEnvContainer = styled('div')`
  101. display: flex;
  102. padding: ${space(3)} ${space(2)};
  103. flex-direction: column;
  104. gap: ${space(4)};
  105. border-right: 1px solid ${p => p.theme.innerBorder};
  106. text-align: right;
  107. `;
  108. const EnvWithStatus = styled('div')`
  109. display: flex;
  110. gap: ${space(1)};
  111. align-items: center;
  112. `;
  113. const MonitorEnvLabel = styled('div')`
  114. text-overflow: ellipsis;
  115. overflow: hidden;
  116. white-space: nowrap;
  117. flex: 1;
  118. `;
  119. const TimelineContainer = styled('div')`
  120. display: flex;
  121. padding: ${space(3)} 0;
  122. flex-direction: column;
  123. gap: ${space(4)};
  124. `;
  125. const TimelinePlaceholder = styled(Placeholder)`
  126. align-self: center;
  127. `;