replaysList.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import {Fragment, useMemo} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Location} from 'history';
  5. import Pagination from 'sentry/components/pagination';
  6. import {t, tct} from 'sentry/locale';
  7. import type {Organization} from 'sentry/types';
  8. import {trackAnalytics} from 'sentry/utils/analytics';
  9. import EventView from 'sentry/utils/discover/eventView';
  10. import {decodeScalar} from 'sentry/utils/queryString';
  11. import {DEFAULT_SORT} from 'sentry/utils/replays/fetchReplayList';
  12. import useReplayList from 'sentry/utils/replays/hooks/useReplayList';
  13. import {useHaveSelectedProjectsSentAnyReplayEvents} from 'sentry/utils/replays/hooks/useReplayOnboarding';
  14. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  15. import {useLocation} from 'sentry/utils/useLocation';
  16. import useOrganization from 'sentry/utils/useOrganization';
  17. import usePageFilters from 'sentry/utils/usePageFilters';
  18. import useProjectSdkNeedsUpdate from 'sentry/utils/useProjectSdkNeedsUpdate';
  19. import ReplayOnboardingPanel from 'sentry/views/replays/list/replayOnboardingPanel';
  20. import ReplayTable from 'sentry/views/replays/replayTable';
  21. import {ReplayColumn} from 'sentry/views/replays/replayTable/types';
  22. import type {ReplayListLocationQuery} from 'sentry/views/replays/types';
  23. import {getReplayListFields} from 'sentry/views/replays/types';
  24. function ReplaysList() {
  25. const location = useLocation<ReplayListLocationQuery>();
  26. const organization = useOrganization();
  27. const eventView = useMemo(() => {
  28. const query = decodeScalar(location.query.query, '');
  29. const conditions = new MutableSearch(query);
  30. return EventView.fromNewQueryWithLocation(
  31. {
  32. id: '',
  33. name: '',
  34. version: 2,
  35. fields: getReplayListFields(organization),
  36. projects: [],
  37. query: conditions.formatString(),
  38. orderby: decodeScalar(location.query.sort, DEFAULT_SORT),
  39. },
  40. location
  41. );
  42. }, [location, organization]);
  43. const hasSessionReplay = organization.features.includes('session-replay');
  44. const {hasSentOneReplay, fetching} = useHaveSelectedProjectsSentAnyReplayEvents();
  45. return hasSessionReplay && !fetching && hasSentOneReplay ? (
  46. <ReplaysListTable
  47. eventView={eventView}
  48. location={location}
  49. organization={organization}
  50. />
  51. ) : (
  52. <ReplayOnboardingPanel />
  53. );
  54. }
  55. const MIN_REPLAY_CLICK_SDK = '7.44.0';
  56. function ReplaysListTable({
  57. eventView,
  58. location,
  59. organization,
  60. }: {
  61. eventView: EventView;
  62. location: Location;
  63. organization: Organization;
  64. }) {
  65. const {replays, pageLinks, isFetching, fetchError} = useReplayList({
  66. eventView,
  67. location,
  68. organization,
  69. });
  70. const {
  71. selection: {projects},
  72. } = usePageFilters();
  73. const {needsUpdate: allSelectedProjectsNeedUpdates} = useProjectSdkNeedsUpdate({
  74. minVersion: MIN_REPLAY_CLICK_SDK,
  75. organization,
  76. projectId: projects.map(p => String(p)),
  77. });
  78. const conditions = useMemo(() => {
  79. return new MutableSearch(decodeScalar(location.query.query, ''));
  80. }, [location.query.query]);
  81. const hasReplayClick = conditions.getFilterKeys().some(k => k.startsWith('click.'));
  82. const hasDeadRageCols = organization.features.includes(
  83. 'replay-rage-click-dead-click-columns'
  84. );
  85. const visibleCols = hasDeadRageCols
  86. ? [
  87. ReplayColumn.REPLAY,
  88. ReplayColumn.OS,
  89. ReplayColumn.BROWSER,
  90. ReplayColumn.DURATION,
  91. ReplayColumn.COUNT_DEAD_CLICKS,
  92. ReplayColumn.COUNT_RAGE_CLICKS,
  93. ReplayColumn.COUNT_ERRORS,
  94. ReplayColumn.ACTIVITY,
  95. ]
  96. : [
  97. ReplayColumn.REPLAY,
  98. ReplayColumn.OS,
  99. ReplayColumn.BROWSER,
  100. ReplayColumn.DURATION,
  101. ReplayColumn.COUNT_ERRORS,
  102. ReplayColumn.ACTIVITY,
  103. ];
  104. return (
  105. <Fragment>
  106. <ReplayTable
  107. fetchError={fetchError}
  108. isFetching={isFetching}
  109. replays={replays}
  110. sort={eventView.sorts[0]}
  111. visibleColumns={visibleCols}
  112. emptyMessage={
  113. allSelectedProjectsNeedUpdates && hasReplayClick ? (
  114. <Fragment>
  115. {t('Unindexed search field')}
  116. <EmptyStateSubheading>
  117. {tct('Field [field] requires an [sdkPrompt]', {
  118. field: <strong>'click'</strong>,
  119. sdkPrompt: <strong>{t('SDK version >= 7.44.0')}</strong>,
  120. })}
  121. </EmptyStateSubheading>
  122. </Fragment>
  123. ) : undefined
  124. }
  125. />
  126. <Pagination
  127. pageLinks={pageLinks}
  128. onCursor={(cursor, path, searchQuery) => {
  129. trackAnalytics('replay.list-paginated', {
  130. organization,
  131. direction: cursor?.endsWith(':1') ? 'prev' : 'next',
  132. });
  133. browserHistory.push({
  134. pathname: path,
  135. query: {...searchQuery, cursor},
  136. });
  137. }}
  138. />
  139. </Fragment>
  140. );
  141. }
  142. const EmptyStateSubheading = styled('div')`
  143. color: ${p => p.theme.subText};
  144. font-size: ${p => p.theme.fontSizeMedium};
  145. `;
  146. export default ReplaysList;