replaysList.tsx 4.5 KB

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