aiOverviewPage.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. 'p75()',
  54. 'p95()',
  55. 'users',
  56. ];
  57. function AiOverviewPage() {
  58. const organization = useOrganization();
  59. const location = useLocation();
  60. const {setPageError} = usePageAlert();
  61. const {projects} = useProjects();
  62. const onboardingProject = useOnboardingProject();
  63. const navigate = useNavigate();
  64. const {teams} = useUserTeams();
  65. const mepSetting = useMEPSettingContext();
  66. const withStaticFilters = canUseMetricsData(organization);
  67. const eventView = generateGenericPerformanceEventView(
  68. location,
  69. withStaticFilters,
  70. organization
  71. );
  72. // TODO - this should come from MetricsField / EAP fields
  73. eventView.fields = [
  74. {field: 'team_key_transaction'},
  75. {field: 'transaction'},
  76. {field: 'transaction.op'},
  77. {field: 'project'},
  78. {field: 'tpm()'},
  79. {field: 'p50(transaction.duration)'},
  80. {field: 'p75(transaction.duration)'},
  81. {field: 'p95(transaction.duration)'},
  82. ].map(field => ({...field, width: COL_WIDTH_UNDEFINED}));
  83. const showOnboarding = onboardingProject !== undefined;
  84. const tripleChartRowCharts = filterAllowedChartsMetrics(
  85. organization,
  86. [
  87. PerformanceWidgetSetting.TPM_AREA,
  88. PerformanceWidgetSetting.DURATION_HISTOGRAM,
  89. PerformanceWidgetSetting.P50_DURATION_AREA,
  90. PerformanceWidgetSetting.P75_DURATION_AREA,
  91. PerformanceWidgetSetting.P95_DURATION_AREA,
  92. PerformanceWidgetSetting.P99_DURATION_AREA,
  93. PerformanceWidgetSetting.FAILURE_RATE_AREA,
  94. ],
  95. mepSetting
  96. );
  97. const sharedProps = {eventView, location, organization, withStaticFilters};
  98. const getFreeTextFromQuery = (query: string) => {
  99. const conditions = new MutableSearch(query);
  100. const transactionValues = conditions.getFilterValues('transaction');
  101. if (transactionValues.length) {
  102. return transactionValues[0];
  103. }
  104. if (conditions.freeText.length > 0) {
  105. // raw text query will be wrapped in wildcards in generatePerformanceEventView
  106. // so no need to wrap it here
  107. return conditions.freeText.join(' ');
  108. }
  109. return '';
  110. };
  111. function handleSearch(searchQuery: string) {
  112. trackAnalytics('performance.domains.ai.search', {organization});
  113. navigate({
  114. pathname: location.pathname,
  115. query: {
  116. ...location.query,
  117. cursor: undefined,
  118. query: String(searchQuery).trim() || undefined,
  119. isDefaultQuery: false,
  120. },
  121. });
  122. }
  123. const derivedQuery = getTransactionSearchQuery(location, eventView.query);
  124. return (
  125. <Feature
  126. features="insights-domain-view"
  127. organization={organization}
  128. renderDisabled={NoAccess}
  129. >
  130. <AiHeader
  131. headerTitle={
  132. <Fragment>
  133. {AI_LANDING_TITLE}
  134. <FeatureBadge type={AI_RELEASE_LEVEL} />
  135. </Fragment>
  136. }
  137. headerActions={<ViewTrendsButton />}
  138. />
  139. <Layout.Body>
  140. <Layout.Main fullWidth>
  141. <ModuleLayout.Layout>
  142. <ModuleLayout.Full>
  143. <ToolRibbon>
  144. <PageFilterBar condensed>
  145. <ProjectPageFilter />
  146. <EnvironmentPageFilter />
  147. <DatePageFilter />
  148. </PageFilterBar>
  149. {!showOnboarding && (
  150. <StyledTransactionNameSearchBar
  151. organization={organization}
  152. eventView={eventView}
  153. onSearch={(query: string) => {
  154. handleSearch(query);
  155. }}
  156. query={getFreeTextFromQuery(derivedQuery)}
  157. />
  158. )}
  159. </ToolRibbon>
  160. </ModuleLayout.Full>
  161. <PageAlert />
  162. <ModuleLayout.Full>
  163. {!showOnboarding && (
  164. <PerformanceDisplayProvider
  165. value={{performanceType: ProjectPerformanceType.ANY}}
  166. >
  167. <TeamKeyTransactionManager.Provider
  168. organization={organization}
  169. teams={teams}
  170. selectedTeams={['myteams']}
  171. selectedProjects={eventView.project.map(String)}
  172. >
  173. <TripleChartRow
  174. allowedCharts={tripleChartRowCharts}
  175. {...sharedProps}
  176. />
  177. <Table
  178. projects={projects}
  179. columnTitles={AI_COLUMN_TITLES}
  180. setError={setPageError}
  181. {...sharedProps}
  182. />
  183. </TeamKeyTransactionManager.Provider>
  184. </PerformanceDisplayProvider>
  185. )}
  186. {showOnboarding && (
  187. <Onboarding project={onboardingProject} organization={organization} />
  188. )}
  189. </ModuleLayout.Full>
  190. </ModuleLayout.Layout>
  191. </Layout.Main>
  192. </Layout.Body>
  193. </Feature>
  194. );
  195. }
  196. function AiOverviewPageWithProviders() {
  197. return (
  198. <DomainOverviewPageProviders>
  199. <AiOverviewPage />
  200. </DomainOverviewPageProviders>
  201. );
  202. }
  203. const StyledTransactionNameSearchBar = styled(TransactionNameSearchBar)`
  204. flex: 2;
  205. `;
  206. export default AiOverviewPageWithProviders;