replaysList.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 {ReplaySearchAlert} from 'sentry/views/replays/list/replaySearchAlert';
  21. import ReplayTable from 'sentry/views/replays/replayTable';
  22. import {ReplayColumns} from 'sentry/views/replays/replayTable/types';
  23. import type {ReplayListLocationQuery} from 'sentry/views/replays/types';
  24. import {REPLAY_LIST_FIELDS} from 'sentry/views/replays/types';
  25. function ReplaysList() {
  26. const location = useLocation<ReplayListLocationQuery>();
  27. const organization = useOrganization();
  28. const eventView = useMemo(() => {
  29. const query = decodeScalar(location.query.query, '');
  30. const conditions = new MutableSearch(query);
  31. return EventView.fromNewQueryWithLocation(
  32. {
  33. id: '',
  34. name: '',
  35. version: 2,
  36. fields: REPLAY_LIST_FIELDS,
  37. projects: [],
  38. query: conditions.formatString(),
  39. orderby: decodeScalar(location.query.sort, DEFAULT_SORT),
  40. },
  41. location
  42. );
  43. }, [location]);
  44. const hasSessionReplay = organization.features.includes('session-replay');
  45. const {hasSentOneReplay, fetching} = useHaveSelectedProjectsSentAnyReplayEvents();
  46. return hasSessionReplay && !fetching && hasSentOneReplay ? (
  47. <ReplaysListTable
  48. eventView={eventView}
  49. location={location}
  50. organization={organization}
  51. />
  52. ) : (
  53. <ReplayOnboardingPanel />
  54. );
  55. }
  56. const MIN_REPLAY_CLICK_SDK = '7.44.0';
  57. function ReplaysListTable({
  58. eventView,
  59. location,
  60. organization,
  61. }: {
  62. eventView: EventView;
  63. location: Location;
  64. organization: Organization;
  65. }) {
  66. const {replays, pageLinks, isFetching, fetchError} = useReplayList({
  67. eventView,
  68. location,
  69. organization,
  70. });
  71. const {
  72. selection: {projects},
  73. } = usePageFilters();
  74. const {needsUpdate: allSelectedProjectsNeedUpdates} = useProjectSdkNeedsUpdate({
  75. minVersion: MIN_REPLAY_CLICK_SDK,
  76. organization,
  77. projectId: projects.map(p => String(p)),
  78. });
  79. const conditions = useMemo(() => {
  80. return new MutableSearch(decodeScalar(location.query.query, ''));
  81. }, [location.query.query]);
  82. const hasReplayClick = conditions.getFilterKeys().some(k => k.startsWith('click.'));
  83. const hasReplayClickSearchBannerRollout = organization.features.includes(
  84. 'session-replay-click-search-banner-rollout'
  85. );
  86. return (
  87. <Fragment>
  88. {hasReplayClickSearchBannerRollout && (
  89. <ReplaySearchAlert needSdkUpdates={Boolean(allSelectedProjectsNeedUpdates)} />
  90. )}
  91. <ReplayTable
  92. fetchError={fetchError}
  93. isFetching={isFetching}
  94. replays={replays}
  95. sort={eventView.sorts[0]}
  96. visibleColumns={[
  97. ReplayColumns.replay,
  98. ReplayColumns.os,
  99. ReplayColumns.browser,
  100. ReplayColumns.duration,
  101. ReplayColumns.countErrors,
  102. ReplayColumns.activity,
  103. ]}
  104. emptyMessage={
  105. allSelectedProjectsNeedUpdates && hasReplayClick ? (
  106. <Fragment>
  107. {t('Unindexed search field')}
  108. <EmptyStateSubheading>
  109. {tct('Field [field] requires an [sdkPrompt]', {
  110. field: <strong>'click'</strong>,
  111. sdkPrompt: <strong>{t('SDK version >= 7.44.0')}</strong>,
  112. })}
  113. </EmptyStateSubheading>
  114. </Fragment>
  115. ) : undefined
  116. }
  117. />
  118. <Pagination
  119. pageLinks={pageLinks}
  120. onCursor={(cursor, path, searchQuery) => {
  121. trackAnalytics('replay.list-paginated', {
  122. organization,
  123. direction: cursor?.endsWith(':1') ? 'prev' : 'next',
  124. });
  125. browserHistory.push({
  126. pathname: path,
  127. query: {...searchQuery, cursor},
  128. });
  129. }}
  130. />
  131. </Fragment>
  132. );
  133. }
  134. const EmptyStateSubheading = styled('div')`
  135. color: ${p => p.theme.subText};
  136. font-size: ${p => p.theme.fontSizeMedium};
  137. `;
  138. export default ReplaysList;