projectDetail.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. api: this.api,
  98. orgSlug: organization.slug,
  99. tagKey: key,
  100. search,
  101. projectIds: projectId ? [projectId] : undefined,
  102. endpointParams: 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. size="sm"
  198. to={
  199. // if we are still fetching project, we can use project slug to build issue stream url and let the redirect handle it
  200. project?.id
  201. ? `/organizations/${params.orgId}/issues/?project=${project.id}`
  202. : `/${params.orgId}/${params.projectId}`
  203. }
  204. >
  205. {t('View All Issues')}
  206. </Button>
  207. <CreateAlertButton
  208. size="sm"
  209. organization={organization}
  210. projectSlug={params.projectId}
  211. />
  212. <Button
  213. size="sm"
  214. icon={<IconSettings />}
  215. aria-label={t('Settings')}
  216. to={`/settings/${params.orgId}/projects/${params.projectId}/`}
  217. />
  218. </ButtonBar>
  219. </Layout.HeaderActions>
  220. </Layout.Header>
  221. <Layout.Body noRowGap>
  222. {project && <StyledGlobalEventProcessingAlert projects={[project]} />}
  223. <Layout.Main fullWidth>
  224. <StyledSdkUpdatesAlert />
  225. </Layout.Main>
  226. <StyledGlobalAppStoreConnectUpdateAlert
  227. project={project}
  228. organization={organization}
  229. />
  230. <Layout.Main>
  231. <ProjectFiltersWrapper>
  232. <ProjectFilters
  233. query={query}
  234. onSearch={this.handleSearch}
  235. relativeDateOptions={
  236. hasOnlyBasicChart
  237. ? pick(DEFAULT_RELATIVE_PERIODS, ERRORS_BASIC_CHART_PERIODS)
  238. : undefined
  239. }
  240. tagValueLoader={this.tagValueLoader}
  241. />
  242. </ProjectFiltersWrapper>
  243. <ProjectScoreCards
  244. organization={organization}
  245. isProjectStabilized={isProjectStabilized}
  246. selection={selection}
  247. hasSessions={hasSessions}
  248. hasTransactions={hasTransactions}
  249. query={query}
  250. />
  251. {isProjectStabilized && (
  252. <Fragment>
  253. {visibleCharts.map((id, index) => (
  254. <ProjectCharts
  255. location={location}
  256. organization={organization}
  257. router={router}
  258. key={`project-charts-${id}`}
  259. chartId={id}
  260. chartIndex={index}
  261. projectId={project?.id}
  262. hasSessions={hasSessions}
  263. hasTransactions={!!hasTransactions}
  264. visibleCharts={visibleCharts}
  265. query={query}
  266. />
  267. ))}
  268. <ProjectIssues
  269. organization={organization}
  270. location={location}
  271. projectId={selection.projects[0]}
  272. query={query}
  273. api={this.api}
  274. />
  275. </Fragment>
  276. )}
  277. </Layout.Main>
  278. <Layout.Side>
  279. <ProjectTeamAccess organization={organization} project={project} />
  280. <Feature features={['incidents']} organization={organization}>
  281. <ProjectLatestAlerts
  282. organization={organization}
  283. projectSlug={params.projectId}
  284. location={location}
  285. isProjectStabilized={isProjectStabilized}
  286. />
  287. </Feature>
  288. <ProjectLatestReleases
  289. organization={organization}
  290. projectSlug={params.projectId}
  291. projectId={project?.id}
  292. location={location}
  293. isProjectStabilized={isProjectStabilized}
  294. />
  295. <ProjectQuickLinks
  296. organization={organization}
  297. project={project}
  298. location={location}
  299. />
  300. </Layout.Side>
  301. </Layout.Body>
  302. </StyledPageContent>
  303. </NoProjectMessage>
  304. </PageFiltersContainer>
  305. );
  306. }
  307. }
  308. const StyledPageContent = styled(PageContent)`
  309. padding: 0;
  310. `;
  311. const ProjectFiltersWrapper = styled('div')`
  312. margin-bottom: ${space(2)};
  313. `;
  314. const StyledSdkUpdatesAlert = styled(GlobalSdkUpdateAlert)`
  315. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  316. margin-bottom: ${space(2)};
  317. }
  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));