projectDetail.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import {Fragment, useCallback, useEffect, useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import pick from 'lodash/pick';
  4. import {fetchOrganizationDetails} from 'sentry/actionCreators/organization';
  5. import {updateProjects} from 'sentry/actionCreators/pageFilters';
  6. import {fetchTagValues} from 'sentry/actionCreators/tags';
  7. import Feature from 'sentry/components/acl/feature';
  8. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  9. import {LinkButton} from 'sentry/components/button';
  10. import ButtonBar from 'sentry/components/buttonBar';
  11. import CreateAlertButton from 'sentry/components/createAlertButton';
  12. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  13. import GlobalEventProcessingAlert from 'sentry/components/globalEventProcessingAlert';
  14. import IdBadge from 'sentry/components/idBadge';
  15. import * as Layout from 'sentry/components/layouts/thirds';
  16. import LoadingError from 'sentry/components/loadingError';
  17. import NoProjectMessage from 'sentry/components/noProjectMessage';
  18. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  19. import MissingProjectMembership from 'sentry/components/projects/missingProjectMembership';
  20. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  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 type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  26. import type {Organization} from 'sentry/types/organization';
  27. import {defined} from 'sentry/utils';
  28. import routeTitleGen from 'sentry/utils/routeTitle';
  29. import useApi from 'sentry/utils/useApi';
  30. import usePageFilters from 'sentry/utils/usePageFilters';
  31. import {useParams} from 'sentry/utils/useParams';
  32. import useProjects from 'sentry/utils/useProjects';
  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. organization: Organization;
  48. };
  49. export default function ProjectDetail({router, location, organization}: Props) {
  50. const api = useApi();
  51. const params = useParams();
  52. const {projects, fetching: loadingProjects} = useProjects();
  53. const {selection} = usePageFilters();
  54. const project = projects.find(p => p.slug === params.projectId);
  55. const {query} = location.query;
  56. const hasPerformance = organization.features.includes('performance-view');
  57. const hasDiscover = organization.features.includes('discover-basic');
  58. const hasTransactions = hasPerformance && project?.firstTransactionEvent;
  59. const projectId = project?.id;
  60. const isProjectStabilized =
  61. defined(project?.id) &&
  62. project.id === location.query.project &&
  63. project.id === String(selection.projects[0]);
  64. const hasSessions = project?.hasSessions ?? null;
  65. const hasOnlyBasicChart = !hasPerformance && !hasDiscover && !hasSessions;
  66. const title = routeTitleGen(
  67. t('Project %s', params.projectId),
  68. organization.slug,
  69. false
  70. );
  71. const visibleCharts = useMemo(() => {
  72. if (hasTransactions || hasSessions) {
  73. return ['chart1', 'chart2'];
  74. }
  75. return ['chart1'];
  76. }, [hasTransactions, hasSessions]);
  77. const onRetryProjects = useCallback(() => {
  78. fetchOrganizationDetails(api, params.orgId, true, false);
  79. }, [api, params.orgId]);
  80. const handleSearch = useCallback(
  81. (searchQuery: string) => {
  82. router.replace({
  83. pathname: location.pathname,
  84. query: {
  85. ...location.query,
  86. query: searchQuery,
  87. },
  88. });
  89. },
  90. [router, location.query, location.pathname]
  91. );
  92. const tagValueLoader = useCallback(
  93. (key: string, search: string) => {
  94. return fetchTagValues({
  95. api: api,
  96. orgSlug: organization.slug,
  97. tagKey: key,
  98. search,
  99. projectIds: location.query.project ? [location.query.project] : undefined,
  100. endpointParams: location.query,
  101. });
  102. },
  103. [api, organization.slug, location.query]
  104. );
  105. useEffect(() => {
  106. function syncProjectWithSlug() {
  107. if (projectId && projectId !== location.query.project) {
  108. // if someone visits /organizations/sentry/projects/javascript/ (without ?project=XXX) we need to update URL and globalSelection with the right project ID
  109. updateProjects([Number(projectId)], router);
  110. }
  111. }
  112. syncProjectWithSlug();
  113. }, [location.query.project, router, projectId]);
  114. if (!loadingProjects && !project) {
  115. return (
  116. <Layout.Page withPadding>
  117. <LoadingError
  118. message={t('This project could not be found.')}
  119. onRetry={onRetryProjects}
  120. />
  121. </Layout.Page>
  122. );
  123. }
  124. if (!loadingProjects && project && !project.hasAccess) {
  125. return (
  126. <Layout.Page>
  127. <MissingProjectMembership organization={organization} project={project} />
  128. </Layout.Page>
  129. );
  130. }
  131. return (
  132. <SentryDocumentTitle title={title}>
  133. <PageFiltersContainer
  134. disablePersistence
  135. skipLoadLastUsed
  136. showAbsolute={!hasOnlyBasicChart}
  137. >
  138. <Layout.Page>
  139. <NoProjectMessage organization={organization}>
  140. <Layout.Header>
  141. <Layout.HeaderContent>
  142. <Breadcrumbs
  143. crumbs={[
  144. {
  145. to: `/organizations/${params.orgId}/projects/`,
  146. label: t('Projects'),
  147. },
  148. {label: t('Project Details')},
  149. ]}
  150. />
  151. <Layout.Title>
  152. {project ? (
  153. <IdBadge
  154. project={project}
  155. avatarSize={28}
  156. hideOverflow="100%"
  157. disableLink
  158. hideName
  159. />
  160. ) : null}
  161. {project?.slug}
  162. </Layout.Title>
  163. </Layout.HeaderContent>
  164. <Layout.HeaderActions>
  165. <ButtonBar gap={1}>
  166. <FeedbackWidgetButton />
  167. <LinkButton
  168. size="sm"
  169. to={
  170. // if we are still fetching project, we can use project slug to build issue stream url and let the redirect handle it
  171. project?.id
  172. ? `/organizations/${params.orgId}/issues/?project=${project.id}`
  173. : `/${params.orgId}/${params.projectId}`
  174. }
  175. >
  176. {t('View All Issues')}
  177. </LinkButton>
  178. <CreateAlertButton
  179. size="sm"
  180. organization={organization}
  181. projectSlug={params.projectId}
  182. aria-label={t('Create Alert')}
  183. />
  184. <LinkButton
  185. size="sm"
  186. icon={<IconSettings />}
  187. aria-label={t('Settings')}
  188. to={`/settings/${params.orgId}/projects/${params.projectId}/`}
  189. />
  190. </ButtonBar>
  191. </Layout.HeaderActions>
  192. </Layout.Header>
  193. <Layout.Body noRowGap>
  194. {project && <StyledGlobalEventProcessingAlert projects={[project]} />}
  195. <Layout.Main>
  196. <ProjectFiltersWrapper>
  197. <ProjectFilters
  198. query={query}
  199. onSearch={handleSearch}
  200. relativeDateOptions={
  201. hasOnlyBasicChart
  202. ? pick(DEFAULT_RELATIVE_PERIODS, ERRORS_BASIC_CHART_PERIODS)
  203. : undefined
  204. }
  205. tagValueLoader={tagValueLoader}
  206. />
  207. </ProjectFiltersWrapper>
  208. <ProjectScoreCards
  209. organization={organization}
  210. isProjectStabilized={isProjectStabilized}
  211. selection={selection}
  212. hasSessions={hasSessions}
  213. hasTransactions={hasTransactions}
  214. query={query}
  215. project={project}
  216. location={location}
  217. />
  218. {isProjectStabilized && (
  219. <Fragment>
  220. {visibleCharts.map((id, index) => (
  221. <ProjectCharts
  222. location={location}
  223. organization={organization}
  224. router={router}
  225. key={`project-charts-${id}`}
  226. chartId={id}
  227. chartIndex={index}
  228. projectId={project?.id}
  229. hasSessions={hasSessions}
  230. hasTransactions={!!hasTransactions}
  231. visibleCharts={visibleCharts}
  232. query={query}
  233. project={project}
  234. />
  235. ))}
  236. <ProjectIssues
  237. organization={organization}
  238. location={location}
  239. projectId={selection.projects[0]}
  240. query={query}
  241. api={api}
  242. />
  243. </Fragment>
  244. )}
  245. </Layout.Main>
  246. <Layout.Side>
  247. <ProjectTeamAccess organization={organization} project={project} />
  248. <Feature features="incidents" organization={organization}>
  249. <ProjectLatestAlerts
  250. organization={organization}
  251. projectSlug={params.projectId}
  252. location={location}
  253. isProjectStabilized={isProjectStabilized}
  254. />
  255. </Feature>
  256. <ProjectLatestReleases
  257. organization={organization}
  258. projectSlug={params.projectId}
  259. location={location}
  260. isProjectStabilized={isProjectStabilized}
  261. project={project}
  262. />
  263. <ProjectQuickLinks
  264. organization={organization}
  265. project={project}
  266. location={location}
  267. />
  268. </Layout.Side>
  269. </Layout.Body>
  270. </NoProjectMessage>
  271. </Layout.Page>
  272. </PageFiltersContainer>
  273. </SentryDocumentTitle>
  274. );
  275. }
  276. const ProjectFiltersWrapper = styled('div')`
  277. margin-bottom: ${space(2)};
  278. `;
  279. const StyledGlobalEventProcessingAlert = styled(GlobalEventProcessingAlert)`
  280. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  281. margin-bottom: 0;
  282. }
  283. `;