replaysErroneousDeadRageCards.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 {Button} from 'sentry/components/button';
  6. import {IconClose, IconSearch} from 'sentry/icons';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import type {Organization} from 'sentry/types';
  10. import EventView from 'sentry/utils/discover/eventView';
  11. import useReplayList from 'sentry/utils/replays/hooks/useReplayList';
  12. import {useHaveSelectedProjectsSentAnyReplayEvents} from 'sentry/utils/replays/hooks/useReplayOnboarding';
  13. import {useLocation} from 'sentry/utils/useLocation';
  14. import useOrganization from 'sentry/utils/useOrganization';
  15. import ReplayTable from 'sentry/views/replays/replayTable';
  16. import {ReplayColumn} from 'sentry/views/replays/replayTable/types';
  17. import {ReplayListLocationQuery} from 'sentry/views/replays/types';
  18. function ReplaysErroneousDeadRageCards() {
  19. const organization = useOrganization();
  20. const location = useLocation<ReplayListLocationQuery>();
  21. const newLocation = useMemo(() => {
  22. return {
  23. pathname: '',
  24. search: '',
  25. hash: '',
  26. state: '',
  27. action: 'PUSH' as const,
  28. key: '',
  29. query: {
  30. project: location.query.project,
  31. environment: location.query.environment,
  32. start: location.query.start,
  33. statsPeriod: location.query.statsPeriod,
  34. utc: location.query.utc,
  35. end: location.query.end,
  36. },
  37. };
  38. }, [
  39. location.query.project,
  40. location.query.environment,
  41. location.query.start,
  42. location.query.statsPeriod,
  43. location.query.utc,
  44. location.query.end,
  45. ]);
  46. const eventViewDead = useMemo(() => {
  47. return EventView.fromNewQueryWithLocation(
  48. {
  49. id: '',
  50. name: '',
  51. version: 2,
  52. fields: [
  53. 'activity',
  54. 'duration',
  55. 'count_dead_clicks',
  56. 'id',
  57. 'project_id',
  58. 'user',
  59. 'finished_at',
  60. 'is_archived',
  61. 'started_at',
  62. ],
  63. projects: [],
  64. query: 'count_dead_clicks:>0',
  65. orderby: '-count_dead_clicks',
  66. },
  67. newLocation
  68. );
  69. }, [newLocation]);
  70. const eventViewRage = useMemo(() => {
  71. return EventView.fromNewQueryWithLocation(
  72. {
  73. id: '',
  74. name: '',
  75. version: 2,
  76. fields: [
  77. 'activity',
  78. 'duration',
  79. 'count_rage_clicks',
  80. 'id',
  81. 'project_id',
  82. 'user',
  83. 'finished_at',
  84. 'is_archived',
  85. 'started_at',
  86. ],
  87. projects: [],
  88. query: 'count_rage_clicks:>0',
  89. orderby: '-count_rage_clicks',
  90. },
  91. newLocation
  92. );
  93. }, [newLocation]);
  94. const hasSessionReplay = organization.features.includes('session-replay');
  95. const hasDeadRageCards = organization.features.includes('replay-error-click-cards');
  96. const {hasSentOneReplay, fetching} = useHaveSelectedProjectsSentAnyReplayEvents();
  97. const deadCols = [
  98. ReplayColumn.MOST_DEAD_CLICKS,
  99. ReplayColumn.COUNT_DEAD_CLICKS_NO_HEADER,
  100. ];
  101. const rageCols = [
  102. ReplayColumn.MOST_RAGE_CLICKS,
  103. ReplayColumn.COUNT_RAGE_CLICKS_NO_HEADER,
  104. ];
  105. return hasSessionReplay && hasDeadRageCards && hasSentOneReplay && !fetching ? (
  106. <SplitCardContainer>
  107. <CardTable
  108. eventView={eventViewDead}
  109. location={newLocation}
  110. organization={organization}
  111. visibleColumns={deadCols}
  112. searchQuery={{
  113. ...location.query,
  114. cursor: undefined,
  115. query: 'count_dead_clicks:>0',
  116. sort: '-count_dead_clicks',
  117. }}
  118. buttonLabel={t('Show all replays with dead clicks')}
  119. />
  120. <CardTable
  121. eventView={eventViewRage}
  122. location={newLocation}
  123. organization={organization}
  124. visibleColumns={rageCols}
  125. searchQuery={{
  126. ...location.query,
  127. cursor: undefined,
  128. query: 'count_rage_clicks:>0',
  129. sort: '-count_rage_clicks',
  130. }}
  131. buttonLabel={t('Show all replays with rage clicks')}
  132. />
  133. </SplitCardContainer>
  134. ) : null;
  135. }
  136. function CardTable({
  137. buttonLabel,
  138. eventView,
  139. location,
  140. organization,
  141. searchQuery,
  142. visibleColumns,
  143. }: {
  144. buttonLabel: string;
  145. eventView: EventView;
  146. location: Location;
  147. organization: Organization;
  148. searchQuery: {
  149. cursor: undefined;
  150. query: string;
  151. sort: string;
  152. };
  153. visibleColumns: ReplayColumn[];
  154. }) {
  155. const {replays, isFetching, fetchError} = useReplayList({
  156. eventView,
  157. location,
  158. organization,
  159. perPage: 3,
  160. });
  161. const gridRows = new Array(replays ? (replays.length > 0 ? 3 : 1) : 1)
  162. .fill(' ')
  163. .map(_ => '1fr')
  164. .join(' ');
  165. const emptyLocation = useLocation();
  166. const emptySearchQuery = {
  167. ...emptyLocation.query,
  168. cursor: undefined,
  169. query: '',
  170. sort: '',
  171. };
  172. return (
  173. <Fragment>
  174. <ReplayTable
  175. fetchError={fetchError}
  176. isFetching={isFetching}
  177. replays={replays}
  178. sort={undefined}
  179. visibleColumns={visibleColumns}
  180. saveLocation
  181. gridRows={'auto ' + gridRows}
  182. />
  183. <StyledButton
  184. size="sm"
  185. onClick={() => {
  186. const newQuery =
  187. emptyLocation.query.query === searchQuery.query
  188. ? emptySearchQuery
  189. : searchQuery;
  190. browserHistory.push({
  191. pathname: emptyLocation.pathname,
  192. query: newQuery,
  193. });
  194. }}
  195. icon={
  196. emptyLocation.query.query === searchQuery.query ? (
  197. <IconClose size="xs" />
  198. ) : (
  199. <IconSearch size="xs" />
  200. )
  201. }
  202. >
  203. {emptyLocation.query.query === searchQuery.query
  204. ? t('Clear filter')
  205. : buttonLabel}
  206. </StyledButton>
  207. </Fragment>
  208. );
  209. }
  210. const SplitCardContainer = styled('div')`
  211. display: grid;
  212. grid-template-columns: 1fr 1fr;
  213. grid-template-rows: max-content max-content;
  214. grid-auto-flow: column;
  215. gap: 0 ${space(2)};
  216. align-items: stretch;
  217. `;
  218. const StyledButton = styled(Button)`
  219. width: 100%;
  220. border-top: none;
  221. border-radius: ${p => p.theme.borderRadiusBottom};
  222. padding: ${space(3)};
  223. `;
  224. export default ReplaysErroneousDeadRageCards;