index.tsx 4.4 KB

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