projectDetail.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. import {Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import pick from 'lodash/pick';
  5. import {fetchOrganizationDetails} from 'sentry/actionCreators/organization';
  6. import {updateProjects} from 'sentry/actionCreators/pageFilters';
  7. import {fetchTagValues} from 'sentry/actionCreators/tags';
  8. import Feature from 'sentry/components/acl/feature';
  9. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  10. import {Button} from 'sentry/components/button';
  11. import ButtonBar from 'sentry/components/buttonBar';
  12. import CreateAlertButton from 'sentry/components/createAlertButton';
  13. import GlobalAppStoreConnectUpdateAlert from 'sentry/components/globalAppStoreConnectUpdateAlert';
  14. import GlobalEventProcessingAlert from 'sentry/components/globalEventProcessingAlert';
  15. import IdBadge from 'sentry/components/idBadge';
  16. import * as Layout from 'sentry/components/layouts/thirds';
  17. import LoadingError from 'sentry/components/loadingError';
  18. import NoProjectMessage from 'sentry/components/noProjectMessage';
  19. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  20. import MissingProjectMembership from 'sentry/components/projects/missingProjectMembership';
  21. import {DEFAULT_RELATIVE_PERIODS} from 'sentry/constants';
  22. import {IconSettings} from 'sentry/icons';
  23. import {t} from 'sentry/locale';
  24. import {space} from 'sentry/styles/space';
  25. import type {Organization, PageFilters, Project} from 'sentry/types';
  26. import {defined} from 'sentry/utils';
  27. import routeTitleGen from 'sentry/utils/routeTitle';
  28. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  29. import withPageFilters from 'sentry/utils/withPageFilters';
  30. import withProjects from 'sentry/utils/withProjects';
  31. import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
  32. import {ERRORS_BASIC_CHART_PERIODS} from './charts/projectErrorsBasicChart';
  33. import ProjectScoreCards from './projectScoreCards/projectScoreCards';
  34. import ProjectCharts from './projectCharts';
  35. import ProjectFilters from './projectFilters';
  36. import ProjectIssues from './projectIssues';
  37. import ProjectLatestAlerts from './projectLatestAlerts';
  38. import ProjectLatestReleases from './projectLatestReleases';
  39. import ProjectQuickLinks from './projectQuickLinks';
  40. import ProjectTeamAccess from './projectTeamAccess';
  41. type RouteParams = {
  42. orgId: string;
  43. projectId: string;
  44. };
  45. type Props = RouteComponentProps<RouteParams, {}> & {
  46. loadingProjects: boolean;
  47. organization: Organization;
  48. projects: Project[];
  49. selection: PageFilters;
  50. };
  51. type State = DeprecatedAsyncView['state'];
  52. class ProjectDetail extends DeprecatedAsyncView<Props, State> {
  53. getTitle() {
  54. const {params, organization} = this.props;
  55. return routeTitleGen(t('Project %s', params.projectId), organization.slug, false);
  56. }
  57. componentDidMount() {
  58. super.componentDidMount();
  59. this.syncProjectWithSlug();
  60. }
  61. componentDidUpdate() {
  62. this.syncProjectWithSlug();
  63. }
  64. get project() {
  65. const {projects, params} = this.props;
  66. return projects.find(p => p.slug === params.projectId);
  67. }
  68. handleProjectChange = (selectedProjects: number[]) => {
  69. const {projects, router, location, organization} = this.props;
  70. const newlySelectedProject = projects.find(p => p.id === String(selectedProjects[0]));
  71. // if we change project in global header, we need to sync the project slug in the URL
  72. if (newlySelectedProject?.id) {
  73. router.replace(
  74. normalizeUrl({
  75. pathname: `/organizations/${organization.slug}/projects/${newlySelectedProject.slug}/`,
  76. query: {
  77. ...location.query,
  78. project: newlySelectedProject.id,
  79. environment: undefined,
  80. },
  81. })
  82. );
  83. }
  84. };
  85. handleSearch = (query: string) => {
  86. const {router, location} = this.props;
  87. router.replace({
  88. pathname: location.pathname,
  89. query: {
  90. ...location.query,
  91. query,
  92. },
  93. });
  94. };
  95. tagValueLoader = (key: string, search: string) => {
  96. const {location, organization} = this.props;
  97. const {project: projectId} = location.query;
  98. return fetchTagValues({
  99. api: this.api,
  100. orgSlug: organization.slug,
  101. tagKey: key,
  102. search,
  103. projectIds: projectId ? [projectId] : undefined,
  104. endpointParams: location.query,
  105. });
  106. };
  107. syncProjectWithSlug() {
  108. const {router, location} = this.props;
  109. const projectId = this.project?.id;
  110. if (projectId && projectId !== location.query.project) {
  111. // if someone visits /organizations/sentry/projects/javascript/ (without ?project=XXX) we need to update URL and globalSelection with the right project ID
  112. updateProjects([Number(projectId)], router);
  113. }
  114. }
  115. onRetryProjects = () => {
  116. const {params} = this.props;
  117. fetchOrganizationDetails(this.api, params.orgId, true, false);
  118. };
  119. isProjectStabilized() {
  120. const {selection, location} = this.props;
  121. const projectId = this.project?.id;
  122. return (
  123. defined(projectId) &&
  124. projectId === location.query.project &&
  125. projectId === String(selection.projects[0])
  126. );
  127. }
  128. renderLoading() {
  129. return this.renderBody();
  130. }
  131. renderNoAccess(project: Project) {
  132. const {organization} = this.props;
  133. return (
  134. <Layout.Page>
  135. <MissingProjectMembership organization={organization} project={project} />
  136. </Layout.Page>
  137. );
  138. }
  139. renderProjectNotFound() {
  140. return (
  141. <Layout.Page withPadding>
  142. <LoadingError
  143. message={t('This project could not be found.')}
  144. onRetry={this.onRetryProjects}
  145. />
  146. </Layout.Page>
  147. );
  148. }
  149. renderBody() {
  150. const {organization, params, location, router, loadingProjects, selection} =
  151. this.props;
  152. const project = this.project;
  153. const {query} = location.query;
  154. const hasPerformance = organization.features.includes('performance-view');
  155. const hasDiscover = organization.features.includes('discover-basic');
  156. const hasTransactions = hasPerformance && project?.firstTransactionEvent;
  157. const isProjectStabilized = this.isProjectStabilized();
  158. const visibleCharts = ['chart1'];
  159. const hasSessions = project?.hasSessions ?? null;
  160. const hasOnlyBasicChart = !hasPerformance && !hasDiscover && !hasSessions;
  161. if (hasTransactions || hasSessions) {
  162. visibleCharts.push('chart2');
  163. }
  164. if (!loadingProjects && !project) {
  165. return this.renderProjectNotFound();
  166. }
  167. if (!loadingProjects && project && !project.hasAccess) {
  168. return this.renderNoAccess(project);
  169. }
  170. return (
  171. <PageFiltersContainer
  172. disablePersistence
  173. skipLoadLastUsed
  174. showAbsolute={!hasOnlyBasicChart}
  175. >
  176. <Layout.Page>
  177. <NoProjectMessage organization={organization}>
  178. <Layout.Header>
  179. <Layout.HeaderContent>
  180. <Breadcrumbs
  181. crumbs={[
  182. {
  183. to: `/organizations/${params.orgId}/projects/`,
  184. label: t('Projects'),
  185. },
  186. {label: t('Project Details')},
  187. ]}
  188. />
  189. <Layout.Title>
  190. {project ? (
  191. <IdBadge
  192. project={project}
  193. avatarSize={28}
  194. hideOverflow="100%"
  195. disableLink
  196. hideName
  197. />
  198. ) : null}
  199. {project?.slug}
  200. </Layout.Title>
  201. </Layout.HeaderContent>
  202. <Layout.HeaderActions>
  203. <ButtonBar gap={1}>
  204. <Button
  205. size="sm"
  206. to={
  207. // if we are still fetching project, we can use project slug to build issue stream url and let the redirect handle it
  208. project?.id
  209. ? `/organizations/${params.orgId}/issues/?project=${project.id}`
  210. : `/${params.orgId}/${params.projectId}`
  211. }
  212. >
  213. {t('View All Issues')}
  214. </Button>
  215. <CreateAlertButton
  216. size="sm"
  217. organization={organization}
  218. projectSlug={params.projectId}
  219. aria-label={t('Create Alert')}
  220. />
  221. <Button
  222. size="sm"
  223. icon={<IconSettings />}
  224. aria-label={t('Settings')}
  225. to={`/settings/${params.orgId}/projects/${params.projectId}/`}
  226. />
  227. </ButtonBar>
  228. </Layout.HeaderActions>
  229. </Layout.Header>
  230. <Layout.Body noRowGap>
  231. {project && <StyledGlobalEventProcessingAlert projects={[project]} />}
  232. <StyledGlobalAppStoreConnectUpdateAlert
  233. project={project}
  234. organization={organization}
  235. />
  236. <Layout.Main>
  237. <ProjectFiltersWrapper>
  238. <ProjectFilters
  239. query={query}
  240. onSearch={this.handleSearch}
  241. relativeDateOptions={
  242. hasOnlyBasicChart
  243. ? pick(DEFAULT_RELATIVE_PERIODS, ERRORS_BASIC_CHART_PERIODS)
  244. : undefined
  245. }
  246. tagValueLoader={this.tagValueLoader}
  247. />
  248. </ProjectFiltersWrapper>
  249. <ProjectScoreCards
  250. organization={organization}
  251. isProjectStabilized={isProjectStabilized}
  252. selection={selection}
  253. hasSessions={hasSessions}
  254. hasTransactions={hasTransactions}
  255. query={query}
  256. project={project}
  257. location={location}
  258. />
  259. {isProjectStabilized && (
  260. <Fragment>
  261. {visibleCharts.map((id, index) => (
  262. <ProjectCharts
  263. location={location}
  264. organization={organization}
  265. router={router}
  266. key={`project-charts-${id}`}
  267. chartId={id}
  268. chartIndex={index}
  269. projectId={project?.id}
  270. hasSessions={hasSessions}
  271. hasTransactions={!!hasTransactions}
  272. visibleCharts={visibleCharts}
  273. query={query}
  274. project={project}
  275. />
  276. ))}
  277. <ProjectIssues
  278. organization={organization}
  279. location={location}
  280. projectId={selection.projects[0]}
  281. query={query}
  282. api={this.api}
  283. />
  284. </Fragment>
  285. )}
  286. </Layout.Main>
  287. <Layout.Side>
  288. <ProjectTeamAccess organization={organization} project={project} />
  289. <Feature features="incidents" organization={organization}>
  290. <ProjectLatestAlerts
  291. organization={organization}
  292. projectSlug={params.projectId}
  293. location={location}
  294. isProjectStabilized={isProjectStabilized}
  295. />
  296. </Feature>
  297. <ProjectLatestReleases
  298. organization={organization}
  299. projectSlug={params.projectId}
  300. projectId={project?.id}
  301. location={location}
  302. isProjectStabilized={isProjectStabilized}
  303. />
  304. <ProjectQuickLinks
  305. organization={organization}
  306. project={project}
  307. location={location}
  308. />
  309. </Layout.Side>
  310. </Layout.Body>
  311. </NoProjectMessage>
  312. </Layout.Page>
  313. </PageFiltersContainer>
  314. );
  315. }
  316. }
  317. const ProjectFiltersWrapper = styled('div')`
  318. margin-bottom: ${space(2)};
  319. `;
  320. const StyledGlobalEventProcessingAlert = styled(GlobalEventProcessingAlert)`
  321. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  322. margin-bottom: 0;
  323. }
  324. `;
  325. const StyledGlobalAppStoreConnectUpdateAlert = styled(GlobalAppStoreConnectUpdateAlert)`
  326. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  327. margin-bottom: 0;
  328. }
  329. `;
  330. StyledGlobalAppStoreConnectUpdateAlert.defaultProps = {
  331. Wrapper: p => <Layout.Main fullWidth {...p} />,
  332. };
  333. export default withProjects(withPageFilters(ProjectDetail));