interactionsLandingPage.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import {browserHistory} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  4. import FeatureBadge from 'sentry/components/featureBadge';
  5. import type {ControlProps} from 'sentry/components/forms/controls/selectControl';
  6. import SelectControl from 'sentry/components/forms/controls/selectControl';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  9. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  10. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  11. import {t} from 'sentry/locale';
  12. import {space} from 'sentry/styles/space';
  13. import {useLocation} from 'sentry/utils/useLocation';
  14. import useOrganization from 'sentry/utils/useOrganization';
  15. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  16. import InteractionsTable from 'sentry/views/performance/browser/interactionTable';
  17. import {
  18. BrowserStarfishFields,
  19. useBrowserModuleFilters,
  20. } from 'sentry/views/performance/browser/useBrowserFilters';
  21. import {useBrowserSort} from 'sentry/views/performance/browser/useBrowserSort';
  22. import {useInteractionElementQuery} from 'sentry/views/performance/browser/useInteractionElementQuery';
  23. import {usePagesQuery} from 'sentry/views/performance/browser/usePageQuery';
  24. import {ModulePageProviders} from 'sentry/views/performance/database/modulePageProviders';
  25. const {COMPONENT, PAGE, TRANSACTION_OP} = BrowserStarfishFields;
  26. type Option = {
  27. label: string;
  28. value: string;
  29. };
  30. function InteractionsLandingPage() {
  31. const organization = useOrganization();
  32. const filters = useBrowserModuleFilters();
  33. const sort = useBrowserSort();
  34. return (
  35. <ModulePageProviders title={[t('Performance'), t('Interactions')].join(' — ')}>
  36. <Layout.Header>
  37. <Layout.HeaderContent>
  38. <Breadcrumbs
  39. crumbs={[
  40. {
  41. label: 'Performance',
  42. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  43. preservePageFilters: true,
  44. },
  45. {
  46. label: 'Interactions',
  47. },
  48. ]}
  49. />
  50. <Layout.Title>
  51. {t('Interactions')}
  52. <FeatureBadge type="alpha" />
  53. </Layout.Title>
  54. </Layout.HeaderContent>
  55. </Layout.Header>
  56. <Layout.Body>
  57. <Layout.Main fullWidth>
  58. <PaddedContainer>
  59. <PageFilterBar condensed>
  60. <ProjectPageFilter />
  61. <DatePageFilter />
  62. </PageFilterBar>
  63. </PaddedContainer>
  64. <FilterOptionsContainer>
  65. <ComponentSelector value={filters[COMPONENT] || ''} />
  66. <ActionSelector value={filters[TRANSACTION_OP] || ''} />
  67. <PageSelector value={filters[PAGE] || ''} />
  68. </FilterOptionsContainer>
  69. <InteractionsTable sort={sort} />
  70. </Layout.Main>
  71. </Layout.Body>
  72. </ModulePageProviders>
  73. );
  74. }
  75. function ComponentSelector({value}: {value?: string}) {
  76. const location = useLocation();
  77. const {data, isLoading} = useInteractionElementQuery();
  78. const options: Option[] =
  79. !isLoading && data.length
  80. ? [
  81. {label: 'All', value: ''},
  82. ...data.map(element => ({
  83. label: element,
  84. value: element,
  85. })),
  86. ]
  87. : [];
  88. return (
  89. <SelectControlWithProps
  90. inFieldLabel={`${t('Component')}:`}
  91. options={options}
  92. value={value}
  93. onChange={newValue => {
  94. browserHistory.push({
  95. ...location,
  96. query: {
  97. ...location.query,
  98. [COMPONENT]: newValue?.value,
  99. },
  100. });
  101. }}
  102. />
  103. );
  104. }
  105. function ActionSelector({value}: {value?: string}) {
  106. const location = useLocation();
  107. const options: Option[] = [
  108. {value: '', label: 'All'},
  109. {value: 'ui.action.click', label: 'Click'},
  110. {value: 'ui.action.right.click', label: 'Right Click'},
  111. ];
  112. return (
  113. <SelectControlWithProps
  114. inFieldLabel={`${t('Action')}:`}
  115. options={options}
  116. value={value}
  117. onChange={newValue => {
  118. browserHistory.push({
  119. ...location,
  120. query: {
  121. ...location.query,
  122. [TRANSACTION_OP]: newValue?.value,
  123. },
  124. });
  125. }}
  126. />
  127. );
  128. }
  129. function PageSelector({value}: {value?: string}) {
  130. const location = useLocation();
  131. const {data: pages, isLoading} = usePagesQuery();
  132. const options: Option[] =
  133. !isLoading && pages.length
  134. ? [
  135. {label: 'All', value: ''},
  136. ...pages.map(page => ({
  137. value: page,
  138. label: page,
  139. })),
  140. ]
  141. : [];
  142. return (
  143. <SelectControlWithProps
  144. inFieldLabel={`${t('Page')}:`}
  145. options={options}
  146. value={value}
  147. onChange={newValue => {
  148. browserHistory.push({
  149. ...location,
  150. query: {
  151. ...location.query,
  152. [PAGE]: newValue?.value,
  153. },
  154. });
  155. }}
  156. />
  157. );
  158. }
  159. function SelectControlWithProps(props: ControlProps & {options: Option[]}) {
  160. return <SelectControl {...props} />;
  161. }
  162. export const PaddedContainer = styled('div')`
  163. margin-bottom: ${space(2)};
  164. `;
  165. const FilterOptionsContainer = styled('div')`
  166. display: grid;
  167. grid-template-columns: repeat(3, 1fr);
  168. gap: ${space(2)};
  169. margin-bottom: ${space(2)};
  170. max-width: 800px;
  171. `;
  172. export default InteractionsLandingPage;