interactionsLandingPage.tsx 5.3 KB

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