tableCell.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import {useTheme} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import Avatar from 'sentry/components/avatar';
  4. import UserBadge from 'sentry/components/idBadge/userBadge';
  5. import Link from 'sentry/components/links/link';
  6. import ContextIcon from 'sentry/components/replays/contextIcon';
  7. import {formatTime} from 'sentry/components/replays/utils';
  8. import StringWalker from 'sentry/components/replays/walker/stringWalker';
  9. import ScoreBar from 'sentry/components/scoreBar';
  10. import TimeSince from 'sentry/components/timeSince';
  11. import {CHART_PALETTE} from 'sentry/constants/chartPalette';
  12. import {IconCalendar, IconDelete, IconFire} from 'sentry/icons';
  13. import {t} from 'sentry/locale';
  14. import {space, ValidSize} from 'sentry/styles/space';
  15. import type {Organization} from 'sentry/types';
  16. import {trackAnalytics} from 'sentry/utils/analytics';
  17. import EventView from 'sentry/utils/discover/eventView';
  18. import {spanOperationRelativeBreakdownRenderer} from 'sentry/utils/discover/fieldRenderers';
  19. import {getShortEventId} from 'sentry/utils/events';
  20. import {useLocation} from 'sentry/utils/useLocation';
  21. import useMedia from 'sentry/utils/useMedia';
  22. import useProjects from 'sentry/utils/useProjects';
  23. import type {ReplayListRecordWithTx} from 'sentry/views/performance/transactionSummary/transactionReplays/useReplaysWithTxData';
  24. import type {ReplayListRecord} from 'sentry/views/replays/types';
  25. type Props = {
  26. replay: ReplayListRecord | ReplayListRecordWithTx;
  27. };
  28. function getUserBadgeUser(replay: Props['replay']) {
  29. return replay.is_archived
  30. ? {
  31. username: '',
  32. email: '',
  33. id: '',
  34. ip_address: '',
  35. name: '',
  36. }
  37. : {
  38. username: replay.user?.display_name || '',
  39. email: replay.user?.email || '',
  40. id: replay.user?.id || '',
  41. ip_address: replay.user?.ip || '',
  42. name: replay.user?.username || '',
  43. };
  44. }
  45. export function ReplayCell({
  46. eventView,
  47. organization,
  48. referrer,
  49. replay,
  50. }: Props & {eventView: EventView; organization: Organization; referrer: string}) {
  51. const {projects} = useProjects();
  52. const project = projects.find(p => p.id === replay.project_id);
  53. const replayDetails = {
  54. pathname: `/replays/${replay.id}/`,
  55. query: {
  56. referrer,
  57. ...eventView.generateQueryStringObject(),
  58. },
  59. };
  60. const trackNavigationEvent = () =>
  61. trackAnalytics('replay.list-navigate-to-details', {
  62. project_id: project?.id,
  63. platform: project?.platform,
  64. organization,
  65. referrer,
  66. });
  67. if (replay.is_archived) {
  68. return (
  69. <Item isArchived={replay.is_archived}>
  70. <Row gap={1}>
  71. <StyledIconDelete color="gray500" size="md" />
  72. <div>
  73. <Row gap={0.5}>{t('Deleted Replay')}</Row>
  74. <Row gap={0.5}>
  75. {project ? <Avatar size={12} project={project} /> : null}
  76. {getShortEventId(replay.id)}
  77. </Row>
  78. </div>
  79. </Row>
  80. </Item>
  81. );
  82. }
  83. const subText = (
  84. <Cols>
  85. <StringWalker urls={replay.urls} />
  86. <Row gap={1}>
  87. <Row gap={0.5}>
  88. {project ? <Avatar size={12} project={project} /> : null}
  89. <Link to={replayDetails} onClick={trackNavigationEvent}>
  90. {getShortEventId(replay.id)}
  91. </Link>
  92. </Row>
  93. <Row gap={0.5}>
  94. <IconCalendar color="gray300" size="xs" />
  95. <TimeSince date={replay.started_at} />
  96. </Row>
  97. </Row>
  98. </Cols>
  99. );
  100. return (
  101. <Item>
  102. <UserBadgeFullWidth
  103. avatarSize={24}
  104. displayName={
  105. replay.is_archived ? (
  106. replay.user.display_name || t('Unknown User')
  107. ) : (
  108. <MainLink to={replayDetails} onClick={trackNavigationEvent}>
  109. {replay.user.display_name || t('Unknown User')}
  110. </MainLink>
  111. )
  112. }
  113. user={getUserBadgeUser(replay)}
  114. // this is the subheading for the avatar, so displayEmail in this case is a misnomer
  115. displayEmail={subText}
  116. />
  117. </Item>
  118. );
  119. }
  120. const StyledIconDelete = styled(IconDelete)`
  121. margin: ${space(0.25)};
  122. `;
  123. // Need to be full width for StringWalker to take up full width and truncate properly
  124. const UserBadgeFullWidth = styled(UserBadge)`
  125. width: 100%;
  126. `;
  127. const Cols = styled('div')`
  128. display: flex;
  129. flex-direction: column;
  130. gap: ${space(0.5)};
  131. width: 100%;
  132. `;
  133. const Row = styled('div')<{gap: ValidSize; minWidth?: number}>`
  134. display: flex;
  135. gap: ${p => space(p.gap)};
  136. align-items: center;
  137. ${p => (p.minWidth ? `min-width: ${p.minWidth}px;` : '')}
  138. `;
  139. const MainLink = styled(Link)`
  140. font-size: ${p => p.theme.fontSizeLarge};
  141. `;
  142. export function TransactionCell({
  143. organization,
  144. replay,
  145. }: Props & {organization: Organization}) {
  146. const location = useLocation();
  147. if (replay.is_archived) {
  148. return <Item isArchived />;
  149. }
  150. const hasTxEvent = 'txEvent' in replay;
  151. const txDuration = hasTxEvent ? replay.txEvent?.['transaction.duration'] : undefined;
  152. return hasTxEvent ? (
  153. <SpanOperationBreakdown>
  154. {txDuration ? <div>{txDuration}ms</div> : null}
  155. {spanOperationRelativeBreakdownRenderer(
  156. replay.txEvent,
  157. {organization, location},
  158. {enableOnClick: false}
  159. )}
  160. </SpanOperationBreakdown>
  161. ) : null;
  162. }
  163. export function OSCell({replay}: Props) {
  164. const {name, version} = replay.os ?? {};
  165. const theme = useTheme();
  166. const hasRoomForColumns = useMedia(`(min-width: ${theme.breakpoints.large})`);
  167. if (replay.is_archived) {
  168. return <Item isArchived />;
  169. }
  170. return (
  171. <Item>
  172. <ContextIcon
  173. name={name ?? ''}
  174. version={version && hasRoomForColumns ? version : undefined}
  175. />
  176. </Item>
  177. );
  178. }
  179. export function BrowserCell({replay}: Props) {
  180. const {name, version} = replay.browser ?? {};
  181. const theme = useTheme();
  182. const hasRoomForColumns = useMedia(`(min-width: ${theme.breakpoints.large})`);
  183. if (replay.is_archived) {
  184. return <Item isArchived />;
  185. }
  186. return (
  187. <Item>
  188. <ContextIcon
  189. name={name ?? ''}
  190. version={version && hasRoomForColumns ? version : undefined}
  191. />
  192. </Item>
  193. );
  194. }
  195. export function DurationCell({replay}: Props) {
  196. if (replay.is_archived) {
  197. return <Item isArchived />;
  198. }
  199. return (
  200. <Item>
  201. <Time>{formatTime(replay.duration.asMilliseconds())}</Time>
  202. </Item>
  203. );
  204. }
  205. export function ErrorCountCell({replay}: Props) {
  206. if (replay.is_archived) {
  207. return <Item isArchived />;
  208. }
  209. return (
  210. <Item data-test-id="replay-table-count-errors">
  211. {replay.count_errors ? (
  212. <ErrorCount>
  213. <IconFire />
  214. {replay.count_errors}
  215. </ErrorCount>
  216. ) : (
  217. <Count>0</Count>
  218. )}
  219. </Item>
  220. );
  221. }
  222. export function ActivityCell({replay}: Props) {
  223. if (replay.is_archived) {
  224. return <Item isArchived />;
  225. }
  226. const scoreBarPalette = new Array(10).fill([CHART_PALETTE[0][0]]);
  227. return (
  228. <Item>
  229. <ScoreBar
  230. size={20}
  231. score={replay?.activity ?? 1}
  232. palette={scoreBarPalette}
  233. radius={0}
  234. />
  235. </Item>
  236. );
  237. }
  238. const Item = styled('div')<{isArchived?: boolean}>`
  239. display: flex;
  240. align-items: center;
  241. gap: ${space(1)};
  242. padding: ${space(1.5)};
  243. ${p => (p.isArchived ? 'opacity: 0.5;' : '')};
  244. `;
  245. const Count = styled('span')`
  246. font-variant-numeric: tabular-nums;
  247. `;
  248. const ErrorCount = styled(Count)`
  249. display: flex;
  250. align-items: center;
  251. gap: ${space(0.5)};
  252. color: ${p => p.theme.red400};
  253. `;
  254. const Time = styled('span')`
  255. font-variant-numeric: tabular-nums;
  256. `;
  257. const SpanOperationBreakdown = styled('div')`
  258. width: 100%;
  259. display: flex;
  260. flex-direction: column;
  261. gap: ${space(0.5)};
  262. color: ${p => p.theme.gray500};
  263. font-size: ${p => p.theme.fontSizeMedium};
  264. text-align: right;
  265. `;