replays.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  6. import PageHeading from 'sentry/components/pageHeading';
  7. import Pagination from 'sentry/components/pagination';
  8. import ReplaysFeatureBadge from 'sentry/components/replays/replaysFeatureBadge';
  9. import {t} from 'sentry/locale';
  10. import {PageContent, PageHeader} from 'sentry/styles/organization';
  11. import space from 'sentry/styles/space';
  12. import EventView from 'sentry/utils/discover/eventView';
  13. import {decodeScalar} from 'sentry/utils/queryString';
  14. import {DEFAULT_SORT, REPLAY_LIST_FIELDS} from 'sentry/utils/replays/fetchReplayList';
  15. import useReplayList from 'sentry/utils/replays/hooks/useReplayList';
  16. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  17. import useMedia from 'sentry/utils/useMedia';
  18. import useOrganization from 'sentry/utils/useOrganization';
  19. import ReplaysFilters from 'sentry/views/replays/filters';
  20. import ReplayTable from 'sentry/views/replays/replayTable';
  21. import type {ReplayListLocationQuery} from 'sentry/views/replays/types';
  22. type Props = RouteComponentProps<{orgId: string}, {}, any, ReplayListLocationQuery>;
  23. function Replays({location}: Props) {
  24. const organization = useOrganization();
  25. const theme = useTheme();
  26. const minWidthIsSmall = useMedia(`(min-width: ${theme.breakpoints.small})`);
  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 {replays, pageLinks, isFetching, fetchError} = useReplayList({
  44. organization,
  45. eventView,
  46. });
  47. return (
  48. <Fragment>
  49. <StyledPageHeader>
  50. <HeaderTitle>
  51. {t('Replays')} <ReplaysFeatureBadge space={1} />
  52. </HeaderTitle>
  53. </StyledPageHeader>
  54. <PageFiltersContainer>
  55. <StyledPageContent>
  56. <ReplaysFilters />
  57. <ReplayTable
  58. isFetching={isFetching}
  59. fetchError={fetchError}
  60. replays={replays}
  61. showProjectColumn={minWidthIsSmall}
  62. sort={eventView.sorts[0]}
  63. />
  64. <Pagination
  65. pageLinks={pageLinks}
  66. onCursor={(cursor, path, searchQuery) => {
  67. browserHistory.push({
  68. pathname: path,
  69. query: {...searchQuery, cursor},
  70. });
  71. }}
  72. />
  73. </StyledPageContent>
  74. </PageFiltersContainer>
  75. </Fragment>
  76. );
  77. }
  78. const StyledPageHeader = styled(PageHeader)`
  79. background-color: ${p => p.theme.surface100};
  80. min-width: max-content;
  81. margin: ${space(3)} ${space(0)} ${space(4)} ${space(4)};
  82. `;
  83. const StyledPageContent = styled(PageContent)`
  84. box-shadow: 0px 0px 1px ${p => p.theme.gray200};
  85. background-color: ${p => p.theme.background};
  86. `;
  87. const HeaderTitle = styled(PageHeading)`
  88. display: flex;
  89. flex: 1;
  90. `;
  91. export default Replays;