replaysList.tsx 4.7 KB

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