index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import {Component} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import {browserHistory} from 'react-router';
  4. import isEqual from 'lodash/isEqual';
  5. import {loadOrganizationTags} from 'sentry/actionCreators/tags';
  6. import type {Client} from 'sentry/api';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  9. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  10. import {t} from 'sentry/locale';
  11. import type {Organization, PageFilters, Project} from 'sentry/types';
  12. import {trackAnalytics} from 'sentry/utils/analytics';
  13. import type EventView from 'sentry/utils/discover/eventView';
  14. import {WebVital} from 'sentry/utils/fields';
  15. import {PerformanceEventViewProvider} from 'sentry/utils/performance/contexts/performanceEventViewContext';
  16. import {decodeScalar} from 'sentry/utils/queryString';
  17. import withApi from 'sentry/utils/withApi';
  18. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  19. import withOrganization from 'sentry/utils/withOrganization';
  20. import withPageFilters from 'sentry/utils/withPageFilters';
  21. import withProjects from 'sentry/utils/withProjects';
  22. import {generatePerformanceVitalDetailView} from '../data';
  23. import {
  24. addRoutePerformanceContext,
  25. getSelectedProjectPlatforms,
  26. getTransactionName,
  27. } from '../utils';
  28. import VitalDetailContent from './vitalDetailContent';
  29. type Props = RouteComponentProps<{}, {}> & {
  30. api: Client;
  31. loadingProjects: boolean;
  32. organization: Organization;
  33. projects: Project[];
  34. selection: PageFilters;
  35. };
  36. type State = {
  37. eventView: EventView;
  38. };
  39. class VitalDetail extends Component<Props, State> {
  40. state: State = {
  41. eventView: generatePerformanceVitalDetailView(
  42. this.props.location,
  43. this.props.organization
  44. ),
  45. };
  46. static getDerivedStateFromProps(nextProps: Readonly<Props>, prevState: State): State {
  47. return {
  48. ...prevState,
  49. eventView: generatePerformanceVitalDetailView(
  50. nextProps.location,
  51. nextProps.organization
  52. ),
  53. };
  54. }
  55. componentDidMount() {
  56. const {api, organization, selection, location, projects} = this.props;
  57. loadOrganizationTags(api, organization.slug, selection);
  58. addRoutePerformanceContext(selection);
  59. trackAnalytics('performance_views.vital_detail.view', {
  60. organization,
  61. project_platforms: getSelectedProjectPlatforms(location, projects),
  62. });
  63. }
  64. componentDidUpdate(prevProps: Props) {
  65. const {api, organization, selection} = this.props;
  66. if (
  67. !isEqual(prevProps.selection.projects, selection.projects) ||
  68. !isEqual(prevProps.selection.datetime, selection.datetime)
  69. ) {
  70. loadOrganizationTags(api, organization.slug, selection);
  71. addRoutePerformanceContext(selection);
  72. }
  73. }
  74. getDocumentTitle(): string {
  75. const name = getTransactionName(this.props.location);
  76. const hasTransactionName = typeof name === 'string' && String(name).trim().length > 0;
  77. if (hasTransactionName) {
  78. return [String(name).trim(), t('Performance')].join(' — ');
  79. }
  80. return [t('Vital Detail'), t('Performance')].join(' — ');
  81. }
  82. render() {
  83. const {organization, location, router, api} = this.props;
  84. const {eventView} = this.state;
  85. if (!eventView) {
  86. browserHistory.replace(
  87. normalizeUrl({
  88. pathname: `/organizations/${organization.slug}/performance/`,
  89. query: {
  90. ...location.query,
  91. },
  92. })
  93. );
  94. return null;
  95. }
  96. const vitalNameQuery = decodeScalar(location.query.vitalName);
  97. const vitalName = !Object.values(WebVital).includes(vitalNameQuery as WebVital)
  98. ? undefined
  99. : (vitalNameQuery as WebVital);
  100. return (
  101. <SentryDocumentTitle title={this.getDocumentTitle()} orgSlug={organization.slug}>
  102. <PerformanceEventViewProvider value={{eventView: this.state.eventView}}>
  103. <PageFiltersContainer>
  104. <Layout.Page>
  105. <VitalDetailContent
  106. location={location}
  107. organization={organization}
  108. eventView={eventView}
  109. router={router}
  110. vitalName={vitalName || WebVital.LCP}
  111. api={api}
  112. />
  113. </Layout.Page>
  114. </PageFiltersContainer>
  115. </PerformanceEventViewProvider>
  116. </SentryDocumentTitle>
  117. );
  118. }
  119. }
  120. export default withApi(withPageFilters(withProjects(withOrganization(VitalDetail))));