index.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {Fragment, ReactNode} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Alert} from 'sentry/components/alert';
  4. import PanelTable from 'sentry/components/panels/panelTable';
  5. import {t} from 'sentry/locale';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import type {Sort} from 'sentry/utils/discover/fields';
  8. import getRouteStringFromRoutes from 'sentry/utils/getRouteStringFromRoutes';
  9. import {useLocation} from 'sentry/utils/useLocation';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. import {useRoutes} from 'sentry/utils/useRoutes';
  12. import type {ReplayListRecordWithTx} from 'sentry/views/performance/transactionSummary/transactionReplays/useReplaysWithTxData';
  13. import HeaderCell from 'sentry/views/replays/replayTable/headerCell';
  14. import {
  15. ActivityCell,
  16. BrowserCell,
  17. DeadClickCountCell,
  18. DurationCell,
  19. ErrorCountCell,
  20. OSCell,
  21. RageClickCountCell,
  22. ReplayCell,
  23. TransactionCell,
  24. } from 'sentry/views/replays/replayTable/tableCell';
  25. import {ReplayColumn} from 'sentry/views/replays/replayTable/types';
  26. import type {ReplayListRecord} from 'sentry/views/replays/types';
  27. type Props = {
  28. fetchError: undefined | Error;
  29. isFetching: boolean;
  30. replays: undefined | ReplayListRecord[] | ReplayListRecordWithTx[];
  31. sort: Sort | undefined;
  32. visibleColumns: ReplayColumn[];
  33. emptyMessage?: ReactNode;
  34. };
  35. function ReplayTable({
  36. fetchError,
  37. isFetching,
  38. replays,
  39. sort,
  40. visibleColumns,
  41. emptyMessage,
  42. }: Props) {
  43. const routes = useRoutes();
  44. const location = useLocation();
  45. const organization = useOrganization();
  46. const tableHeaders = visibleColumns
  47. .filter(Boolean)
  48. .map(column => <HeaderCell key={column} column={column} sort={sort} />);
  49. if (fetchError && !isFetching) {
  50. return (
  51. <StyledPanelTable
  52. headers={tableHeaders}
  53. isLoading={false}
  54. visibleColumns={visibleColumns}
  55. data-test-id="replay-table"
  56. >
  57. <StyledAlert type="error" showIcon>
  58. {typeof fetchError === 'string'
  59. ? fetchError
  60. : t(
  61. 'Sorry, the list of replays could not be loaded. This could be due to invalid search parameters or an internal systems error.'
  62. )}
  63. </StyledAlert>
  64. </StyledPanelTable>
  65. );
  66. }
  67. const referrer = getRouteStringFromRoutes(routes);
  68. const eventView = EventView.fromLocation(location);
  69. return (
  70. <StyledPanelTable
  71. headers={tableHeaders}
  72. isEmpty={replays?.length === 0}
  73. isLoading={isFetching}
  74. visibleColumns={visibleColumns}
  75. disablePadding
  76. data-test-id="replay-table"
  77. emptyMessage={emptyMessage}
  78. >
  79. {replays?.map(replay => {
  80. return (
  81. <Fragment key={replay.id}>
  82. {visibleColumns.map(column => {
  83. switch (column) {
  84. case ReplayColumn.ACTIVITY:
  85. return <ActivityCell key="activity" replay={replay} />;
  86. case ReplayColumn.BROWSER:
  87. return <BrowserCell key="browser" replay={replay} />;
  88. case ReplayColumn.COUNT_DEAD_CLICKS:
  89. return <DeadClickCountCell key="countDeadClicks" replay={replay} />;
  90. case ReplayColumn.COUNT_ERRORS:
  91. return <ErrorCountCell key="countErrors" replay={replay} />;
  92. case ReplayColumn.COUNT_RAGE_CLICKS:
  93. return <RageClickCountCell key="countRageClicks" replay={replay} />;
  94. case ReplayColumn.DURATION:
  95. return <DurationCell key="duration" replay={replay} />;
  96. case ReplayColumn.OS:
  97. return <OSCell key="os" replay={replay} />;
  98. case ReplayColumn.REPLAY:
  99. return (
  100. <ReplayCell
  101. key="session"
  102. replay={replay}
  103. eventView={eventView}
  104. organization={organization}
  105. referrer={referrer}
  106. />
  107. );
  108. case ReplayColumn.SLOWEST_TRANSACTION:
  109. return (
  110. <TransactionCell
  111. key="slowestTransaction"
  112. replay={replay}
  113. organization={organization}
  114. />
  115. );
  116. default:
  117. return null;
  118. }
  119. })}
  120. </Fragment>
  121. );
  122. })}
  123. </StyledPanelTable>
  124. );
  125. }
  126. const StyledPanelTable = styled(PanelTable)<{
  127. visibleColumns: ReplayColumn[];
  128. }>`
  129. grid-template-columns: ${p =>
  130. p.visibleColumns
  131. .filter(Boolean)
  132. .map(column => (column === 'replay' ? 'minmax(100px, 1fr)' : 'max-content'))
  133. .join(' ')};
  134. `;
  135. const StyledAlert = styled(Alert)`
  136. border-radius: 0;
  137. border-width: 1px 0 0 0;
  138. grid-column: 1/-1;
  139. margin-bottom: 0;
  140. `;
  141. export default ReplayTable;