aiOverviewPage.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Feature from 'sentry/components/acl/feature';
  4. import FeatureBadge from 'sentry/components/badge/featureBadge';
  5. import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  6. import * as Layout from 'sentry/components/layouts/thirds';
  7. import {NoAccess} from 'sentry/components/noAccess';
  8. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  9. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  10. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  11. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  12. import TransactionNameSearchBar from 'sentry/components/performance/searchBar';
  13. import * as TeamKeyTransactionManager from 'sentry/components/performance/teamKeyTransactionsManager';
  14. import {trackAnalytics} from 'sentry/utils/analytics';
  15. import {
  16. canUseMetricsData,
  17. useMEPSettingContext,
  18. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  19. import {PageAlert, usePageAlert} from 'sentry/utils/performance/contexts/pageAlert';
  20. import {PerformanceDisplayProvider} from 'sentry/utils/performance/contexts/performanceDisplayContext';
  21. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  22. import {useLocation} from 'sentry/utils/useLocation';
  23. import {useNavigate} from 'sentry/utils/useNavigate';
  24. import useOrganization from 'sentry/utils/useOrganization';
  25. import useProjects from 'sentry/utils/useProjects';
  26. import {useUserTeams} from 'sentry/utils/useUserTeams';
  27. import * as ModuleLayout from 'sentry/views/insights/common/components/moduleLayout';
  28. import {ToolRibbon} from 'sentry/views/insights/common/components/ribbon';
  29. import {ViewTrendsButton} from 'sentry/views/insights/common/components/viewTrendsButton';
  30. import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
  31. import {AiHeader} from 'sentry/views/insights/pages/ai/aiPageHeader';
  32. import {
  33. AI_LANDING_TITLE,
  34. AI_RELEASE_LEVEL,
  35. } from 'sentry/views/insights/pages/ai/settings';
  36. import {DomainOverviewPageProviders} from 'sentry/views/insights/pages/domainOverviewPageProviders';
  37. import {generateGenericPerformanceEventView} from 'sentry/views/performance/data';
  38. import {TripleChartRow} from 'sentry/views/performance/landing/widgets/components/widgetChartRow';
  39. import {filterAllowedChartsMetrics} from 'sentry/views/performance/landing/widgets/utils';
  40. import {PerformanceWidgetSetting} from 'sentry/views/performance/landing/widgets/widgetDefinitions';
  41. import Onboarding from 'sentry/views/performance/onboarding';
  42. import Table from 'sentry/views/performance/table';
  43. import {
  44. getTransactionSearchQuery,
  45. ProjectPerformanceType,
  46. } from 'sentry/views/performance/utils';
  47. export const AI_COLUMN_TITLES = [
  48. 'transaction',
  49. 'operation',
  50. 'project',
  51. 'tpm',
  52. 'p50()',
  53. 'p95()',
  54. 'users',
  55. ];
  56. function AiOverviewPage() {
  57. const organization = useOrganization();
  58. const location = useLocation();
  59. const {setPageError} = usePageAlert();
  60. const {projects} = useProjects();
  61. const onboardingProject = useOnboardingProject();
  62. const navigate = useNavigate();
  63. const {teams} = useUserTeams();
  64. const mepSetting = useMEPSettingContext();
  65. const withStaticFilters = canUseMetricsData(organization);
  66. const eventView = generateGenericPerformanceEventView(
  67. location,
  68. withStaticFilters,
  69. organization
  70. );
  71. // TODO - this should come from MetricsField / EAP fields
  72. eventView.fields = [
  73. {field: 'team_key_transaction'},
  74. {field: 'transaction'},
  75. {field: 'transaction.op'},
  76. {field: 'project'},
  77. {field: 'tpm()'},
  78. {field: 'p50()'},
  79. {field: 'p95()'},
  80. ].map(field => ({...field, width: COL_WIDTH_UNDEFINED}));
  81. const showOnboarding = onboardingProject !== undefined;
  82. const tripleChartRowCharts = filterAllowedChartsMetrics(
  83. organization,
  84. [
  85. PerformanceWidgetSetting.TPM_AREA,
  86. PerformanceWidgetSetting.DURATION_HISTOGRAM,
  87. PerformanceWidgetSetting.P50_DURATION_AREA,
  88. PerformanceWidgetSetting.P75_DURATION_AREA,
  89. PerformanceWidgetSetting.P95_DURATION_AREA,
  90. PerformanceWidgetSetting.P99_DURATION_AREA,
  91. PerformanceWidgetSetting.FAILURE_RATE_AREA,
  92. ],
  93. mepSetting
  94. );
  95. const sharedProps = {eventView, location, organization, withStaticFilters};
  96. const getFreeTextFromQuery = (query: string) => {
  97. const conditions = new MutableSearch(query);
  98. const transactionValues = conditions.getFilterValues('transaction');
  99. if (transactionValues.length) {
  100. return transactionValues[0];
  101. }
  102. if (conditions.freeText.length > 0) {
  103. // raw text query will be wrapped in wildcards in generatePerformanceEventView
  104. // so no need to wrap it here
  105. return conditions.freeText.join(' ');
  106. }
  107. return '';
  108. };
  109. function handleSearch(searchQuery: string) {
  110. trackAnalytics('performance.domains.ai.search', {organization});
  111. navigate({
  112. pathname: location.pathname,
  113. query: {
  114. ...location.query,
  115. cursor: undefined,
  116. query: String(searchQuery).trim() || undefined,
  117. isDefaultQuery: false,
  118. },
  119. });
  120. }
  121. const derivedQuery = getTransactionSearchQuery(location, eventView.query);
  122. return (
  123. <Feature
  124. features="performance-view"
  125. organization={organization}
  126. renderDisabled={NoAccess}
  127. >
  128. <AiHeader
  129. headerTitle={
  130. <Fragment>
  131. {AI_LANDING_TITLE}
  132. <FeatureBadge type={AI_RELEASE_LEVEL} />
  133. </Fragment>
  134. }
  135. headerActions={<ViewTrendsButton />}
  136. />
  137. <Layout.Body>
  138. <Layout.Main fullWidth>
  139. <ModuleLayout.Layout>
  140. <ModuleLayout.Full>
  141. <ToolRibbon>
  142. <PageFilterBar condensed>
  143. <ProjectPageFilter />
  144. <EnvironmentPageFilter />
  145. <DatePageFilter />
  146. </PageFilterBar>
  147. {!showOnboarding && (
  148. <StyledTransactionNameSearchBar
  149. organization={organization}
  150. eventView={eventView}
  151. onSearch={(query: string) => {
  152. handleSearch(query);
  153. }}
  154. query={getFreeTextFromQuery(derivedQuery)}
  155. />
  156. )}
  157. </ToolRibbon>
  158. </ModuleLayout.Full>
  159. <PageAlert />
  160. <ModuleLayout.Full>
  161. {!showOnboarding && (
  162. <PerformanceDisplayProvider
  163. value={{performanceType: ProjectPerformanceType.ANY}}
  164. >
  165. <TeamKeyTransactionManager.Provider
  166. organization={organization}
  167. teams={teams}
  168. selectedTeams={['myteams']}
  169. selectedProjects={eventView.project.map(String)}
  170. >
  171. <TripleChartRow
  172. allowedCharts={tripleChartRowCharts}
  173. {...sharedProps}
  174. />
  175. <Table
  176. projects={projects}
  177. columnTitles={AI_COLUMN_TITLES}
  178. setError={setPageError}
  179. {...sharedProps}
  180. />
  181. </TeamKeyTransactionManager.Provider>
  182. </PerformanceDisplayProvider>
  183. )}
  184. {showOnboarding && (
  185. <Onboarding project={onboardingProject} organization={organization} />
  186. )}
  187. </ModuleLayout.Full>
  188. </ModuleLayout.Layout>
  189. </Layout.Main>
  190. </Layout.Body>
  191. </Feature>
  192. );
  193. }
  194. function AiOverviewPageWithProviders() {
  195. return (
  196. <DomainOverviewPageProviders>
  197. <AiOverviewPage />
  198. </DomainOverviewPageProviders>
  199. );
  200. }
  201. const StyledTransactionNameSearchBar = styled(TransactionNameSearchBar)`
  202. flex: 2;
  203. `;
  204. export default AiOverviewPageWithProviders;