releaseComparisonChartRow.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import NotAvailable from 'sentry/components/notAvailable';
  5. import Placeholder from 'sentry/components/placeholder';
  6. import Radio from 'sentry/components/radio';
  7. import {IconChevron} from 'sentry/icons';
  8. import {t} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import {ReleaseComparisonChartType} from 'sentry/types';
  11. import {defined} from 'sentry/utils';
  12. import {releaseComparisonChartLabels} from '../../utils';
  13. import {ReleaseComparisonRow} from '.';
  14. type Props = Omit<ReleaseComparisonRow, 'diffDirection' | 'diffColor'> & {
  15. activeChart: ReleaseComparisonChartType;
  16. chartDiff: React.ReactNode;
  17. expanded: boolean;
  18. onChartChange: (type: ReleaseComparisonChartType) => void;
  19. onExpanderToggle: (type: ReleaseComparisonChartType) => void;
  20. showPlaceholders: boolean;
  21. withExpanders: boolean;
  22. };
  23. function ReleaseComparisonChartRow({
  24. type,
  25. role,
  26. drilldown,
  27. thisRelease,
  28. allReleases,
  29. diff,
  30. showPlaceholders,
  31. activeChart,
  32. chartDiff,
  33. onChartChange,
  34. onExpanderToggle,
  35. expanded,
  36. withExpanders,
  37. }: Props) {
  38. return (
  39. <ChartTableRow
  40. htmlFor={type}
  41. isActive={type === activeChart}
  42. isLoading={showPlaceholders}
  43. role={role}
  44. expanded={expanded}
  45. >
  46. <DescriptionCell>
  47. <TitleWrapper>
  48. <Radio
  49. id={type}
  50. disabled={false}
  51. checked={type === activeChart}
  52. onChange={() => onChartChange(type)}
  53. />
  54. {releaseComparisonChartLabels[type]}&nbsp;{drilldown}
  55. </TitleWrapper>
  56. </DescriptionCell>
  57. <NumericCell>
  58. {showPlaceholders ? (
  59. <Placeholder height="20px" />
  60. ) : defined(allReleases) ? (
  61. allReleases
  62. ) : (
  63. <NotAvailable />
  64. )}
  65. </NumericCell>
  66. <NumericCell>
  67. {showPlaceholders ? (
  68. <Placeholder height="20px" />
  69. ) : defined(thisRelease) ? (
  70. thisRelease
  71. ) : (
  72. <NotAvailable />
  73. )}
  74. </NumericCell>
  75. <NumericCell>
  76. {showPlaceholders ? (
  77. <Placeholder height="20px" />
  78. ) : defined(diff) ? (
  79. chartDiff
  80. ) : (
  81. <NotAvailable />
  82. )}
  83. </NumericCell>
  84. {withExpanders && (
  85. <ExpanderCell>
  86. {role === 'parent' && (
  87. <ToggleButton
  88. onClick={() => onExpanderToggle(type)}
  89. borderless
  90. size="zero"
  91. icon={<IconChevron direction={expanded ? 'up' : 'down'} />}
  92. aria-label={t('Toggle chart group')}
  93. />
  94. )}
  95. </ExpanderCell>
  96. )}
  97. </ChartTableRow>
  98. );
  99. }
  100. const Cell = styled('div')`
  101. text-align: right;
  102. color: ${p => p.theme.subText};
  103. ${p => p.theme.overflowEllipsis}
  104. font-size: ${p => p.theme.fontSizeMedium};
  105. `;
  106. const NumericCell = styled(Cell)`
  107. font-variant-numeric: tabular-nums;
  108. `;
  109. const DescriptionCell = styled(Cell)`
  110. text-align: left;
  111. overflow: visible;
  112. color: ${p => p.theme.textColor};
  113. `;
  114. const ExpanderCell = styled(Cell)`
  115. display: flex;
  116. align-items: center;
  117. justify-content: flex-end;
  118. `;
  119. const TitleWrapper = styled('div')`
  120. display: flex;
  121. align-items: center;
  122. position: relative;
  123. z-index: 1;
  124. background: ${p => p.theme.background};
  125. input {
  126. width: ${space(2)};
  127. height: ${space(2)};
  128. flex-shrink: 0;
  129. background-color: ${p => p.theme.background};
  130. margin-right: ${space(1)} !important;
  131. &:checked:after {
  132. width: ${space(1)};
  133. height: ${space(1)};
  134. }
  135. &:hover {
  136. cursor: pointer;
  137. }
  138. }
  139. `;
  140. const ChartTableRow = styled('label')<{
  141. expanded: boolean;
  142. isActive: boolean;
  143. isLoading: boolean;
  144. role: ReleaseComparisonRow['role'];
  145. }>`
  146. display: contents;
  147. font-weight: 400;
  148. margin-bottom: 0;
  149. > * {
  150. padding: ${space(1)} ${space(2)};
  151. }
  152. ${p =>
  153. p.isActive &&
  154. !p.isLoading &&
  155. css`
  156. ${Cell}, ${NumericCell}, ${DescriptionCell}, ${TitleWrapper}, ${ExpanderCell} {
  157. background-color: ${p.theme.bodyBackground};
  158. }
  159. `}
  160. &:hover {
  161. cursor: pointer;
  162. ${Cell}, ${NumericCell}, ${DescriptionCell}, ${ExpanderCell}, ${TitleWrapper} {
  163. ${p => !p.isLoading && `background-color: ${p.theme.bodyBackground}`}
  164. }
  165. }
  166. ${p =>
  167. (p.role === 'default' || (p.role === 'parent' && !p.expanded)) &&
  168. css`
  169. &:not(:last-child) {
  170. ${Cell}, ${NumericCell}, ${DescriptionCell}, ${ExpanderCell} {
  171. border-bottom: 1px solid ${p.theme.border};
  172. }
  173. }
  174. `}
  175. ${p =>
  176. p.role === 'children' &&
  177. css`
  178. ${DescriptionCell} {
  179. padding-left: 44px;
  180. position: relative;
  181. &:before {
  182. content: '';
  183. width: 15px;
  184. height: 36px;
  185. position: absolute;
  186. top: -17px;
  187. left: 24px;
  188. border-bottom: 1px solid ${p.theme.border};
  189. border-left: 1px solid ${p.theme.border};
  190. }
  191. }
  192. `}
  193. ${p =>
  194. p.role === 'children' &&
  195. css`
  196. ${Cell}, ${NumericCell}, ${DescriptionCell}, ${ExpanderCell} {
  197. padding-bottom: ${space(0.75)};
  198. padding-top: ${space(0.75)};
  199. border-bottom: 0;
  200. }
  201. `}
  202. `;
  203. const ToggleButton = styled(Button)`
  204. &,
  205. &:hover,
  206. &:focus,
  207. &:active {
  208. background: transparent;
  209. }
  210. `;
  211. export default ReleaseComparisonChartRow;