changeExplorer.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import moment from 'moment';
  5. import {getArbitraryRelativePeriod} from 'sentry/components/organizations/timeRangeSelector/utils';
  6. import {DEFAULT_RELATIVE_PERIODS} from 'sentry/constants';
  7. import {IconFire} from 'sentry/icons';
  8. import {t} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import {Organization, Project} from 'sentry/types';
  11. import theme from 'sentry/utils/theme';
  12. import {MetricsTable} from 'sentry/views/performance/trends/changeExplorerUtils/metricsTable';
  13. import {Chart} from 'sentry/views/performance/trends/chart';
  14. import {
  15. NormalizedTrendsTransaction,
  16. TrendChangeType,
  17. TrendParameter,
  18. TrendsStats,
  19. TrendView,
  20. } from 'sentry/views/performance/trends/types';
  21. import DetailPanel from 'sentry/views/starfish/components/detailPanel';
  22. type PerformanceChangeExplorerProps = {
  23. collapsed: boolean;
  24. isLoading: boolean;
  25. location: Location;
  26. onClose: () => void;
  27. organization: Organization;
  28. projects: Project[];
  29. statsData: TrendsStats;
  30. transaction: NormalizedTrendsTransaction;
  31. trendChangeType: TrendChangeType;
  32. trendFunction: string;
  33. trendParameter: TrendParameter;
  34. trendView: TrendView;
  35. };
  36. type ExplorerBodyProps = {
  37. isLoading: boolean;
  38. location: Location;
  39. organization: Organization;
  40. projects: Project[];
  41. statsData: TrendsStats;
  42. transaction: NormalizedTrendsTransaction;
  43. trendChangeType: TrendChangeType;
  44. trendFunction: string;
  45. trendParameter: TrendParameter;
  46. trendView: TrendView;
  47. };
  48. type HeaderProps = {
  49. transaction: NormalizedTrendsTransaction;
  50. trendChangeType: TrendChangeType;
  51. };
  52. export function PerformanceChangeExplorer({
  53. collapsed,
  54. transaction,
  55. onClose,
  56. trendChangeType,
  57. trendFunction,
  58. trendView,
  59. statsData,
  60. isLoading,
  61. organization,
  62. projects,
  63. trendParameter,
  64. location,
  65. }: PerformanceChangeExplorerProps) {
  66. return (
  67. <DetailPanel detailKey={!collapsed ? transaction.transaction : ''} onClose={onClose}>
  68. {!collapsed && (
  69. <PanelBodyWrapper>
  70. <ExplorerBody
  71. transaction={transaction}
  72. trendChangeType={trendChangeType}
  73. trendFunction={trendFunction}
  74. trendView={trendView}
  75. statsData={statsData}
  76. isLoading={isLoading}
  77. organization={organization}
  78. projects={projects}
  79. trendParameter={trendParameter}
  80. location={location}
  81. />
  82. </PanelBodyWrapper>
  83. )}
  84. </DetailPanel>
  85. );
  86. }
  87. function ExplorerBody(props: ExplorerBodyProps) {
  88. const {
  89. transaction,
  90. trendChangeType,
  91. trendFunction,
  92. trendView,
  93. trendParameter,
  94. isLoading,
  95. location,
  96. organization,
  97. } = props;
  98. const breakpointDate = transaction.breakpoint
  99. ? moment(transaction.breakpoint * 1000).format('ddd, DD MMM YYYY HH:mm:ss z')
  100. : '';
  101. const start = moment(trendView.start).format('DD MMM YYYY HH:mm:ss z');
  102. const end = moment(trendView.end).format('DD MMM YYYY HH:mm:ss z');
  103. return (
  104. <Fragment>
  105. <Header transaction={transaction} trendChangeType={trendChangeType} />
  106. <div style={{display: 'flex', gap: space(4)}}>
  107. <InfoItem
  108. label={
  109. trendChangeType === TrendChangeType.REGRESSION
  110. ? t('Regression Metric')
  111. : t('Improvement Metric')
  112. }
  113. value={trendFunction}
  114. />
  115. <InfoItem label={t('Start Time')} value={breakpointDate} />
  116. </div>
  117. <GraphPanel data-test-id="pce-graph">
  118. <strong>{`${trendParameter.label} (${trendFunction})`}</strong>
  119. <ExplorerText color={theme.gray300} margin={`-${space(3)}`}>
  120. {trendView.statsPeriod
  121. ? DEFAULT_RELATIVE_PERIODS[trendView.statsPeriod] ||
  122. getArbitraryRelativePeriod(trendView.statsPeriod)[trendView.statsPeriod]
  123. : `${start} - ${end}`}
  124. </ExplorerText>
  125. <Chart
  126. query={trendView.query}
  127. project={trendView.project}
  128. environment={trendView.environment}
  129. start={trendView.start}
  130. end={trendView.end}
  131. statsPeriod={trendView.statsPeriod}
  132. disableXAxis
  133. disableLegend
  134. neutralColor
  135. {...props}
  136. />
  137. </GraphPanel>
  138. <MetricsTable
  139. isLoading={isLoading}
  140. location={location}
  141. transaction={transaction}
  142. trendFunction={trendFunction}
  143. trendView={trendView}
  144. organization={organization}
  145. />
  146. </Fragment>
  147. );
  148. }
  149. function InfoItem({label, value}: {label: string; value: string}) {
  150. return (
  151. <div>
  152. <InfoLabel>{label}</InfoLabel>
  153. <InfoText>{value}</InfoText>
  154. </div>
  155. );
  156. }
  157. function Header(props: HeaderProps) {
  158. const {transaction, trendChangeType} = props;
  159. const regression = trendChangeType === TrendChangeType.REGRESSION;
  160. return (
  161. <HeaderWrapper data-test-id="pce-header">
  162. <FireIcon regression={regression}>
  163. <IconFire color="white" />
  164. </FireIcon>
  165. <HeaderTextWrapper>
  166. <ChangeType regression={regression}>
  167. {regression ? t('Ongoing Regression') : t('Ongoing Improvement')}
  168. </ChangeType>
  169. <TransactionName>{transaction.transaction}</TransactionName>
  170. </HeaderTextWrapper>
  171. </HeaderWrapper>
  172. );
  173. }
  174. const PanelBodyWrapper = styled('div')`
  175. padding: 0 ${space(2)};
  176. margin-top: ${space(4)};
  177. `;
  178. const HeaderWrapper = styled('div')`
  179. display: flex;
  180. flex-wrap: nowrap;
  181. margin-bottom: ${space(3)};
  182. `;
  183. const HeaderTextWrapper = styled('div')`
  184. ${p => p.theme.overflowEllipsis};
  185. `;
  186. type ChangeTypeProps = {regression: boolean};
  187. const ChangeType = styled('p')<ChangeTypeProps>`
  188. color: ${p => (p.regression ? p.theme.danger : p.theme.success)};
  189. margin-bottom: ${space(0)};
  190. `;
  191. const FireIcon = styled('div')<ChangeTypeProps>`
  192. padding: ${space(1.5)};
  193. background-color: ${p => (p.regression ? p.theme.danger : p.theme.success)};
  194. border-radius: ${space(0.5)};
  195. margin-right: ${space(2)};
  196. float: left;
  197. height: 40px;
  198. `;
  199. const TransactionName = styled('h4')`
  200. margin-right: ${space(1)};
  201. ${p => p.theme.overflowEllipsis};
  202. `;
  203. const InfoLabel = styled('strong')`
  204. color: ${p => p.theme.gray300};
  205. `;
  206. const InfoText = styled('h3')`
  207. font-weight: normal;
  208. `;
  209. const GraphPanel = styled('div')`
  210. border: 1px solid ${p => p.theme.border};
  211. border-radius: ${p => p.theme.panelBorderRadius};
  212. margin-bottom: ${space(2)};
  213. padding: ${space(3)};
  214. display: block;
  215. `;
  216. export const ExplorerText = styled('p')<{
  217. align?: string;
  218. color?: string;
  219. margin?: string;
  220. }>`
  221. margin-bottom: ${p => (p.margin ? p.margin : space(0))};
  222. color: ${p => p.color};
  223. text-align: ${p => p.align};
  224. `;