1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/*
* SonarQube
* Copyright (C) 2009-2023 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.
*/
import { ThemeProvider } from '@emotion/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { lightTheme } from 'design-system';
import * as React from 'react';
import { render } from 'react-dom';
import { Helmet, HelmetProvider } from 'react-helmet-async';
import { IntlShape, RawIntlProvider } from 'react-intl';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import accountRoutes from '../../apps/account/routes';
import auditLogsRoutes from '../../apps/audit-logs/routes';
import backgroundTasksRoutes from '../../apps/background-tasks/routes';
import ChangeAdminPasswordApp from '../../apps/change-admin-password/ChangeAdminPasswordApp';
import codeRoutes from '../../apps/code/routes';
import codingRulesRoutes from '../../apps/coding-rules/routes';
import componentMeasuresRoutes from '../../apps/component-measures/routes';
import groupsRoutes from '../../apps/groups/routes';
import { globalIssuesRoutes, projectIssuesRoutes } from '../../apps/issues/routes';
import maintenanceRoutes 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 projectActivityRoutes from '../../apps/projectActivity/routes';
import projectBranchesRoutes from '../../apps/projectBranches/routes';
import ProjectDeletionApp from '../../apps/projectDeletion/App';
import projectDumpRoutes from '../../apps/projectDump/routes';
import projectInfoRoutes from '../../apps/projectInformation/routes';
import ProjectKeyApp from '../../apps/projectKey/ProjectKeyApp';
import ProjectLinksApp from '../../apps/projectLinks/ProjectLinksApp';
import projectNewCodeDefinitionRoutes from '../../apps/projectNewCode/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 SecurityHotspotsApp from '../../apps/security-hotspots/SecurityHotspotsApp';
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 webAPIRoutesV2 from '../../apps/web-api-v2/routes';
import webAPIRoutes from '../../apps/web-api/routes';
import webhooksRoutes from '../../apps/webhooks/routes';
import { translate } from '../../helpers/l10n';
import { getBaseUrl } from '../../helpers/system';
import { AppState } from '../../types/appstate';
import { Feature } from '../../types/features';
import { CurrentUser } from '../../types/users';
import AdminContainer from '../components/AdminContainer';
import App from '../components/App';
import ComponentContainer from '../components/ComponentContainer';
import DocumentationRedirect from '../components/DocumentationRedirect';
import FormattingHelp from '../components/FormattingHelp';
import GlobalContainer from '../components/GlobalContainer';
import GlobalMessagesContainer from '../components/GlobalMessagesContainer';
import Landing from '../components/Landing';
import MigrationContainer from '../components/MigrationContainer';
import NonAdminPagesContainer from '../components/NonAdminPagesContainer';
import NotFound from '../components/NotFound';
import PluginRiskConsent from '../components/PluginRiskConsent';
import ProjectAdminContainer from '../components/ProjectAdminContainer';
import ResetPassword from '../components/ResetPassword';
import SimpleContainer from '../components/SimpleContainer';
import SonarLintConnection from '../components/SonarLintConnection';
import { DEFAULT_APP_STATE } from '../components/app-state/AppStateContext';
import AppStateContextProvider from '../components/app-state/AppStateContextProvider';
import {
AvailableFeaturesContext,
DEFAULT_AVAILABLE_FEATURES,
} from '../components/available-features/AvailableFeaturesContext';
import CurrentUserContextProvider from '../components/current-user/CurrentUserContextProvider';
import GlobalAdminPageExtension from '../components/extensions/GlobalAdminPageExtension';
import GlobalPageExtension from '../components/extensions/GlobalPageExtension';
import PortfolioPage from '../components/extensions/PortfolioPage';
import PortfoliosPage from '../components/extensions/PortfoliosPage';
import ProjectAdminPageExtension from '../components/extensions/ProjectAdminPageExtension';
import ProjectPageExtension from '../components/extensions/ProjectPageExtension';
import exportModulesAsGlobals from './exportModulesAsGlobals';
function renderComponentRoutes() {
return (
<Route element={<ComponentContainer />}>
{/* This container is a catch-all for all non-admin pages */}
<Route element={<NonAdminPagesContainer />}>
{codeRoutes()}
{componentMeasuresRoutes()}
{overviewRoutes()}
<Route path="portfolio" element={<PortfolioPage />} />
{projectActivityRoutes()}
<Route
path="project/extension/:pluginKey/:extensionKey"
element={<ProjectPageExtension />}
/>
{projectIssuesRoutes()}
<Route path="security_hotspots" element={<SecurityHotspotsApp />} />
{projectQualityGateRoutes()}
{projectQualityProfilesRoutes()}
{projectInfoRoutes()}
{tutorialsRoutes()}
</Route>
<Route element={<ProjectAdminContainer />}>
<Route path="project">
<Route
path="admin/extension/:pluginKey/:extensionKey"
element={<ProjectAdminPageExtension />}
/>
{backgroundTasksRoutes()}
{projectNewCodeDefinitionRoutes()}
{projectBranchesRoutes()}
{projectDumpRoutes()}
{settingsRoutes()}
{webhooksRoutes()}
<Route path="deletion" element={<ProjectDeletionApp />} />
<Route path="links" element={<ProjectLinksApp />} />
<Route path="key" element={<ProjectKeyApp />} />
</Route>
{projectPermissionsRoutes()}
</Route>
</Route>
);
}
function renderAdminRoutes() {
return (
<Route path="admin" element={<AdminContainer />}>
<Route path="extension/:pluginKey/:extensionKey" element={<GlobalAdminPageExtension />} />
{settingsRoutes()}
{auditLogsRoutes()}
{backgroundTasksRoutes()}
{groupsRoutes()}
{permissionTemplatesRoutes()}
{globalPermissionsRoutes()}
{projectsManagementRoutes()}
{systemRoutes()}
{marketplaceRoutes()}
{usersRoutes()}
{webhooksRoutes()}
</Route>
);
}
function renderRedirects() {
return (
<>
{/*
* This redirect enables analyzers and PDFs to link to the correct version of the
* documentation without having to compute the direct links themselves (DRYer).
*/}
<Route path="/documentation/*" element={<DocumentationRedirect />} />
</>
);
}
const queryClient = new QueryClient();
export default function startReactApp(
l10nBundle: IntlShape,
currentUser?: CurrentUser,
appState?: AppState,
availableFeatures?: Feature[],
) {
exportModulesAsGlobals();
const el = document.getElementById('content');
render(
<HelmetProvider>
<AppStateContextProvider appState={appState ?? DEFAULT_APP_STATE}>
<AvailableFeaturesContext.Provider value={availableFeatures ?? DEFAULT_AVAILABLE_FEATURES}>
<CurrentUserContextProvider currentUser={currentUser}>
<RawIntlProvider value={l10nBundle}>
<ThemeProvider theme={lightTheme}>
<QueryClientProvider client={queryClient}>
<GlobalMessagesContainer />
<BrowserRouter basename={getBaseUrl()}>
<Helmet titleTemplate={translate('page_title.template.default')} />
<Routes>
{renderRedirects()}
<Route path="formatting/help" element={<FormattingHelp />} />
<Route element={<SimpleContainer />}>{maintenanceRoutes()}</Route>
<Route element={<MigrationContainer />}>
{sessionsRoutes()}
<Route path="/" element={<App />}>
<Route index element={<Landing />} />
<Route element={<GlobalContainer />}>
{accountRoutes()}
{codingRulesRoutes()}
<Route
path="extension/:pluginKey/:extensionKey"
element={<GlobalPageExtension />}
/>
{globalIssuesRoutes()}
{projectsRoutes()}
{qualityGatesRoutes()}
{qualityProfilesRoutes()}
<Route path="portfolios" element={<PortfoliosPage />} />
<Route path="sonarlint/auth" element={<SonarLintConnection />} />
{webAPIRoutes()}
{webAPIRoutesV2()}
{renderComponentRoutes()}
{renderAdminRoutes()}
</Route>
<Route
// We don't want this route to have any menu.
// That is why we can not have it under the accountRoutes
path="account/reset_password"
element={<ResetPassword />}
/>
<Route
// We don't want this route to have any menu. This is why we define it here
// rather than under the admin routes.
path="admin/change_admin_password"
element={<ChangeAdminPasswordApp />}
/>
<Route
// We don't want this route to have any menu. This is why we define it here
// rather than under the admin routes.
path="admin/plugin_risk_consent"
element={<PluginRiskConsent />}
/>
<Route path="not_found" element={<NotFound />} />
<Route path="*" element={<NotFound />} />
</Route>
</Route>
</Routes>
</BrowserRouter>
</QueryClientProvider>
</ThemeProvider>
</RawIntlProvider>
</CurrentUserContextProvider>
</AvailableFeaturesContext.Provider>
</AppStateContextProvider>
</HelmetProvider>,
el,
);
}
|