import {Fragment} from 'react'; import { IndexRedirect, IndexRoute as BaseIndexRoute, IndexRouteProps, Redirect, Route as BaseRoute, RouteProps, } from 'react-router'; import memoize from 'lodash/memoize'; import LazyLoad from 'sentry/components/lazyLoad'; import {EXPERIMENTAL_SPA} from 'sentry/constants'; import {t} from 'sentry/locale'; import HookStore from 'sentry/stores/hookStore'; import {HookName} from 'sentry/types/hooks'; import errorHandler from 'sentry/utils/errorHandler'; import App from 'sentry/views/app'; import AuthLayout from 'sentry/views/auth/layout'; import IssueListContainer from 'sentry/views/issueList/container'; import IssueListOverview from 'sentry/views/issueList/overview'; import OrganizationContextContainer from 'sentry/views/organizationContextContainer'; import OrganizationDetails from 'sentry/views/organizationDetails'; import {Tab, TabPaths} from 'sentry/views/organizationGroupDetails/types'; import OrganizationRoot from 'sentry/views/organizationRoot'; import ProjectEventRedirect from 'sentry/views/projectEventRedirect'; import redirectDeprecatedProjectRoute from 'sentry/views/projects/redirectDeprecatedProjectRoute'; import RouteNotFound from 'sentry/views/routeNotFound'; import SettingsWrapper from 'sentry/views/settings/components/settingsWrapper'; import Feature from './components/acl/feature'; type CustomProps = { name?: string; }; /** * We add some additional props to our routes */ const Route = BaseRoute as React.ComponentClass; const IndexRoute = BaseIndexRoute as React.ComponentClass; const hook = (name: HookName) => HookStore.get(name).map(cb => cb()); const SafeLazyLoad = errorHandler(LazyLoad); // NOTE: makeLazyloadComponent is exported for use in the sentry.io (getsentry) // pirvate routing tree. /** * Factory function to produce a component that will render the SafeLazyLoad * _with_ the required props. */ export function makeLazyloadComponent>( resolve: () => Promise<{default: C}> ) { // XXX: Assign the component to a variable so it has a displayname const RouteLazyLoad: React.FC> = props => { return ; }; return RouteLazyLoad; } // Shorthand to avoid extra line wrapping const make = makeLazyloadComponent; function buildRoutes() { // Read this to understand where to add new routes, how / why the routing // tree is structured the way it is, and how the lazy-loading / // code-splitting works for pages. // // ## Formatting // // NOTE that there are intentionally NO blank lines within route tree blocks. // This helps make it easier to navigate within the file by using your // editors shortcuts to jump between 'paragraphs' of code. // // [!!] Do NOT add blank lines within route blocks to preserve this behavior! // // // ## Lazy loading // // * The `SafeLazyLoad` component // // Most routes are rendered as LazyLoad components (SafeLazyLoad is the // errorHandler wrapped version). This means the rendered component for the // route will only be loaded when the route is loaded. This helps us // "code-split" the app. // // ## Hooks // // There are a number of `hook()` routes placed within the routing tree to // allow for additional routes to be augmented into the application via the // hookStore mechanism. // // // ## The structure // // * `experimentalSpaRoutes` // // These routes are specifically for the experimental single-page-app mode, // where Sentry is run separate from Django. These are NOT part of the root // component. // // Right now these are mainly used for authentication pages. In the future // they would be used for other pages like registration. // // * `rootRoutes` // // These routes live directly under the container, and generally // are not specific to an organization. // // * `settingsRoutes` // // This is the route tree for all of `/settings/`. This route tree is // composed of a few different sub-trees. // // - `accountSettingsRoutes` User specific settings // - `orgSettingsRoutes` Specific to a organization // - `projectSettingsRoutes` Specific to a project // - `legacySettingsRedirects` Routes that used to exist in settings // // * `organizationRoutes` // // This is where a majority of the app routes live. This is wrapped with // the component, which provides the sidebar and // organization context. // // Within these routes are a variety of subroutes. They are not all // listed here as the subroutes will be added and removed, and most are // self explanatory. // // * `legacyRedirectRoutes` // // This route tree contains routes for many old legacy paths. // // You may also find 's collocated next to the feature routes // they have redirects for. A good rule here is to place 'helper' redirects // next to the routes they redirect to, and place 'legacy route' redirects // for routes that have completely changed in this tree. const experimentalSpaRoutes = EXPERIMENTAL_SPA ? ( import('sentry/views/auth/login'))} /> import('sentry/views/auth/login'))} /> ) : null; const rootRoutes = ( import('sentry/views/app/root'))} /> import('sentry/views/acceptOrganizationInvite'))} /> import('sentry/views/acceptProjectTransfer'))} /> import('sentry/views/integrationOrganizationLink'))} /> import('sentry/views/integrationOrganizationLink'))} /> import('sentry/views/sentryAppExternalInstallation'))} /> import('sentry/views/sharedGroupDetails'))} /> import('sentry/views/organizationCreate'))} /> import('sentry/views/dataExport/dataDownload'))} /> import('sentry/views/disabledMember'))} /> import('sentry/views/organizationJoinRequest'))} /> import('sentry/views/onboarding/onboarding'))} /> ); const accountSettingsRoutes = ( import('sentry/views/settings/account/accountSettingsLayout') )} > import('sentry/views/settings/account/accountDetails'))} /> import('sentry/views/settings/account/notifications/notificationSettings') )} /> import('sentry/views/settings/account/accountNotificationFineTuning') )} /> import('sentry/views/settings/account/accountEmails'))} /> import('sentry/views/settings/account/accountAuthorizations') )} /> import( 'sentry/views/settings/account/accountSecurity/accountSecurityWrapper' ) )} > import('sentry/views/settings/account/accountSecurity') )} /> import('sentry/views/settings/account/accountSecurity/sessionHistory') )} /> import( 'sentry/views/settings/account/accountSecurity/accountSecurityDetails' ) )} /> import( 'sentry/views/settings/account/accountSecurity/accountSecurityEnroll' ) )} /> import('sentry/views/settings/account/accountSubscriptions') )} /> import('sentry/views/settings/account/accountIdentities'))} /> import('sentry/views/settings/account/apiTokens'))} /> import('sentry/views/settings/account/apiNewToken'))} /> import('sentry/views/settings/account/apiApplications') )} /> import('sentry/views/settings/account/apiApplications/details') )} /> {hook('routes:api')} import('sentry/views/settings/account/accountClose'))} /> ); const projectSettingsRoutes = ( import('sentry/views/settings/project/projectSettingsLayout') )} > import('sentry/views/settings/projectGeneralSettings'))} /> import('sentry/views/settings/project/projectTeams'))} /> import('sentry/views/settings/projectAlerts'))} > import('sentry/views/settings/projectAlerts/settings'))} /> import('sentry/views/settings/project/projectEnvironments') )} > import('sentry/views/settings/projectTags'))} /> import('sentry/views/settings/project/projectReleaseTracking') )} /> import('sentry/views/settings/project/projectOwnership'))} /> import('sentry/views/settings/projectDataForwarding'))} /> import('sentry/views/settings/projectSecurityAndPrivacy') )} /> import('sentry/views/settings/projectSecurityAndPrivacy') )} /> import('sentry/views/settings/projectDebugFiles'))} /> import('sentry/views/settings/projectProguard'))} /> import('sentry/views/settings/projectPerformance'))} /> import('sentry/views/settings/projectSourceMaps'))} > import('sentry/views/settings/projectSourceMaps/list'))} /> import('sentry/views/settings/projectSourceMaps/detail'))} /> import('sentry/views/settings/project/projectProcessingIssues') )} /> import('sentry/views/settings/project/projectFilters'))} > import('sentry/views/settings/project/server-side-sampling') )} /> import('sentry/views/settings/projectIssueGrouping'))} /> import('sentry/views/settings/project/projectServiceHooks') )} /> import('sentry/views/settings/project/projectCreateServiceHook') )} /> import('sentry/views/settings/project/projectServiceHookDetails') )} /> import('sentry/views/settings/project/projectKeys/list'))} /> import('sentry/views/settings/project/projectKeys/details') )} /> import('sentry/views/settings/project/projectUserFeedback') )} /> import('sentry/views/settings/projectSecurityHeaders'))} /> import('sentry/views/settings/projectSecurityHeaders/csp') )} /> import('sentry/views/settings/projectSecurityHeaders/expectCt') )} /> import('sentry/views/settings/projectSecurityHeaders/hpkp') )} /> import('sentry/views/settings/projectPlugins'))} /> import('sentry/views/settings/projectPlugins/details'))} /> import('sentry/views/projectInstall/overview'))} /> import('sentry/views/projectInstall/platformOrIntegration') )} /> ); const orgSettingsRoutes = ( import('sentry/views/settings/organization/organizationSettingsLayout') )} > {hook('routes:organization')} import('sentry/views/settings/organizationGeneralSettings') )} /> import('sentry/views/settings/organizationProjects'))} /> import('sentry/views/settings/organizationApiKeys'))} /> import( 'sentry/views/settings/organizationApiKeys/organizationApiKeyDetails' ) )} /> import('sentry/views/settings/organizationAuditLog'))} /> import('sentry/views/settings/organizationAuth'))} /> import( 'sentry/views/settings/organizationMembers/organizationMembersWrapper' ) )} > import( 'sentry/views/settings/organizationMembers/organizationMembersList' ) )} /> import('sentry/views/settings/organizationMembers/organizationMemberDetail') )} /> import('sentry/views/settings/organizationRateLimits'))} /> import('sentry/views/settings/organizationRelay'))} /> import('sentry/views/settings/organizationRepositories'))} /> import('sentry/views/settings/organizationGeneralSettings') )} /> import('sentry/views/settings/organizationSecurityAndPrivacy') )} /> import('sentry/views/settings/organizationSecurityAndPrivacy') )} /> import('sentry/views/settings/organizationTeams'))} /> import('sentry/views/settings/organizationTeams/teamDetails') )} > import('sentry/views/settings/organizationTeams/teamMembers') )} /> import('sentry/views/settings/organizationTeams/teamNotifications') )} /> import('sentry/views/settings/organizationTeams/teamProjects') )} /> import('sentry/views/settings/organizationTeams/teamSettings') )} /> import('sentry/views/organizationIntegrations/pluginDetailedView') )} /> import('sentry/views/organizationIntegrations/sentryAppDetailedView') )} /> import('sentry/views/organizationIntegrations/docIntegrationDetailedView') )} /> import('sentry/views/organizationIntegrations/integrationListDirectory') )} /> import('sentry/views/organizationIntegrations/integrationDetailedView') )} /> import( 'sentry/views/settings/organizationIntegrations/configureIntegration' ) )} /> import('sentry/views/settings/organizationDeveloperSettings') )} /> import( 'sentry/views/settings/organizationDeveloperSettings/sentryApplicationDetails' ) )} /> import( 'sentry/views/settings/organizationDeveloperSettings/sentryApplicationDetails' ) )} /> import( 'sentry/views/settings/organizationDeveloperSettings/sentryApplicationDetails' ) )} /> import( 'sentry/views/settings/organizationDeveloperSettings/sentryApplicationDashboard' ) )} /> import( 'sentry/views/settings/organizationDeveloperSettings/sentryFunctionDetails' ) )} /> import( 'sentry/views/settings/organizationDeveloperSettings/sentryFunctionDetails' ) )} /> ); const legacySettingsRedirects = ( ); const settingsRoutes = ( import('sentry/views/settings/settingsIndex'))} /> {accountSettingsRoutes} {orgSettingsRoutes} {projectSettingsRoutes} {legacySettingsRedirects} ); const projectsRoutes = ( import('sentry/views/projectsDashboard'))} /> import('sentry/views/projectInstall/newProject'))} /> import('sentry/views/projectInstall/gettingStarted'))} > import('sentry/views/projectInstall/overview'))} /> import('sentry/views/projectInstall/platformOrIntegration') )} /> import('sentry/views/projectDetail'))} /> ); const dashboardRoutes = ( import('sentry/views/dashboardsV2'))} > import('sentry/views/dashboardsV2/manage'))} /> import('sentry/views/dashboardsV2/create'))} > import('sentry/views/dashboardsV2/widgetBuilder'))} /> import('sentry/views/dashboardsV2/widgetBuilder'))} /> import('sentry/views/dashboardsV2/create'))} > import('sentry/views/dashboardsV2/create'))} /> import('sentry/views/dashboardsV2/view'))} > import('sentry/views/dashboardsV2/widgetBuilder'))} /> import('sentry/views/dashboardsV2/widgetBuilder'))} /> import('sentry/views/dashboardsV2/view'))} /> ); const alertRoutes = ( import('sentry/views/alerts'))} > import('sentry/views/alerts/list/incidents'))} /> import('sentry/views/alerts/list/rules'))} /> import('sentry/views/alerts/rules/metric/details'))} /> import('sentry/views/alerts/builder/projectProvider'))} > import('sentry/views/alerts/edit'))} /> import('sentry/views/alerts/rules/issue/details'))} > import('sentry/views/alerts/rules/issue/details/ruleDetails') )} /> import('sentry/views/alerts/builder/projectProvider'))} > import('sentry/views/alerts/edit'))} /> import('sentry/views/alerts/builder/projectProvider'))} > import('sentry/views/alerts/wizard'))} /> import('sentry/views/alerts/builder/projectProvider'))} > import('sentry/views/alerts/create'))} /> import('sentry/views/alerts/incidentRedirect'))} /> import('sentry/views/alerts/builder/projectProvider'))} > import('sentry/views/alerts/create'))} /> import('sentry/views/alerts/wizard'))} /> ); const monitorsRoutes = ( import('sentry/views/monitors'))} > import('sentry/views/monitors/monitors'))} /> import('sentry/views/monitors/create'))} /> import('sentry/views/monitors/details'))} /> import('sentry/views/monitors/edit'))} /> ); const replayRoutes = ( import('sentry/views/replays'))} > import('sentry/views/replays/replays'))} /> import('sentry/views/replays/details'))} /> ); const releasesRoutes = ( import('sentry/views/releases/list'))} /> import('sentry/views/releases/detail'))} > import('sentry/views/releases/detail/overview'))} /> import('sentry/views/releases/detail/commitsAndFiles/commits') )} /> import('sentry/views/releases/detail/commitsAndFiles/filesChanged') )} /> ); const activityRoutes = ( import('sentry/views/organizationActivity'))} /> ); const statsRoutes = ( import('sentry/views/organizationStats'))} /> import('sentry/views/organizationStats/teamInsights'))} > import('sentry/views/organizationStats/teamInsights/issues') )} /> import('sentry/views/organizationStats/teamInsights'))} > import('sentry/views/organizationStats/teamInsights/health') )} /> ); // TODO(mark) Long term this /queries route should go away and /discover // should be the canonical route for discover2. We have a redirect right now // as /discover was for discover 1 and most of the application is linking to // /discover/queries and not /discover const discoverRoutes = ( import('sentry/views/eventsV2'))} > import('sentry/views/eventsV2/landing'))} /> import('sentry/views/eventsV2/results'))} /> import('sentry/views/eventsV2/eventDetails'))} /> ); const performanceRoutes = ( import('sentry/views/performance'))} > import('sentry/views/performance/content'))} /> import('sentry/views/performance/trends'))} /> import('sentry/views/performance/transactionSummary/transactionOverview') )} /> import('sentry/views/performance/transactionSummary/transactionReplays') )} /> import('sentry/views/performance/transactionSummary/transactionVitals') )} /> import('sentry/views/performance/transactionSummary/transactionTags') )} /> import('sentry/views/performance/transactionSummary/transactionEvents') )} /> import('sentry/views/performance/transactionSummary/transactionAnomalies') )} /> import('sentry/views/performance/transactionSummary/transactionSpans') )} /> import( 'sentry/views/performance/transactionSummary/transactionSpans/spanDetails' ) )} /> import('sentry/views/performance/vitalDetail'))} /> import('sentry/views/performance/traceDetails'))} /> import('sentry/views/performance/transactionDetails'))} /> ); const userFeedbackRoutes = ( import('sentry/views/userFeedback'))} /> ); const issueListRoutes = ( ); // Once org issues is complete, these routes can be nested under // /organizations/:orgId/issues const issueDetailsRoutes = ( import('sentry/views/organizationGroupDetails'))} > import('sentry/views/organizationGroupDetails/groupEventDetails') )} /> import('sentry/views/organizationGroupDetails/groupReplays') )} /> import('sentry/views/organizationGroupDetails/groupActivity') )} /> import('sentry/views/organizationGroupDetails/groupEvents') )} /> import('sentry/views/organizationGroupDetails/groupTags'))} /> import('sentry/views/organizationGroupDetails/groupTagValues') )} /> import('sentry/views/organizationGroupDetails/groupUserFeedback') )} /> import('sentry/views/organizationGroupDetails/groupEventAttachments') )} /> import('sentry/views/organizationGroupDetails/groupSimilarIssues') )} /> import('sentry/views/organizationGroupDetails/groupMerged') )} /> import('sentry/views/organizationGroupDetails/grouping'))} /> import('sentry/views/organizationGroupDetails/groupEventDetails') )} /> import('sentry/views/organizationGroupDetails/groupReplays') )} /> import('sentry/views/organizationGroupDetails/groupActivity') )} /> import('sentry/views/organizationGroupDetails/groupEvents') )} /> import('sentry/views/organizationGroupDetails/groupSimilarIssues') )} /> import('sentry/views/organizationGroupDetails/groupTags') )} /> import('sentry/views/organizationGroupDetails/groupTagValues') )} /> import('sentry/views/organizationGroupDetails/groupUserFeedback') )} /> import('sentry/views/organizationGroupDetails/groupEventAttachments') )} /> import('sentry/views/organizationGroupDetails/groupMerged') )} /> import('sentry/views/organizationGroupDetails/grouping'))} /> ); // These are the "manage" pages. For sentry.io, these are _different_ from // the SaaS admin routes in getsentry. const adminManageRoutes = ( import('sentry/views/admin/adminLayout'))} > import('sentry/views/admin/adminOverview'))} /> import('sentry/views/admin/adminBuffer'))} /> import('sentry/views/admin/adminRelays'))} /> import('sentry/views/admin/adminOrganizations'))} /> import('sentry/views/admin/adminProjects'))} /> import('sentry/views/admin/adminQueue'))} /> import('sentry/views/admin/adminQuotas'))} /> import('sentry/views/admin/adminSettings'))} /> import('sentry/views/admin/adminUsers'))} /> import('sentry/views/admin/adminUserEdit'))} /> import('sentry/views/admin/adminMail'))} /> import('sentry/views/admin/adminEnvironment'))} /> import('sentry/views/admin/adminPackages'))} /> import('sentry/views/admin/adminWarnings'))} /> {hook('routes:admin')} ); // XXX(epurkhiser): This should probably go away. It's not totally clear to // me why we need the OrganizationRoot root container. const legacyOrganizationRootRoutes = ( {hook('routes:organization')} ); // XXX(epurkhiser): These also exist in the legacyOrganizationRootRoutes. Not // sure which one here is more correct. const legacyGettingStartedRoutes = ( import('sentry/views/projectInstall/gettingStarted'))} > import('sentry/views/projectInstall/overview'))} /> import('sentry/views/projectInstall/platformOrIntegration') )} /> ); // Support for deprecated URLs (pre-Sentry 10). We just redirect users to new // canonical URLs. // // XXX(epurkhiser): Can these be moved over to the legacyOrgRedirects routes, // or do these need to be nested into the OrganizationDetails tree? const legacyOrgRedirects = ( `/organizations/${orgId}/issues/?project=${projectId}` ) )} /> `/organizations/${orgId}/issues/?project=${projectId}` ) )} /> `/organizations/${orgId}/dashboards/?project=${projectId}` ) )} /> `/organizations/${orgId}/user-feedback/?project=${projectId}` ) )} /> `/organizations/${orgId}/releases/?project=${projectId}` ) )} /> `/organizations/${orgId}/releases/${router.params.version}/?project=${projectId}` ) )} /> `/organizations/${orgId}/releases/${router.params.version}/new-events/?project=${projectId}` ) )} /> `/organizations/${orgId}/releases/${router.params.version}/all-events/?project=${projectId}` ) )} /> `/organizations/${orgId}/releases/${router.params.version}/commits/?project=${projectId}` ) )} /> ); const profilingRoutes = ( import('sentry/views/profiling'))} > import('sentry/views/profiling/content'))} /> import('sentry/views/profiling/profileSummary'))} /> import('sentry/views/profiling/profileGroupProvider'))} > import('sentry/views/profiling/profileDetails'))} /> import('sentry/views/profiling/profileFlamechart'))} /> ); const organizationRoutes = ( {settingsRoutes} {projectsRoutes} {dashboardRoutes} {userFeedbackRoutes} {issueListRoutes} {issueDetailsRoutes} {alertRoutes} {monitorsRoutes} {replayRoutes} {releasesRoutes} {activityRoutes} {statsRoutes} {discoverRoutes} {performanceRoutes} {profilingRoutes} {adminManageRoutes} {legacyOrganizationRootRoutes} {legacyGettingStartedRoutes} {legacyOrgRedirects} ); const legacyRedirectRoutes = ( ); const appRoutes = ( {experimentalSpaRoutes} {rootRoutes} {organizationRoutes} {legacyRedirectRoutes} {hook('routes')} ); return appRoutes; } // We load routes both when initlaizing the SDK (for routing integrations) and // when the app renders Main. Memoize to avoid rebuilding the route tree. export const routes = memoize(buildRoutes);