replaysList.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import {Fragment, useMemo} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import Pagination from 'sentry/components/pagination';
  5. import {t, tct} from 'sentry/locale';
  6. import {trackAnalytics} from 'sentry/utils/analytics';
  7. import {decodeList, decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  8. import useFetchReplayList from 'sentry/utils/replays/hooks/useFetchReplayList';
  9. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  10. import useLocationQuery from 'sentry/utils/url/useLocationQuery';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import usePageFilters from 'sentry/utils/usePageFilters';
  13. import useProjectSdkNeedsUpdate from 'sentry/utils/useProjectSdkNeedsUpdate';
  14. import useAllMobileProj from 'sentry/views/replays/detail/useAllMobileProj';
  15. import ReplayTable from 'sentry/views/replays/replayTable';
  16. import {ReplayColumn} from 'sentry/views/replays/replayTable/types';
  17. const MIN_REPLAY_CLICK_SDK = '7.44.0';
  18. function ReplaysList() {
  19. const organization = useOrganization();
  20. const query = useLocationQuery({
  21. fields: {
  22. cursor: decodeScalar,
  23. end: decodeScalar,
  24. environment: decodeList,
  25. project: decodeList,
  26. query: decodeScalar,
  27. sort: value => decodeScalar(value, '-started_at'),
  28. start: decodeScalar,
  29. statsPeriod: decodeScalar,
  30. utc: decodeScalar,
  31. },
  32. });
  33. const {
  34. data: replays,
  35. getResponseHeader,
  36. isLoading,
  37. error,
  38. } = useFetchReplayList({
  39. options: {query},
  40. organization,
  41. queryReferrer: 'replayList',
  42. });
  43. const pageLinks = getResponseHeader?.('Link') ?? null;
  44. const {
  45. selection: {projects},
  46. } = usePageFilters();
  47. const {allMobileProj} = useAllMobileProj();
  48. const {needsUpdate: allSelectedProjectsNeedUpdates} = useProjectSdkNeedsUpdate({
  49. minVersion: MIN_REPLAY_CLICK_SDK,
  50. organization,
  51. projectId: projects.map(String),
  52. });
  53. const conditions = useMemo(() => new MutableSearch(query.query), [query.query]);
  54. const hasReplayClick = conditions.getFilterKeys().some(k => k.startsWith('click.'));
  55. // browser isn't applicable for mobile projects
  56. // rage and dead clicks not available yet
  57. const visibleCols = allMobileProj
  58. ? [
  59. ReplayColumn.REPLAY,
  60. ReplayColumn.OS,
  61. ReplayColumn.DURATION,
  62. ReplayColumn.COUNT_ERRORS,
  63. ReplayColumn.ACTIVITY,
  64. ]
  65. : [
  66. ReplayColumn.REPLAY,
  67. ReplayColumn.OS,
  68. ReplayColumn.BROWSER,
  69. ReplayColumn.DURATION,
  70. ReplayColumn.COUNT_DEAD_CLICKS,
  71. ReplayColumn.COUNT_RAGE_CLICKS,
  72. ReplayColumn.COUNT_ERRORS,
  73. ReplayColumn.ACTIVITY,
  74. ];
  75. return (
  76. <Fragment>
  77. <ReplayTable
  78. referrerLocation={'replay'}
  79. fetchError={error}
  80. isFetching={isLoading}
  81. replays={replays}
  82. sort={decodeSorts(query.sort).at(0)}
  83. visibleColumns={visibleCols}
  84. showDropdownFilters
  85. emptyMessage={
  86. allSelectedProjectsNeedUpdates && hasReplayClick ? (
  87. <Fragment>
  88. {t('Unindexed search field')}
  89. <EmptyStateSubheading>
  90. {tct('Field [field] requires an [sdkPrompt]', {
  91. field: <strong>'click'</strong>,
  92. sdkPrompt: <strong>{t('SDK version >= 7.44.0')}</strong>,
  93. })}
  94. </EmptyStateSubheading>
  95. </Fragment>
  96. ) : undefined
  97. }
  98. />
  99. <ReplayPagination
  100. pageLinks={pageLinks}
  101. onCursor={(cursor, path, searchQuery) => {
  102. trackAnalytics('replay.list-paginated', {
  103. organization,
  104. direction: cursor?.endsWith(':1') ? 'prev' : 'next',
  105. });
  106. browserHistory.push({
  107. pathname: path,
  108. query: {...searchQuery, cursor},
  109. });
  110. }}
  111. />
  112. </Fragment>
  113. );
  114. }
  115. const EmptyStateSubheading = styled('div')`
  116. color: ${p => p.theme.subText};
  117. font-size: ${p => p.theme.fontSizeMedium};
  118. `;
  119. const ReplayPagination = styled(Pagination)`
  120. margin-top: 0;
  121. `;
  122. export default ReplaysList;