index.tsx 4.4 KB

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