index.tsx 4.5 KB

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