index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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';
  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 {ReplayColumn} 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: ReplayColumn[];
  31. emptyMessage?: ReactNode;
  32. };
  33. function ReplayTable({
  34. fetchError,
  35. isFetching,
  36. replays,
  37. sort,
  38. visibleColumns,
  39. emptyMessage,
  40. }: Props) {
  41. const routes = useRoutes();
  42. const location = useLocation();
  43. const organization = useOrganization();
  44. const tableHeaders = visibleColumns
  45. .filter(Boolean)
  46. .map(column => <HeaderCell key={column} column={column} sort={sort} />);
  47. if (fetchError && !isFetching) {
  48. return (
  49. <StyledPanelTable
  50. headers={tableHeaders}
  51. isLoading={false}
  52. visibleColumns={visibleColumns}
  53. data-test-id="replay-table"
  54. >
  55. <StyledAlert type="error" showIcon>
  56. {typeof fetchError === 'string'
  57. ? fetchError
  58. : t(
  59. 'Sorry, the list of replays could not be loaded. This could be due to invalid search parameters or an internal systems error.'
  60. )}
  61. </StyledAlert>
  62. </StyledPanelTable>
  63. );
  64. }
  65. const referrer = getRouteStringFromRoutes(routes);
  66. const eventView = EventView.fromLocation(location);
  67. return (
  68. <StyledPanelTable
  69. headers={tableHeaders}
  70. isEmpty={replays?.length === 0}
  71. isLoading={isFetching}
  72. visibleColumns={visibleColumns}
  73. disablePadding
  74. data-test-id="replay-table"
  75. emptyMessage={emptyMessage}
  76. >
  77. {replays?.map(replay => {
  78. return (
  79. <Fragment key={replay.id}>
  80. {visibleColumns.map(column => {
  81. switch (column) {
  82. case ReplayColumn.ACTIVITY:
  83. return <ActivityCell key="activity" replay={replay} />;
  84. case ReplayColumn.BROWSER:
  85. return <BrowserCell key="browser" replay={replay} />;
  86. case ReplayColumn.COUNT_ERRORS:
  87. return <ErrorCountCell key="countErrors" replay={replay} />;
  88. case ReplayColumn.DURATION:
  89. return <DurationCell key="duration" replay={replay} />;
  90. case ReplayColumn.OS:
  91. return <OSCell key="os" replay={replay} />;
  92. case ReplayColumn.REPLAY:
  93. return (
  94. <ReplayCell
  95. key="session"
  96. replay={replay}
  97. eventView={eventView}
  98. organization={organization}
  99. referrer={referrer}
  100. />
  101. );
  102. case ReplayColumn.SLOWEST_TRANSACTION:
  103. return (
  104. <TransactionCell
  105. key="slowestTransaction"
  106. replay={replay}
  107. organization={organization}
  108. />
  109. );
  110. default:
  111. return null;
  112. }
  113. })}
  114. </Fragment>
  115. );
  116. })}
  117. </StyledPanelTable>
  118. );
  119. }
  120. const StyledPanelTable = styled(PanelTable)<{
  121. visibleColumns: ReplayColumn[];
  122. }>`
  123. grid-template-columns: ${p =>
  124. p.visibleColumns
  125. .filter(Boolean)
  126. .map(column => (column === 'replay' ? 'minmax(100px, 1fr)' : 'max-content'))
  127. .join(' ')};
  128. `;
  129. const StyledAlert = styled(Alert)`
  130. border-radius: 0;
  131. border-width: 1px 0 0 0;
  132. grid-column: 1/-1;
  133. margin-bottom: 0;
  134. `;
  135. export default ReplayTable;