deadRageSelectorCards.tsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import {ComponentProps, ReactNode, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import Accordion from 'sentry/components/accordion/accordion';
  4. import {LinkButton} from 'sentry/components/button';
  5. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  6. import FeatureBadge from 'sentry/components/featureBadge';
  7. import Placeholder from 'sentry/components/placeholder';
  8. import QuestionTooltip from 'sentry/components/questionTooltip';
  9. import TextOverflow from 'sentry/components/textOverflow';
  10. import {IconCursorArrow} from 'sentry/icons';
  11. import {t, tct} from 'sentry/locale';
  12. import {space} from 'sentry/styles/space';
  13. import useDeadRageSelectors from 'sentry/utils/replays/hooks/useDeadRageSelectors';
  14. import {ColorOrAlias} from 'sentry/utils/theme';
  15. import {useLocation} from 'sentry/utils/useLocation';
  16. import useOrganization from 'sentry/utils/useOrganization';
  17. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  18. import {
  19. ContentContainer,
  20. HeaderContainer,
  21. HeaderTitleLegend,
  22. Subtitle,
  23. WidgetContainer,
  24. } from 'sentry/views/profiling/landing/styles';
  25. import ExampleReplaysList from 'sentry/views/replays/deadRageClick/exampleReplaysList';
  26. import {
  27. ProjectInfo,
  28. SelectorLink,
  29. transformSelectorQuery,
  30. } from 'sentry/views/replays/deadRageClick/selectorTable';
  31. function DeadRageSelectorCards() {
  32. return (
  33. <SplitCardContainer>
  34. <AccordionWidget
  35. clickType="count_dead_clicks"
  36. header={
  37. <div>
  38. <StyledWidgetHeader>
  39. <TitleTooltipContainer>
  40. {t('Most Dead Clicks')}
  41. <QuestionTooltip
  42. size="xs"
  43. position="top"
  44. title={t(
  45. 'The top selectors your users have dead clicked on (i.e., a user click that does not result in any page activity after 7 seconds).'
  46. )}
  47. isHoverable
  48. />
  49. </TitleTooltipContainer>
  50. <FeatureBadge type="new" />
  51. </StyledWidgetHeader>
  52. <Subtitle>{t('Suggested replays to watch')}</Subtitle>
  53. </div>
  54. }
  55. deadOrRage="dead"
  56. />
  57. <AccordionWidget
  58. clickType="count_rage_clicks"
  59. header={
  60. <div>
  61. <StyledWidgetHeader>
  62. <TitleTooltipContainer>
  63. {t('Most Rage Clicks')}
  64. <QuestionTooltip
  65. size="xs"
  66. position="top"
  67. title={t(
  68. 'The top selectors your users have rage clicked on (i.e., 5 or more clicks on a dead element, which exhibits no page activity after 7 seconds).'
  69. )}
  70. isHoverable
  71. />
  72. </TitleTooltipContainer>
  73. <FeatureBadge type="new" />
  74. </StyledWidgetHeader>
  75. <Subtitle>{t('Suggested replays to watch')}</Subtitle>
  76. </div>
  77. }
  78. deadOrRage="rage"
  79. />
  80. </SplitCardContainer>
  81. );
  82. }
  83. function AccordionWidget({
  84. clickType,
  85. deadOrRage,
  86. header,
  87. }: {
  88. clickType: 'count_dead_clicks' | 'count_rage_clicks';
  89. deadOrRage: 'dead' | 'rage';
  90. header: ReactNode;
  91. }) {
  92. const [selectedListIndex, setSelectListIndex] = useState(-1);
  93. const {isLoading, isError, data} = useDeadRageSelectors({
  94. per_page: 3,
  95. sort: `-${clickType}`,
  96. cursor: undefined,
  97. prefix: 'selector_',
  98. isWidgetData: true,
  99. });
  100. const location = useLocation();
  101. const filteredData = data.filter(d => (d[clickType] ?? 0) > 0);
  102. const clickColor = deadOrRage === 'dead' ? 'yellow300' : 'red300';
  103. return (
  104. <StyledWidgetContainer>
  105. <StyledHeaderContainer>
  106. <IconCursorArrow color={clickColor} />
  107. {header}
  108. </StyledHeaderContainer>
  109. {isLoading ? (
  110. <LoadingContainer>
  111. <StyledPlaceholder />
  112. <StyledPlaceholder />
  113. <StyledPlaceholder />
  114. </LoadingContainer>
  115. ) : isError || (!isLoading && filteredData.length === 0) ? (
  116. <CenteredContentContainer>
  117. <EmptyStateWarning>
  118. <div>{t('No results found')}</div>
  119. <EmptySubtitle>
  120. {tct(
  121. 'There were no [type] clicks within this timeframe. Expand your timeframe, or increase your replay sample rate to see more data.',
  122. {type: deadOrRage}
  123. )}
  124. </EmptySubtitle>
  125. </EmptyStateWarning>
  126. </CenteredContentContainer>
  127. ) : (
  128. <LeftAlignedContentContainer>
  129. <Accordion
  130. buttonOnLeft
  131. collapsible
  132. expandedIndex={selectedListIndex}
  133. setExpandedIndex={setSelectListIndex}
  134. items={filteredData.map(d => {
  135. const selectorQuery = `${deadOrRage}.selector:"${transformSelectorQuery(
  136. d.dom_element.fullSelector
  137. )}"`;
  138. return {
  139. header: () => (
  140. <AccordionItemHeader
  141. count={d[clickType] ?? 0}
  142. selector={d.dom_element.selector}
  143. clickColor={clickColor}
  144. selectorQuery={selectorQuery}
  145. id={d.project_id}
  146. />
  147. ),
  148. content: () => (
  149. <ExampleReplaysList
  150. location={location}
  151. clickType={clickType}
  152. selectorQuery={selectorQuery}
  153. projectId={d.project_id}
  154. />
  155. ),
  156. };
  157. })}
  158. />
  159. </LeftAlignedContentContainer>
  160. )}
  161. <SearchButton
  162. label={t('See all selectors')}
  163. path="selectors"
  164. sort={`-${clickType}`}
  165. />
  166. </StyledWidgetContainer>
  167. );
  168. }
  169. function AccordionItemHeader({
  170. count,
  171. clickColor,
  172. selector,
  173. selectorQuery,
  174. id,
  175. }: {
  176. clickColor: ColorOrAlias;
  177. count: number;
  178. id: number;
  179. selector: string;
  180. selectorQuery: string;
  181. }) {
  182. const clickCount = (
  183. <ClickCount>
  184. <IconCursorArrow size="xs" color={clickColor} />
  185. {count}
  186. </ClickCount>
  187. );
  188. return (
  189. <StyledAccordionHeader>
  190. <SelectorLink
  191. value={selector}
  192. selectorQuery={selectorQuery}
  193. projectId={id.toString()}
  194. />
  195. <RightAlignedCell>
  196. {clickCount}
  197. <ProjectInfo id={id} isWidget />
  198. </RightAlignedCell>
  199. </StyledAccordionHeader>
  200. );
  201. }
  202. function SearchButton({
  203. label,
  204. sort,
  205. path,
  206. ...props
  207. }: {
  208. label: ReactNode;
  209. path: string;
  210. sort: string;
  211. } & Omit<ComponentProps<typeof LinkButton>, 'size' | 'to'>) {
  212. const location = useLocation();
  213. const organization = useOrganization();
  214. return (
  215. <StyledButton
  216. {...props}
  217. size="xs"
  218. to={{
  219. pathname: normalizeUrl(`/organizations/${organization.slug}/replays/${path}/`),
  220. query: {
  221. ...location.query,
  222. sort,
  223. query: undefined,
  224. cursor: undefined,
  225. },
  226. }}
  227. >
  228. {label}
  229. </StyledButton>
  230. );
  231. }
  232. const SplitCardContainer = styled('div')`
  233. display: grid;
  234. grid-template-columns: 1fr 1fr;
  235. grid-template-rows: max-content;
  236. grid-auto-flow: column;
  237. gap: 0 ${space(2)};
  238. align-items: stretch;
  239. `;
  240. const ClickCount = styled(TextOverflow)`
  241. color: ${p => p.theme.gray400};
  242. display: grid;
  243. grid-template-columns: auto auto;
  244. gap: ${space(0.75)};
  245. align-items: center;
  246. `;
  247. const StyledHeaderContainer = styled(HeaderContainer)`
  248. grid-auto-flow: row;
  249. align-items: center;
  250. grid-template-rows: auto;
  251. grid-template-columns: 30px auto;
  252. `;
  253. const LeftAlignedContentContainer = styled(ContentContainer)`
  254. justify-content: flex-start;
  255. `;
  256. const CenteredContentContainer = styled(ContentContainer)`
  257. justify-content: center;
  258. `;
  259. const StyledButton = styled(LinkButton)`
  260. width: 100%;
  261. border-radius: ${p => p.theme.borderRadiusBottom};
  262. padding: ${space(3)};
  263. border-bottom: none;
  264. border-left: none;
  265. border-right: none;
  266. font-size: ${p => p.theme.fontSizeMedium};
  267. `;
  268. const StyledAccordionHeader = styled('div')`
  269. display: grid;
  270. grid-template-columns: 1fr max-content;
  271. flex: 1;
  272. `;
  273. const TitleTooltipContainer = styled('div')`
  274. display: flex;
  275. gap: ${space(1)};
  276. align-items: center;
  277. `;
  278. const StyledWidgetHeader = styled(HeaderTitleLegend)`
  279. display: grid;
  280. justify-content: space-between;
  281. align-items: center;
  282. `;
  283. const StyledWidgetContainer = styled(WidgetContainer)`
  284. margin-bottom: 0;
  285. padding-top: ${space(1.5)};
  286. `;
  287. export const RightAlignedCell = styled('div')`
  288. text-align: right;
  289. display: flex;
  290. align-items: center;
  291. justify-content: center;
  292. gap: ${space(1)};
  293. padding-left: ${space(1)};
  294. `;
  295. const EmptySubtitle = styled('div')`
  296. font-size: ${p => p.theme.fontSizeMedium};
  297. line-height: 1.6em;
  298. padding-left: ${space(1)};
  299. padding-right: ${space(1)};
  300. `;
  301. const LoadingContainer = styled(ContentContainer)`
  302. gap: ${space(0.25)};
  303. padding: ${space(1)} ${space(0.5)} 3px ${space(0.5)};
  304. `;
  305. const StyledPlaceholder = styled(Placeholder)`
  306. height: 34px;
  307. `;
  308. export default DeadRageSelectorCards;