automationListRow.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import styled from '@emotion/styled';
  2. import Checkbox from 'sentry/components/checkbox';
  3. import {Flex} from 'sentry/components/container/flex';
  4. import InteractionStateLayer from 'sentry/components/interactionStateLayer';
  5. import {
  6. type Action,
  7. ActionCell,
  8. } from 'sentry/components/workflowEngine/gridCell/actionCell';
  9. import {
  10. ConnectionCell,
  11. type Item,
  12. } from 'sentry/components/workflowEngine/gridCell/connectionCell';
  13. import {TimeAgoCell} from 'sentry/components/workflowEngine/gridCell/timeAgoCell';
  14. import {TitleCell} from 'sentry/components/workflowEngine/gridCell/titleCell';
  15. import {tn} from 'sentry/locale';
  16. import {space} from 'sentry/styles/space';
  17. import type {AvatarProject} from 'sentry/types/project';
  18. export type Automation = {
  19. actions: Action[];
  20. id: string;
  21. link: string;
  22. monitors: Item[];
  23. name: string;
  24. project: AvatarProject;
  25. details?: string[];
  26. disabled?: boolean;
  27. lastTriggered?: Date;
  28. };
  29. type AutomationListRowProps = Automation & {
  30. handleSelect: (id: string, checked: boolean) => void;
  31. selected: boolean;
  32. };
  33. export function AutomationListRow({
  34. actions,
  35. id,
  36. lastTriggered,
  37. link,
  38. monitors,
  39. name,
  40. project,
  41. details,
  42. handleSelect,
  43. selected,
  44. disabled,
  45. }: AutomationListRowProps) {
  46. return (
  47. <RowWrapper disabled={disabled}>
  48. <InteractionStateLayer />
  49. <Flex justify="space-between">
  50. <StyledCheckbox
  51. checked={selected}
  52. onChange={() => {
  53. handleSelect(id, !selected);
  54. }}
  55. />
  56. <CellWrapper>
  57. <StyledTitleCell
  58. name={name}
  59. project={project}
  60. link={link}
  61. details={details}
  62. disabled={disabled}
  63. />
  64. </CellWrapper>
  65. </Flex>
  66. <CellWrapper className="last-triggered">
  67. <TimeAgoCell date={lastTriggered} />
  68. </CellWrapper>
  69. <CellWrapper className="action">
  70. <ActionCell actions={actions} disabled={disabled} />
  71. </CellWrapper>
  72. <CellWrapper className="connected-monitors">
  73. <ConnectionCell
  74. items={monitors}
  75. renderText={count => tn('%s monitor', '%s monitors', count)}
  76. disabled={disabled}
  77. />
  78. </CellWrapper>
  79. </RowWrapper>
  80. );
  81. }
  82. const StyledCheckbox = styled(Checkbox)<{checked?: boolean}>`
  83. visibility: ${p => (p.checked ? 'visible' : 'hidden')};
  84. align-self: flex-start;
  85. opacity: 1;
  86. `;
  87. const CellWrapper = styled(Flex)`
  88. padding: 0 ${space(2)};
  89. flex: 1;
  90. overflow: hidden;
  91. white-space: nowrap;
  92. `;
  93. const StyledTitleCell = styled(TitleCell)`
  94. padding: ${space(2)};
  95. margin: -${space(2)};
  96. `;
  97. const RowWrapper = styled('div')<{disabled?: boolean}>`
  98. display: grid;
  99. position: relative;
  100. align-items: center;
  101. padding: ${space(2)};
  102. ${p =>
  103. p.disabled &&
  104. `
  105. ${CellWrapper} {
  106. opacity: 0.6;
  107. }
  108. `}
  109. &:hover {
  110. ${StyledCheckbox} {
  111. visibility: visible;
  112. }
  113. }
  114. .last-triggered,
  115. .action,
  116. .connected-monitors {
  117. display: none;
  118. }
  119. @media (min-width: ${p => p.theme.breakpoints.xsmall}) {
  120. grid-template-columns: 2.5fr 1fr;
  121. .action {
  122. display: flex;
  123. }
  124. }
  125. @media (min-width: ${p => p.theme.breakpoints.small}) {
  126. grid-template-columns: 2.5fr 1fr 1fr;
  127. .last-triggered {
  128. display: flex;
  129. }
  130. }
  131. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  132. grid-template-columns: 2.5fr 1fr 1fr 1fr;
  133. .connected-monitors {
  134. display: flex;
  135. }
  136. }
  137. @media (min-width: ${p => p.theme.breakpoints.large}) {
  138. grid-template-columns: 3fr 1fr 1fr 1fr;
  139. }
  140. `;