deadRageSelectorCards.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import {ComponentProps, Fragment, ReactNode} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import {LinkButton} from 'sentry/components/button';
  5. import {IconCursorArrow, IconShow} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import useDeadRageSelectors from 'sentry/utils/replays/hooks/useDeadRageSelectors';
  9. import {useLocation} from 'sentry/utils/useLocation';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  12. import SelectorTable from 'sentry/views/replays/deadRageClick/selectorTable';
  13. function DeadRageSelectorCards() {
  14. const location = useLocation();
  15. return (
  16. <SplitCardContainer>
  17. <DeadClickTable location={location} />
  18. <RageClickTable location={location} />
  19. </SplitCardContainer>
  20. );
  21. }
  22. function DeadClickTable({location}: {location: Location<any>}) {
  23. const {isLoading, isError, data} = useDeadRageSelectors({
  24. per_page: 4,
  25. sort: '-count_dead_clicks',
  26. cursor: undefined,
  27. prefix: 'selector_',
  28. });
  29. return (
  30. <SelectorTable
  31. data={data}
  32. isError={isError}
  33. isLoading={isLoading}
  34. location={location}
  35. clickCountColumn={{key: 'count_dead_clicks', name: 'dead clicks'}}
  36. title={
  37. <Fragment>
  38. <IconContainer>
  39. <IconCursorArrow size="xs" color="yellow300" />
  40. </IconContainer>
  41. {t('Most Dead Clicks')}
  42. </Fragment>
  43. }
  44. headerButtons={
  45. <SearchButton
  46. label={t('Show all')}
  47. sort="-count_dead_clicks"
  48. path="dead-clicks"
  49. />
  50. }
  51. customHandleResize={() => {}}
  52. />
  53. );
  54. }
  55. function RageClickTable({location}: {location: Location<any>}) {
  56. const {isLoading, isError, data} = useDeadRageSelectors({
  57. per_page: 4,
  58. sort: '-count_rage_clicks',
  59. cursor: undefined,
  60. prefix: 'selector_',
  61. });
  62. return (
  63. <SelectorTable
  64. data={data}
  65. isError={isError}
  66. isLoading={isLoading}
  67. location={location}
  68. clickCountColumn={{key: 'count_rage_clicks', name: 'rage clicks'}}
  69. title={
  70. <Fragment>
  71. <IconContainer>
  72. <IconCursorArrow size="xs" color="red300" />
  73. </IconContainer>
  74. {t('Most Rage Clicks')}
  75. </Fragment>
  76. }
  77. headerButtons={
  78. <SearchButton
  79. label={t('Show all')}
  80. sort="-count_rage_clicks"
  81. path="rage-clicks"
  82. />
  83. }
  84. customHandleResize={() => {}}
  85. />
  86. );
  87. }
  88. function SearchButton({
  89. label,
  90. sort,
  91. path,
  92. ...props
  93. }: {
  94. label: ReactNode;
  95. path: string;
  96. sort: string;
  97. } & Omit<ComponentProps<typeof LinkButton>, 'size' | 'to'>) {
  98. const location = useLocation();
  99. const organization = useOrganization();
  100. return (
  101. <LinkButton
  102. {...props}
  103. size="xs"
  104. to={{
  105. pathname: normalizeUrl(`/organizations/${organization.slug}/replays/${path}/`),
  106. query: {
  107. ...location.query,
  108. sort,
  109. query: undefined,
  110. cursor: undefined,
  111. },
  112. }}
  113. icon={<IconShow size="xs" />}
  114. >
  115. {label}
  116. </LinkButton>
  117. );
  118. }
  119. const SplitCardContainer = styled('div')`
  120. display: grid;
  121. grid-template-columns: 1fr 1fr;
  122. grid-template-rows: max-content max-content;
  123. grid-auto-flow: column;
  124. gap: 0 ${space(2)};
  125. align-items: stretch;
  126. padding-top: ${space(1)};
  127. `;
  128. const IconContainer = styled('span')`
  129. margin-right: ${space(1)};
  130. `;
  131. export default DeadRageSelectorCards;