replays.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import {Fragment, useMemo} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import {useTheme} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import DetailedError from 'sentry/components/errors/detailedError';
  6. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  7. import PageHeading from 'sentry/components/pageHeading';
  8. import Pagination from 'sentry/components/pagination';
  9. import ReplaysFeatureBadge from 'sentry/components/replays/replaysFeatureBadge';
  10. import {t} from 'sentry/locale';
  11. import {PageContent, PageHeader} from 'sentry/styles/organization';
  12. import space from 'sentry/styles/space';
  13. import EventView from 'sentry/utils/discover/eventView';
  14. import {decodeScalar} from 'sentry/utils/queryString';
  15. import useReplayList, {
  16. DEFAULT_SORT,
  17. REPLAY_LIST_FIELDS,
  18. } from 'sentry/utils/replays/hooks/useReplayList';
  19. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  20. import useMedia from 'sentry/utils/useMedia';
  21. import useOrganization from 'sentry/utils/useOrganization';
  22. import ReplaysFilters from 'sentry/views/replays/filters';
  23. import ReplayTable from 'sentry/views/replays/replayTable';
  24. import type {ReplayListLocationQuery} from 'sentry/views/replays/types';
  25. type Props = RouteComponentProps<{orgId: string}, {}, any, ReplayListLocationQuery>;
  26. function Replays({location}: Props) {
  27. const organization = useOrganization();
  28. const theme = useTheme();
  29. const minWidthIsSmall = useMedia(`(min-width: ${theme.breakpoints.small})`);
  30. const eventView = useMemo(() => {
  31. const query = decodeScalar(location.query.query, '');
  32. const conditions = new MutableSearch(query);
  33. return EventView.fromNewQueryWithLocation(
  34. {
  35. id: '',
  36. name: '',
  37. version: 2,
  38. fields: REPLAY_LIST_FIELDS,
  39. projects: [],
  40. query: conditions.formatString(),
  41. orderby: decodeScalar(location.query.sort, DEFAULT_SORT),
  42. },
  43. location
  44. );
  45. }, [location]);
  46. const {pathname, query} = location;
  47. const {replays, pageLinks, isFetching, fetchError} = useReplayList({
  48. organization,
  49. eventView,
  50. });
  51. if (fetchError && !isFetching) {
  52. const reasons = [
  53. t('The search parameters you selected are invalid in some way'),
  54. t('There is an internal systems error or active issue'),
  55. ];
  56. return (
  57. <DetailedError
  58. hideSupportLinks
  59. heading={t('Sorry, the list of replays could not be found.')}
  60. message={
  61. <div>
  62. <p>{t('This could be due to a handful of reasons:')}</p>
  63. <ol className="detailed-error-list">
  64. {reasons.map((reason, i) => (
  65. <li key={i}>{reason}</li>
  66. ))}
  67. </ol>
  68. </div>
  69. }
  70. />
  71. );
  72. }
  73. return (
  74. <Fragment>
  75. <StyledPageHeader>
  76. <HeaderTitle>
  77. <div>
  78. {t('Replays')} <ReplaysFeatureBadge />
  79. </div>
  80. </HeaderTitle>
  81. </StyledPageHeader>
  82. <PageFiltersContainer>
  83. <StyledPageContent>
  84. <ReplaysFilters
  85. query={query.query || ''}
  86. organization={organization}
  87. handleSearchQuery={searchQuery => {
  88. browserHistory.push({
  89. pathname,
  90. query: {
  91. ...query,
  92. cursor: undefined,
  93. query: searchQuery.trim(),
  94. },
  95. });
  96. }}
  97. />
  98. <ReplayTable
  99. isFetching={isFetching}
  100. replays={replays}
  101. showProjectColumn={minWidthIsSmall}
  102. sort={eventView.sorts[0]}
  103. />
  104. <Pagination
  105. pageLinks={pageLinks}
  106. onCursor={(cursor, path, searchQuery) => {
  107. browserHistory.push({
  108. pathname: path,
  109. query: {...searchQuery, cursor},
  110. });
  111. }}
  112. />
  113. </StyledPageContent>
  114. </PageFiltersContainer>
  115. </Fragment>
  116. );
  117. }
  118. const StyledPageHeader = styled(PageHeader)`
  119. background-color: ${p => p.theme.surface100};
  120. min-width: max-content;
  121. margin: ${space(3)} ${space(0)} ${space(4)} ${space(4)};
  122. `;
  123. const StyledPageContent = styled(PageContent)`
  124. box-shadow: 0px 0px 1px ${p => p.theme.gray200};
  125. background-color: ${p => p.theme.background};
  126. `;
  127. const HeaderTitle = styled(PageHeading)`
  128. display: flex;
  129. align-items: center;
  130. justify-content: space-between;
  131. flex: 1;
  132. `;
  133. export default Replays;