tableCell.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 ErrorCount from 'sentry/components/replays/header/errorCount';
  8. import {formatTime} from 'sentry/components/replays/utils';
  9. import {StringWalker} from 'sentry/components/replays/walker/urlWalker';
  10. import ScoreBar from 'sentry/components/scoreBar';
  11. import TimeSince from 'sentry/components/timeSince';
  12. import {CHART_PALETTE} from 'sentry/constants/chartPalette';
  13. import {IconCalendar, IconDelete} from 'sentry/icons';
  14. import {t} from 'sentry/locale';
  15. import {space, ValidSize} from 'sentry/styles/space';
  16. import type {Organization} from 'sentry/types';
  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: `/organizations/${organization.slug}/replays/${project?.slug}:${replay.id}/`,
  55. query: {
  56. referrer,
  57. ...eventView.generateQueryStringObject(),
  58. },
  59. };
  60. if (replay.is_archived) {
  61. return (
  62. <Item isArchived={replay.is_archived}>
  63. <Row gap={1}>
  64. <StyledIconDelete color="gray500" size="md" />
  65. <div>
  66. <Row gap={0.5}>{t('Deleted Replay')}</Row>
  67. <Row gap={0.5}>
  68. {project ? <Avatar size={12} project={project} /> : null}
  69. {getShortEventId(replay.id)}
  70. </Row>
  71. </div>
  72. </Row>
  73. </Item>
  74. );
  75. }
  76. const subText = (
  77. <Cols>
  78. <StringWalker urls={replay.urls} />
  79. <Row gap={1}>
  80. <Row gap={0.5}>
  81. {project ? <Avatar size={12} project={project} /> : null}
  82. <Link to={replayDetails}>{getShortEventId(replay.id)}</Link>
  83. </Row>
  84. <Row gap={0.5}>
  85. <IconCalendar color="gray300" size="xs" />
  86. <TimeSince date={replay.started_at} />
  87. </Row>
  88. </Row>
  89. </Cols>
  90. );
  91. return (
  92. <Item>
  93. <UserBadgeFullWidth
  94. avatarSize={24}
  95. displayName={
  96. replay.is_archived ? (
  97. replay.user.display_name || t('Unknown User')
  98. ) : (
  99. <MainLink to={replayDetails}>
  100. {replay.user.display_name || t('Unknown User')}
  101. </MainLink>
  102. )
  103. }
  104. user={getUserBadgeUser(replay)}
  105. // this is the subheading for the avatar, so displayEmail in this case is a misnomer
  106. displayEmail={subText}
  107. />
  108. </Item>
  109. );
  110. }
  111. const StyledIconDelete = styled(IconDelete)`
  112. margin: ${space(0.25)};
  113. `;
  114. // Need to be full width for StringWalker to take up full width and truncate properly
  115. const UserBadgeFullWidth = styled(UserBadge)`
  116. width: 100%;
  117. `;
  118. const Cols = styled('div')`
  119. display: flex;
  120. flex-direction: column;
  121. gap: ${space(0.5)};
  122. width: 100%;
  123. `;
  124. const Row = styled('div')<{gap: ValidSize; minWidth?: number}>`
  125. display: flex;
  126. gap: ${p => space(p.gap)};
  127. align-items: center;
  128. ${p => (p.minWidth ? `min-width: ${p.minWidth}px;` : '')}
  129. `;
  130. const MainLink = styled(Link)`
  131. font-size: ${p => p.theme.fontSizeLarge};
  132. `;
  133. export function TransactionCell({
  134. organization,
  135. replay,
  136. }: Props & {organization: Organization}) {
  137. const location = useLocation();
  138. if (replay.is_archived) {
  139. return <Item isArchived />;
  140. }
  141. const hasTxEvent = 'txEvent' in replay;
  142. const txDuration = hasTxEvent ? replay.txEvent?.['transaction.duration'] : undefined;
  143. return hasTxEvent ? (
  144. <SpanOperationBreakdown>
  145. {txDuration ? <div>{txDuration}ms</div> : null}
  146. {spanOperationRelativeBreakdownRenderer(
  147. replay.txEvent,
  148. {organization, location},
  149. {enableOnClick: false}
  150. )}
  151. </SpanOperationBreakdown>
  152. ) : null;
  153. }
  154. export function OSCell({replay}: Props) {
  155. const {name, version} = replay.os ?? {};
  156. const theme = useTheme();
  157. const hasRoomForColumns = useMedia(`(min-width: ${theme.breakpoints.large})`);
  158. if (replay.is_archived) {
  159. return <Item isArchived />;
  160. }
  161. return (
  162. <Item>
  163. <ContextIcon
  164. name={name ?? ''}
  165. version={version && hasRoomForColumns ? version : undefined}
  166. />
  167. </Item>
  168. );
  169. }
  170. export function BrowserCell({replay}: Props) {
  171. const {name, version} = replay.browser ?? {};
  172. const theme = useTheme();
  173. const hasRoomForColumns = useMedia(`(min-width: ${theme.breakpoints.large})`);
  174. if (replay.is_archived) {
  175. return <Item isArchived />;
  176. }
  177. return (
  178. <Item>
  179. <ContextIcon
  180. name={name ?? ''}
  181. version={version && hasRoomForColumns ? version : undefined}
  182. />
  183. </Item>
  184. );
  185. }
  186. export function DurationCell({replay}: Props) {
  187. if (replay.is_archived) {
  188. return <Item isArchived />;
  189. }
  190. return (
  191. <Item>
  192. <Time>{formatTime(replay.duration.asMilliseconds())}</Time>
  193. </Item>
  194. );
  195. }
  196. export function ErrorCountCell({replay}: Props) {
  197. if (replay.is_archived) {
  198. return <Item isArchived />;
  199. }
  200. return (
  201. <Item data-test-id="replay-table-count-errors">
  202. <ErrorCount countErrors={replay.count_errors} />
  203. </Item>
  204. );
  205. }
  206. export function ActivityCell({replay}: Props) {
  207. if (replay.is_archived) {
  208. return <Item isArchived />;
  209. }
  210. const scoreBarPalette = new Array(10).fill([CHART_PALETTE[0][0]]);
  211. return (
  212. <Item>
  213. <ScoreBar
  214. size={20}
  215. score={replay?.activity ?? 1}
  216. palette={scoreBarPalette}
  217. radius={0}
  218. />
  219. </Item>
  220. );
  221. }
  222. const Item = styled('div')<{isArchived?: boolean}>`
  223. display: flex;
  224. align-items: center;
  225. gap: ${space(1)};
  226. padding: ${space(1.5)};
  227. ${p => (p.isArchived ? 'opacity: 0.5;' : '')};
  228. `;
  229. const Time = styled('span')`
  230. font-variant-numeric: tabular-nums;
  231. `;
  232. const SpanOperationBreakdown = styled('div')`
  233. width: 100%;
  234. display: flex;
  235. flex-direction: column;
  236. gap: ${space(0.5)};
  237. color: ${p => p.theme.gray500};
  238. font-size: ${p => p.theme.fontSizeMedium};
  239. text-align: right;
  240. `;