aiOverviewPage.tsx 7.9 KB

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