index.tsx 4.5 KB

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