projectDetail.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 skipLoadLastUsed showAbsolute={!hasOnlyBasicChart}>
  170. <NoProjectMessage organization={organization}>
  171. <StyledPageContent>
  172. <Layout.Header>
  173. <Layout.HeaderContent>
  174. <Breadcrumbs
  175. crumbs={[
  176. {
  177. to: `/organizations/${params.orgId}/projects/`,
  178. label: t('Projects'),
  179. },
  180. {label: t('Project Details')},
  181. ]}
  182. />
  183. <Layout.Title>
  184. {project && (
  185. <IdBadge
  186. project={project}
  187. avatarSize={28}
  188. hideOverflow="100%"
  189. disableLink
  190. />
  191. )}
  192. </Layout.Title>
  193. </Layout.HeaderContent>
  194. <Layout.HeaderActions>
  195. <ButtonBar gap={1}>
  196. <Button
  197. to={
  198. // if we are still fetching project, we can use project slug to build issue stream url and let the redirect handle it
  199. project?.id
  200. ? `/organizations/${params.orgId}/issues/?project=${project.id}`
  201. : `/${params.orgId}/${params.projectId}`
  202. }
  203. >
  204. {t('View All Issues')}
  205. </Button>
  206. <CreateAlertButton
  207. organization={organization}
  208. projectSlug={params.projectId}
  209. />
  210. <Button
  211. icon={<IconSettings />}
  212. aria-label={t('Settings')}
  213. to={`/settings/${params.orgId}/projects/${params.projectId}/`}
  214. />
  215. </ButtonBar>
  216. </Layout.HeaderActions>
  217. </Layout.Header>
  218. <Layout.Body noRowGap>
  219. {project && <StyledGlobalEventProcessingAlert projects={[project]} />}
  220. <Layout.Main fullWidth>
  221. <StyledSdkUpdatesAlert />
  222. </Layout.Main>
  223. <StyledGlobalAppStoreConnectUpdateAlert
  224. project={project}
  225. organization={organization}
  226. />
  227. <Layout.Main>
  228. <ProjectFiltersWrapper>
  229. <ProjectFilters
  230. query={query}
  231. onSearch={this.handleSearch}
  232. relativeDateOptions={
  233. hasOnlyBasicChart
  234. ? pick(DEFAULT_RELATIVE_PERIODS, ERRORS_BASIC_CHART_PERIODS)
  235. : undefined
  236. }
  237. tagValueLoader={this.tagValueLoader}
  238. />
  239. </ProjectFiltersWrapper>
  240. <ProjectScoreCards
  241. organization={organization}
  242. isProjectStabilized={isProjectStabilized}
  243. selection={selection}
  244. hasSessions={hasSessions}
  245. hasTransactions={hasTransactions}
  246. query={query}
  247. />
  248. {isProjectStabilized && (
  249. <Fragment>
  250. {visibleCharts.map((id, index) => (
  251. <ProjectCharts
  252. location={location}
  253. organization={organization}
  254. router={router}
  255. key={`project-charts-${id}`}
  256. chartId={id}
  257. chartIndex={index}
  258. projectId={project?.id}
  259. hasSessions={hasSessions}
  260. hasTransactions={!!hasTransactions}
  261. visibleCharts={visibleCharts}
  262. query={query}
  263. />
  264. ))}
  265. <ProjectIssues
  266. organization={organization}
  267. location={location}
  268. projectId={selection.projects[0]}
  269. query={query}
  270. api={this.api}
  271. />
  272. </Fragment>
  273. )}
  274. </Layout.Main>
  275. <Layout.Side>
  276. <ProjectTeamAccess organization={organization} project={project} />
  277. <Feature features={['incidents']} organization={organization}>
  278. <ProjectLatestAlerts
  279. organization={organization}
  280. projectSlug={params.projectId}
  281. location={location}
  282. isProjectStabilized={isProjectStabilized}
  283. />
  284. </Feature>
  285. <ProjectLatestReleases
  286. organization={organization}
  287. projectSlug={params.projectId}
  288. projectId={project?.id}
  289. location={location}
  290. isProjectStabilized={isProjectStabilized}
  291. />
  292. <ProjectQuickLinks
  293. organization={organization}
  294. project={project}
  295. location={location}
  296. />
  297. </Layout.Side>
  298. </Layout.Body>
  299. </StyledPageContent>
  300. </NoProjectMessage>
  301. </PageFiltersContainer>
  302. );
  303. }
  304. }
  305. const StyledPageContent = styled(PageContent)`
  306. padding: 0;
  307. `;
  308. const ProjectFiltersWrapper = styled('div')`
  309. margin-bottom: ${space(2)};
  310. `;
  311. const StyledSdkUpdatesAlert = styled(GlobalSdkUpdateAlert)`
  312. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  313. margin-bottom: ${space(2)};
  314. }
  315. `;
  316. const StyledGlobalEventProcessingAlert = styled(GlobalEventProcessingAlert)`
  317. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  318. margin-bottom: 0;
  319. }
  320. `;
  321. const StyledGlobalAppStoreConnectUpdateAlert = styled(GlobalAppStoreConnectUpdateAlert)`
  322. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  323. margin-bottom: 0;
  324. }
  325. `;
  326. StyledGlobalAppStoreConnectUpdateAlert.defaultProps = {
  327. Wrapper: p => <Layout.Main fullWidth {...p} />,
  328. };
  329. export default withProjects(withPageFilters(ProjectDetail));