aiOverviewPage.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import styled from '@emotion/styled';
  2. import Feature from 'sentry/components/acl/feature';
  3. import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import {NoAccess} from 'sentry/components/noAccess';
  6. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  7. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  8. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  9. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  10. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  11. import TransactionNameSearchBar from 'sentry/components/performance/searchBar';
  12. import * as TeamKeyTransactionManager from 'sentry/components/performance/teamKeyTransactionsManager';
  13. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  14. import {trackAnalytics} from 'sentry/utils/analytics';
  15. import {
  16. canUseMetricsData,
  17. MEPSettingProvider,
  18. useMEPSettingContext,
  19. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  20. import {PageAlert, usePageAlert} from 'sentry/utils/performance/contexts/pageAlert';
  21. import {PerformanceDisplayProvider} from 'sentry/utils/performance/contexts/performanceDisplayContext';
  22. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  23. import {useLocation} from 'sentry/utils/useLocation';
  24. import {useNavigate} from 'sentry/utils/useNavigate';
  25. import useOrganization from 'sentry/utils/useOrganization';
  26. import useProjects from 'sentry/utils/useProjects';
  27. import {useUserTeams} from 'sentry/utils/useUserTeams';
  28. import * as ModuleLayout from 'sentry/views/insights/common/components/moduleLayout';
  29. import {ToolRibbon} from 'sentry/views/insights/common/components/ribbon';
  30. import {ViewTrendsButton} from 'sentry/views/insights/common/components/viewTrendsButton';
  31. import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
  32. import {AiHeader} from 'sentry/views/insights/pages/ai/aiPageHeader';
  33. import {AI_LANDING_TITLE} from 'sentry/views/insights/pages/ai/settings';
  34. import {OVERVIEW_PAGE_TITLE} from 'sentry/views/insights/pages/settings';
  35. import {generateGenericPerformanceEventView} from 'sentry/views/performance/data';
  36. import {TripleChartRow} from 'sentry/views/performance/landing/widgets/components/widgetChartRow';
  37. import {filterAllowedChartsMetrics} from 'sentry/views/performance/landing/widgets/utils';
  38. import {PerformanceWidgetSetting} from 'sentry/views/performance/landing/widgets/widgetDefinitions';
  39. import Onboarding from 'sentry/views/performance/onboarding';
  40. import Table from 'sentry/views/performance/table';
  41. import {
  42. getTransactionSearchQuery,
  43. ProjectPerformanceType,
  44. } from 'sentry/views/performance/utils';
  45. export const AI_COLUMN_TITLES = [
  46. 'transaction',
  47. 'operation',
  48. 'project',
  49. 'tpm',
  50. 'p50()',
  51. 'p75()',
  52. 'p95()',
  53. 'users',
  54. ];
  55. function AiOverviewPage() {
  56. const organization = useOrganization();
  57. const location = useLocation();
  58. const {setPageError} = usePageAlert();
  59. const {projects} = useProjects();
  60. const onboardingProject = useOnboardingProject();
  61. const navigate = useNavigate();
  62. const {teams} = useUserTeams();
  63. const mepSetting = useMEPSettingContext();
  64. const withStaticFilters = canUseMetricsData(organization);
  65. const eventView = generateGenericPerformanceEventView(
  66. location,
  67. withStaticFilters,
  68. organization
  69. );
  70. // TODO - this should come from MetricsField / EAP fields
  71. eventView.fields = [
  72. {field: 'team_key_transaction'},
  73. {field: 'transaction'},
  74. {field: 'transaction.op'},
  75. {field: 'project'},
  76. {field: 'tpm()'},
  77. {field: 'p50(transaction.duration)'},
  78. {field: 'p75(transaction.duration)'},
  79. {field: 'p95(transaction.duration)'},
  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="insights-domain-view"
  125. organization={organization}
  126. renderDisabled={NoAccess}
  127. >
  128. <AiHeader headerTitle={AI_LANDING_TITLE} headerActions={<ViewTrendsButton />} />
  129. <Layout.Body>
  130. <Layout.Main fullWidth>
  131. <ModuleLayout.Layout>
  132. <ModuleLayout.Full>
  133. <ToolRibbon>
  134. <PageFilterBar condensed>
  135. <ProjectPageFilter />
  136. <EnvironmentPageFilter />
  137. <DatePageFilter />
  138. </PageFilterBar>
  139. {!showOnboarding && (
  140. <StyledTransactionNameSearchBar
  141. organization={organization}
  142. eventView={eventView}
  143. onSearch={(query: string) => {
  144. handleSearch(query);
  145. }}
  146. query={getFreeTextFromQuery(derivedQuery)}
  147. />
  148. )}
  149. </ToolRibbon>
  150. </ModuleLayout.Full>
  151. <PageAlert />
  152. <ModuleLayout.Full>
  153. {!showOnboarding && (
  154. <PerformanceDisplayProvider
  155. value={{performanceType: ProjectPerformanceType.ANY}}
  156. >
  157. <TeamKeyTransactionManager.Provider
  158. organization={organization}
  159. teams={teams}
  160. selectedTeams={['myteams']}
  161. selectedProjects={eventView.project.map(String)}
  162. >
  163. <TripleChartRow
  164. allowedCharts={tripleChartRowCharts}
  165. {...sharedProps}
  166. />
  167. <Table
  168. projects={projects}
  169. columnTitles={AI_COLUMN_TITLES}
  170. setError={setPageError}
  171. {...sharedProps}
  172. />
  173. </TeamKeyTransactionManager.Provider>
  174. </PerformanceDisplayProvider>
  175. )}
  176. {showOnboarding && (
  177. <Onboarding project={onboardingProject} organization={organization} />
  178. )}
  179. </ModuleLayout.Full>
  180. </ModuleLayout.Layout>
  181. </Layout.Main>
  182. </Layout.Body>
  183. </Feature>
  184. );
  185. }
  186. function AiOverviewPageWithProviders() {
  187. const organization = useOrganization();
  188. const location = useLocation();
  189. return (
  190. <PageFiltersContainer>
  191. <SentryDocumentTitle title={OVERVIEW_PAGE_TITLE} orgSlug={organization.slug}>
  192. <MEPSettingProvider location={location}>
  193. <AiOverviewPage />
  194. </MEPSettingProvider>
  195. </SentryDocumentTitle>
  196. </PageFiltersContainer>
  197. );
  198. }
  199. const StyledTransactionNameSearchBar = styled(TransactionNameSearchBar)`
  200. flex: 2;
  201. `;
  202. export default AiOverviewPageWithProviders;