projectDetail.tsx 12 KB

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