tableCell.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 {normalizeUrl} from 'sentry/utils/withDomainRequired';
  24. import type {ReplayListRecordWithTx} from 'sentry/views/performance/transactionSummary/transactionReplays/useReplaysWithTxData';
  25. import type {ReplayListRecord} from 'sentry/views/replays/types';
  26. type Props = {
  27. replay: ReplayListRecord | ReplayListRecordWithTx;
  28. };
  29. export type ReferrerTableType = 'main' | 'dead-table' | 'errors-table' | 'rage-table';
  30. function getUserBadgeUser(replay: Props['replay']) {
  31. return replay.is_archived
  32. ? {
  33. username: '',
  34. email: '',
  35. id: '',
  36. ip_address: '',
  37. name: '',
  38. }
  39. : {
  40. username: replay.user?.display_name || '',
  41. email: replay.user?.email || '',
  42. id: replay.user?.id || '',
  43. ip_address: replay.user?.ip || '',
  44. name: replay.user?.username || '',
  45. };
  46. }
  47. export function ReplayCell({
  48. eventView,
  49. organization,
  50. referrer,
  51. replay,
  52. showUrl,
  53. referrer_table,
  54. }: Props & {
  55. eventView: EventView;
  56. organization: Organization;
  57. referrer: string;
  58. referrer_table: ReferrerTableType;
  59. showUrl: boolean;
  60. }) {
  61. const {projects} = useProjects();
  62. const project = projects.find(p => p.id === replay.project_id);
  63. const replayDetails = {
  64. pathname: normalizeUrl(`/organizations/${organization.slug}/replays/${replay.id}/`),
  65. query: {
  66. referrer,
  67. ...eventView.generateQueryStringObject(),
  68. },
  69. };
  70. const replayDetailsErrorTab = {
  71. pathname: normalizeUrl(`/organizations/${organization.slug}/replays/${replay.id}/`),
  72. query: {
  73. referrer,
  74. ...eventView.generateQueryStringObject(),
  75. t_main: 'errors',
  76. },
  77. };
  78. const replayDetailsDOMEventsTab = {
  79. pathname: normalizeUrl(`/organizations/${organization.slug}/replays/${replay.id}/`),
  80. query: {
  81. referrer,
  82. ...eventView.generateQueryStringObject(),
  83. t_main: 'dom',
  84. f_d_type: 'ui.slowClickDetected',
  85. },
  86. };
  87. const detailsTab = () => {
  88. switch (referrer_table) {
  89. case 'errors-table':
  90. return replayDetailsErrorTab;
  91. case 'dead-table':
  92. return replayDetailsDOMEventsTab;
  93. case 'rage-table':
  94. return replayDetailsDOMEventsTab;
  95. default:
  96. return replayDetails;
  97. }
  98. };
  99. const trackNavigationEvent = () =>
  100. trackAnalytics('replay.list-navigate-to-details', {
  101. project_id: project?.id,
  102. platform: project?.platform,
  103. organization,
  104. referrer,
  105. referrer_table,
  106. });
  107. if (replay.is_archived) {
  108. return (
  109. <Item isArchived={replay.is_archived}>
  110. <Row gap={1}>
  111. <StyledIconDelete color="gray500" size="md" />
  112. <div>
  113. <Row gap={0.5}>{t('Deleted Replay')}</Row>
  114. <Row gap={0.5}>
  115. {project ? <Avatar size={12} project={project} /> : null}
  116. {getShortEventId(replay.id)}
  117. </Row>
  118. </div>
  119. </Row>
  120. </Item>
  121. );
  122. }
  123. const subText = (
  124. <Cols>
  125. {showUrl ? <StringWalker urls={replay.urls} /> : undefined}
  126. <Row gap={1}>
  127. <Row gap={0.5}>
  128. {project ? <Avatar size={12} project={project} /> : null}
  129. <Link to={detailsTab} onClick={trackNavigationEvent}>
  130. {getShortEventId(replay.id)}
  131. </Link>
  132. </Row>
  133. <Row gap={0.5}>
  134. <IconCalendar color="gray300" size="xs" />
  135. <TimeSince date={replay.started_at} />
  136. </Row>
  137. </Row>
  138. </Cols>
  139. );
  140. return (
  141. <Item>
  142. <UserBadgeFullWidth
  143. avatarSize={24}
  144. displayName={
  145. replay.is_archived ? (
  146. replay.user.display_name || t('Unknown User')
  147. ) : (
  148. <MainLink to={detailsTab} onClick={trackNavigationEvent}>
  149. {replay.user.display_name || t('Unknown User')}
  150. </MainLink>
  151. )
  152. }
  153. user={getUserBadgeUser(replay)}
  154. // this is the subheading for the avatar, so displayEmail in this case is a misnomer
  155. displayEmail={subText}
  156. />
  157. </Item>
  158. );
  159. }
  160. const StyledIconDelete = styled(IconDelete)`
  161. margin: ${space(0.25)};
  162. `;
  163. // Need to be full width for StringWalker to take up full width and truncate properly
  164. const UserBadgeFullWidth = styled(UserBadge)`
  165. width: 100%;
  166. `;
  167. const Cols = styled('div')`
  168. display: flex;
  169. flex-direction: column;
  170. gap: ${space(0.5)};
  171. width: 100%;
  172. `;
  173. const Row = styled('div')<{gap: ValidSize; minWidth?: number}>`
  174. display: flex;
  175. gap: ${p => space(p.gap)};
  176. align-items: center;
  177. ${p => (p.minWidth ? `min-width: ${p.minWidth}px;` : '')}
  178. `;
  179. const MainLink = styled(Link)`
  180. font-size: ${p => p.theme.fontSizeLarge};
  181. `;
  182. export function TransactionCell({
  183. organization,
  184. replay,
  185. }: Props & {organization: Organization}) {
  186. const location = useLocation();
  187. if (replay.is_archived) {
  188. return <Item isArchived />;
  189. }
  190. const hasTxEvent = 'txEvent' in replay;
  191. const txDuration = hasTxEvent ? replay.txEvent?.['transaction.duration'] : undefined;
  192. return hasTxEvent ? (
  193. <SpanOperationBreakdown>
  194. {txDuration ? <div>{txDuration}ms</div> : null}
  195. {spanOperationRelativeBreakdownRenderer(
  196. replay.txEvent,
  197. {organization, location},
  198. {enableOnClick: false}
  199. )}
  200. </SpanOperationBreakdown>
  201. ) : null;
  202. }
  203. export function OSCell({replay}: Props) {
  204. const {name, version} = replay.os ?? {};
  205. const theme = useTheme();
  206. const hasRoomForColumns = useMedia(`(min-width: ${theme.breakpoints.large})`);
  207. if (replay.is_archived) {
  208. return <Item isArchived />;
  209. }
  210. return (
  211. <Item>
  212. <ContextIcon
  213. name={name ?? ''}
  214. version={version && hasRoomForColumns ? version : undefined}
  215. showVersion={false}
  216. />
  217. </Item>
  218. );
  219. }
  220. export function BrowserCell({replay}: Props) {
  221. const {name, version} = replay.browser ?? {};
  222. const theme = useTheme();
  223. const hasRoomForColumns = useMedia(`(min-width: ${theme.breakpoints.large})`);
  224. if (replay.is_archived) {
  225. return <Item isArchived />;
  226. }
  227. return (
  228. <Item>
  229. <ContextIcon
  230. name={name ?? ''}
  231. version={version && hasRoomForColumns ? version : undefined}
  232. showVersion={false}
  233. />
  234. </Item>
  235. );
  236. }
  237. export function DurationCell({replay}: Props) {
  238. if (replay.is_archived) {
  239. return <Item isArchived />;
  240. }
  241. return (
  242. <Item>
  243. <Time>{formatTime(replay.duration.asMilliseconds())}</Time>
  244. </Item>
  245. );
  246. }
  247. export function RageClickCountCell({replay}: Props) {
  248. if (replay.is_archived) {
  249. return <Item isArchived />;
  250. }
  251. return (
  252. <Item data-test-id="replay-table-count-rage-clicks">
  253. {replay.count_rage_clicks ? (
  254. <DeadRageCount>{replay.count_rage_clicks}</DeadRageCount>
  255. ) : (
  256. <Count>0</Count>
  257. )}
  258. </Item>
  259. );
  260. }
  261. export function DeadClickCountCell({replay}: Props) {
  262. if (replay.is_archived) {
  263. return <Item isArchived />;
  264. }
  265. return (
  266. <Item data-test-id="replay-table-count-dead-clicks">
  267. {replay.count_dead_clicks ? (
  268. <DeadRageCount>{replay.count_dead_clicks}</DeadRageCount>
  269. ) : (
  270. <Count>0</Count>
  271. )}
  272. </Item>
  273. );
  274. }
  275. export function ErrorCountCell({replay}: Props) {
  276. if (replay.is_archived) {
  277. return <Item isArchived />;
  278. }
  279. return (
  280. <Item data-test-id="replay-table-count-errors">
  281. {replay.count_errors ? (
  282. <ErrorCount>
  283. <IconFire />
  284. {replay.count_errors}
  285. </ErrorCount>
  286. ) : (
  287. <Count>0</Count>
  288. )}
  289. </Item>
  290. );
  291. }
  292. export function ActivityCell({replay}: Props) {
  293. if (replay.is_archived) {
  294. return <Item isArchived />;
  295. }
  296. const scoreBarPalette = new Array(10).fill([CHART_PALETTE[0][0]]);
  297. return (
  298. <Item>
  299. <ScoreBar
  300. size={20}
  301. score={replay?.activity ?? 1}
  302. palette={scoreBarPalette}
  303. radius={0}
  304. />
  305. </Item>
  306. );
  307. }
  308. const Item = styled('div')<{isArchived?: boolean}>`
  309. display: flex;
  310. align-items: center;
  311. gap: ${space(1)};
  312. padding: ${space(1.5)};
  313. ${p => (p.isArchived ? 'opacity: 0.5;' : '')};
  314. `;
  315. const Count = styled('span')`
  316. font-variant-numeric: tabular-nums;
  317. `;
  318. const DeadRageCount = styled(Count)`
  319. display: flex;
  320. width: 40px;
  321. `;
  322. const ErrorCount = styled(Count)`
  323. display: flex;
  324. align-items: center;
  325. gap: ${space(0.5)};
  326. color: ${p => p.theme.red400};
  327. `;
  328. const Time = styled('span')`
  329. font-variant-numeric: tabular-nums;
  330. `;
  331. const SpanOperationBreakdown = styled('div')`
  332. width: 100%;
  333. display: flex;
  334. flex-direction: column;
  335. gap: ${space(0.5)};
  336. color: ${p => p.theme.gray500};
  337. font-size: ${p => p.theme.fontSizeMedium};
  338. text-align: right;
  339. `;