projectDetail.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 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 {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 AsyncView from 'sentry/views/asyncView';
  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 = AsyncView['state'];
  52. class ProjectDetail extends AsyncView<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. this.syncProjectWithSlug();
  59. }
  60. componentDidUpdate() {
  61. this.syncProjectWithSlug();
  62. }
  63. get project() {
  64. const {projects, params} = this.props;
  65. return projects.find(p => p.slug === params.projectId);
  66. }
  67. handleProjectChange = (selectedProjects: number[]) => {
  68. const {projects, router, location, organization} = this.props;
  69. const newlySelectedProject = projects.find(p => p.id === String(selectedProjects[0]));
  70. // if we change project in global header, we need to sync the project slug in the URL
  71. if (newlySelectedProject?.id) {
  72. router.replace(
  73. normalizeUrl({
  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. };
  84. handleSearch = (query: string) => {
  85. const {router, location} = this.props;
  86. router.replace({
  87. pathname: location.pathname,
  88. query: {
  89. ...location.query,
  90. query,
  91. },
  92. });
  93. };
  94. tagValueLoader = (key: string, search: string) => {
  95. const {location, organization} = this.props;
  96. const {project: projectId} = location.query;
  97. return fetchTagValues({
  98. api: this.api,
  99. orgSlug: organization.slug,
  100. tagKey: key,
  101. search,
  102. projectIds: projectId ? [projectId] : undefined,
  103. endpointParams: location.query,
  104. });
  105. };
  106. syncProjectWithSlug() {
  107. const {router, location} = this.props;
  108. const projectId = this.project?.id;
  109. if (projectId && projectId !== location.query.project) {
  110. // if someone visits /organizations/sentry/projects/javascript/ (without ?project=XXX) we need to update URL and globalSelection with the right project ID
  111. updateProjects([Number(projectId)], router);
  112. }
  113. }
  114. onRetryProjects = () => {
  115. const {params} = this.props;
  116. fetchOrganizationDetails(this.api, params.orgId, true, false);
  117. };
  118. isProjectStabilized() {
  119. const {selection, location} = this.props;
  120. const projectId = this.project?.id;
  121. return (
  122. defined(projectId) &&
  123. projectId === location.query.project &&
  124. projectId === String(selection.projects[0])
  125. );
  126. }
  127. renderLoading() {
  128. return this.renderBody();
  129. }
  130. renderNoAccess(project: Project) {
  131. const {organization} = this.props;
  132. return (
  133. <Layout.Page>
  134. <MissingProjectMembership organization={organization} project={project} />
  135. </Layout.Page>
  136. );
  137. }
  138. renderProjectNotFound() {
  139. return (
  140. <Layout.Page withPadding>
  141. <LoadingError
  142. message={t('This project could not be found.')}
  143. onRetry={this.onRetryProjects}
  144. />
  145. </Layout.Page>
  146. );
  147. }
  148. renderBody() {
  149. const {organization, params, location, router, loadingProjects, selection} =
  150. this.props;
  151. const project = this.project;
  152. const {query} = location.query;
  153. const hasPerformance = organization.features.includes('performance-view');
  154. const hasDiscover = organization.features.includes('discover-basic');
  155. const hasTransactions = hasPerformance && project?.firstTransactionEvent;
  156. const isProjectStabilized = this.isProjectStabilized();
  157. const visibleCharts = ['chart1'];
  158. const hasSessions = project?.hasSessions ?? null;
  159. const hasOnlyBasicChart = !hasPerformance && !hasDiscover && !hasSessions;
  160. if (hasTransactions || hasSessions) {
  161. visibleCharts.push('chart2');
  162. }
  163. if (!loadingProjects && !project) {
  164. return this.renderProjectNotFound();
  165. }
  166. if (!loadingProjects && project && !project.hasAccess) {
  167. return this.renderNoAccess(project);
  168. }
  169. return (
  170. <PageFiltersContainer
  171. disablePersistence
  172. skipLoadLastUsed
  173. showAbsolute={!hasOnlyBasicChart}
  174. >
  175. <Layout.Page>
  176. <NoProjectMessage organization={organization}>
  177. <Layout.Header>
  178. <Layout.HeaderContent>
  179. <Breadcrumbs
  180. crumbs={[
  181. {
  182. to: `/organizations/${params.orgId}/projects/`,
  183. label: t('Projects'),
  184. },
  185. {label: t('Project Details')},
  186. ]}
  187. />
  188. <Layout.Title>
  189. {project ? (
  190. <IdBadge
  191. project={project}
  192. avatarSize={28}
  193. hideOverflow="100%"
  194. disableLink
  195. hideName
  196. />
  197. ) : null}
  198. {project?.slug}
  199. </Layout.Title>
  200. </Layout.HeaderContent>
  201. <Layout.HeaderActions>
  202. <ButtonBar gap={1}>
  203. <Button
  204. size="sm"
  205. to={
  206. // if we are still fetching project, we can use project slug to build issue stream url and let the redirect handle it
  207. project?.id
  208. ? `/organizations/${params.orgId}/issues/?project=${project.id}`
  209. : `/${params.orgId}/${params.projectId}`
  210. }
  211. >
  212. {t('View All Issues')}
  213. </Button>
  214. <CreateAlertButton
  215. size="sm"
  216. organization={organization}
  217. projectSlug={params.projectId}
  218. aria-label={t('Create Alert')}
  219. />
  220. <Button
  221. size="sm"
  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. <StyledGlobalAppStoreConnectUpdateAlert
  232. project={project}
  233. organization={organization}
  234. />
  235. <Layout.Main>
  236. <ProjectFiltersWrapper>
  237. <ProjectFilters
  238. query={query}
  239. onSearch={this.handleSearch}
  240. relativeDateOptions={
  241. hasOnlyBasicChart
  242. ? pick(DEFAULT_RELATIVE_PERIODS, ERRORS_BASIC_CHART_PERIODS)
  243. : undefined
  244. }
  245. tagValueLoader={this.tagValueLoader}
  246. />
  247. </ProjectFiltersWrapper>
  248. <ProjectScoreCards
  249. organization={organization}
  250. isProjectStabilized={isProjectStabilized}
  251. selection={selection}
  252. hasSessions={hasSessions}
  253. hasTransactions={hasTransactions}
  254. query={query}
  255. project={project}
  256. location={location}
  257. />
  258. {isProjectStabilized && (
  259. <Fragment>
  260. {visibleCharts.map((id, index) => (
  261. <ProjectCharts
  262. location={location}
  263. organization={organization}
  264. router={router}
  265. key={`project-charts-${id}`}
  266. chartId={id}
  267. chartIndex={index}
  268. projectId={project?.id}
  269. hasSessions={hasSessions}
  270. hasTransactions={!!hasTransactions}
  271. visibleCharts={visibleCharts}
  272. query={query}
  273. project={project}
  274. />
  275. ))}
  276. <ProjectIssues
  277. organization={organization}
  278. location={location}
  279. projectId={selection.projects[0]}
  280. query={query}
  281. api={this.api}
  282. />
  283. </Fragment>
  284. )}
  285. </Layout.Main>
  286. <Layout.Side>
  287. <ProjectTeamAccess organization={organization} project={project} />
  288. <Feature features={['incidents']} organization={organization}>
  289. <ProjectLatestAlerts
  290. organization={organization}
  291. projectSlug={params.projectId}
  292. location={location}
  293. isProjectStabilized={isProjectStabilized}
  294. />
  295. </Feature>
  296. <ProjectLatestReleases
  297. organization={organization}
  298. projectSlug={params.projectId}
  299. projectId={project?.id}
  300. location={location}
  301. isProjectStabilized={isProjectStabilized}
  302. />
  303. <ProjectQuickLinks
  304. organization={organization}
  305. project={project}
  306. location={location}
  307. />
  308. </Layout.Side>
  309. </Layout.Body>
  310. </NoProjectMessage>
  311. </Layout.Page>
  312. </PageFiltersContainer>
  313. );
  314. }
  315. }
  316. const ProjectFiltersWrapper = styled('div')`
  317. margin-bottom: ${space(2)};
  318. `;
  319. const StyledGlobalEventProcessingAlert = styled(GlobalEventProcessingAlert)`
  320. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  321. margin-bottom: 0;
  322. }
  323. `;
  324. const StyledGlobalAppStoreConnectUpdateAlert = styled(GlobalAppStoreConnectUpdateAlert)`
  325. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  326. margin-bottom: 0;
  327. }
  328. `;
  329. StyledGlobalAppStoreConnectUpdateAlert.defaultProps = {
  330. Wrapper: p => <Layout.Main fullWidth {...p} />,
  331. };
  332. export default withProjects(withPageFilters(ProjectDetail));