/* * SonarQube * Copyright (C) 2009-2021 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* eslint-disable react/jsx-sort-props */ import { Location } from 'history'; import { pick } from 'lodash'; import * as React from 'react'; import ReactDom, { render } from 'react-dom'; import { HelmetProvider } from 'react-helmet-async'; import { IntlProvider } from 'react-intl'; import { Provider } from 'react-redux'; import { IndexRoute, Redirect, Route, RouteConfig, RouteProps, Router } from 'react-router'; import accountRoutes from '../../apps/account/routes'; import applicationConsoleRoutes from '../../apps/application-console/routes'; import applicationSettingsRoutes from '../../apps/application-settings/routes'; import auditLogsRoutes from '../../apps/audit-logs/routes'; import backgroundTasksRoutes from '../../apps/background-tasks/routes'; import codeRoutes from '../../apps/code/routes'; import codingRulesRoutes from '../../apps/coding-rules/routes'; import componentMeasuresRoutes from '../../apps/component-measures/routes'; import documentationRoutes from '../../apps/documentation/routes'; import groupsRoutes from '../../apps/groups/routes'; import Issues from '../../apps/issues/components/AppContainer'; import { maintenanceRoutes, setupRoutes } from '../../apps/maintenance/routes'; import marketplaceRoutes from '../../apps/marketplace/routes'; import overviewRoutes from '../../apps/overview/routes'; import permissionTemplatesRoutes from '../../apps/permission-templates/routes'; import { globalPermissionsRoutes, projectPermissionsRoutes } from '../../apps/permissions/routes'; import portfolioRoutes from '../../apps/portfolio/routes'; import projectActivityRoutes from '../../apps/projectActivity/routes'; import projectBaselineRoutes from '../../apps/projectBaseline/routes'; import projectBranchesRoutes from '../../apps/projectBranches/routes'; import projectDumpRoutes from '../../apps/projectDump/routes'; import projectQualityGateRoutes from '../../apps/projectQualityGate/routes'; import projectQualityProfilesRoutes from '../../apps/projectQualityProfiles/routes'; import projectsRoutes from '../../apps/projects/routes'; import projectsManagementRoutes from '../../apps/projectsManagement/routes'; import qualityGatesRoutes from '../../apps/quality-gates/routes'; import qualityProfilesRoutes from '../../apps/quality-profiles/routes'; import sessionsRoutes from '../../apps/sessions/routes'; import settingsRoutes from '../../apps/settings/routes'; import systemRoutes from '../../apps/system/routes'; import tutorialsRoutes from '../../apps/tutorials/routes'; import usersRoutes from '../../apps/users/routes'; import webAPIRoutes from '../../apps/web-api/routes'; import webhooksRoutes from '../../apps/webhooks/routes'; import withIndexationGuard from '../../components/hoc/withIndexationGuard'; import { lazyLoadComponent } from '../../components/lazyLoadComponent'; import getHistory from '../../helpers/getHistory'; import App from '../components/App'; import GlobalContainer from '../components/GlobalContainer'; import { PageContext } from '../components/indexation/PageUnavailableDueToIndexation'; import MigrationContainer from '../components/MigrationContainer'; import NonAdminPagesContainer from '../components/NonAdminPagesContainer'; import getStore from './getStore'; /* * Expose dependencies to extensions */ function attachToGlobal() { window.React = React; window.ReactDOM = ReactDom; } function handleUpdate(this: { state: { location: Location } }) { const { action } = this.state.location; if (action === 'PUSH') { window.scrollTo(0, 0); } } // this is not an official api const RouteWithChildRoutes = Route as React.ComponentClass< RouteProps & { childRoutes: RouteConfig } >; function renderRedirects() { return ( <> { replace({ pathname: '/issues', query: { myIssues: 'true', resolved: 'false' } }); }} /> { replace(`/coding_rules${window.location.hash}`); }} /> { replace({ pathname: '/dashboard', query: { id: nextState.params.key } }); }} /> { replace(`/issues${window.location.hash}`); }} /> ); } function renderComponentRoutes() { return ( import('../components/ComponentContainer'))}> {/* This container is a catch-all for all non-admin pages */} import('../components/extensions/ProjectPageExtension') )} /> { if (query.types) { if (query.types === 'SECURITY_HOTSPOT') { replace({ pathname: '/security_hotspots', query: { ...pick(query, ['id', 'branch', 'pullRequest']), assignedToMe: false } }); } else { query.types = query.types .split(',') .filter((type: string) => type !== 'SECURITY_HOTSPOT') .join(','); } } }} /> import('../../apps/security-hotspots/SecurityHotspotsApp') )} /> import('../components/ProjectAdminContainer'))}> import('../components/extensions/ProjectAdminPageExtension') )} /> import('../../apps/projectDeletion/App'))} /> import('../../apps/projectLinks/App'))} /> import('../../apps/projectKey/Key'))} /> ); } function renderAdminRoutes() { return ( import('../components/AdminContainer'))} path="admin"> import('../components/extensions/GlobalAdminPageExtension') )} /> ); } export default function startReactApp( lang: string, currentUser?: T.CurrentUser, appState?: T.AppState ) { attachToGlobal(); const el = document.getElementById('content'); const history = getHistory(); const store = getStore(currentUser, appState); render( {renderRedirects()} import('../components/FormattingHelp'))} /> import('../components/SimpleContainer'))}> {maintenanceRoutes} {setupRoutes} import('../components/SimpleSessionsContainer') )}> import('../components/Landing'))} /> import('../components/extensions/GlobalPageExtension') )} /> import('../components/extensions/PortfoliosPage') )} /> {renderComponentRoutes()} {renderAdminRoutes()} import('../components/ResetPassword'))} /> import('../../apps/change-admin-password/ChangeAdminPasswordApp') )} /> import('../components/PluginRiskConsent'))} /> import('../components/NotFound'))} /> import('../components/NotFound'))} /> , el ); }