index.tsx 4.5 KB

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