projectDetail.tsx 12 KB

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