replaysList.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 {REPLAY_LIST_FIELDS} 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: REPLAY_LIST_FIELDS,
  36. projects: [],
  37. query: conditions.formatString(),
  38. orderby: decodeScalar(location.query.sort, DEFAULT_SORT),
  39. },
  40. location
  41. );
  42. }, [location]);
  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(String),
  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 visibleCols = [
  83. ReplayColumn.REPLAY,
  84. ReplayColumn.OS,
  85. ReplayColumn.BROWSER,
  86. ReplayColumn.DURATION,
  87. ReplayColumn.COUNT_DEAD_CLICKS,
  88. ReplayColumn.COUNT_RAGE_CLICKS,
  89. ReplayColumn.COUNT_ERRORS,
  90. ReplayColumn.ACTIVITY,
  91. ];
  92. return (
  93. <Fragment>
  94. <ReplayTable
  95. fetchError={fetchError}
  96. isFetching={isFetching}
  97. replays={replays}
  98. sort={eventView.sorts[0]}
  99. visibleColumns={visibleCols}
  100. emptyMessage={
  101. allSelectedProjectsNeedUpdates && hasReplayClick ? (
  102. <Fragment>
  103. {t('Unindexed search field')}
  104. <EmptyStateSubheading>
  105. {tct('Field [field] requires an [sdkPrompt]', {
  106. field: <strong>'click'</strong>,
  107. sdkPrompt: <strong>{t('SDK version >= 7.44.0')}</strong>,
  108. })}
  109. </EmptyStateSubheading>
  110. </Fragment>
  111. ) : undefined
  112. }
  113. />
  114. <ReplayPagination
  115. pageLinks={pageLinks}
  116. onCursor={(cursor, path, searchQuery) => {
  117. trackAnalytics('replay.list-paginated', {
  118. organization,
  119. direction: cursor?.endsWith(':1') ? 'prev' : 'next',
  120. });
  121. browserHistory.push({
  122. pathname: path,
  123. query: {...searchQuery, cursor},
  124. });
  125. }}
  126. />
  127. </Fragment>
  128. );
  129. }
  130. const EmptyStateSubheading = styled('div')`
  131. color: ${p => p.theme.subText};
  132. font-size: ${p => p.theme.fontSizeMedium};
  133. `;
  134. const ReplayPagination = styled(Pagination)`
  135. margin-top: 0;
  136. `;
  137. export default ReplaysList;