diff options
author | Philippe Perrin <philippe.perrin@sonarsource.com> | 2022-03-08 16:59:11 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-03-14 20:03:08 +0000 |
commit | 15e088d040984e033a74877b5e42babeb365ded9 (patch) | |
tree | 0eb06082e2e46e627ae5de1065e1b35f34d9b8c3 /server/sonar-web/src/main/js/app/utils | |
parent | 80bdd0543ac958ae1a6684c638ee569cfd3d2721 (diff) | |
download | sonarqube-15e088d040984e033a74877b5e42babeb365ded9.tar.gz sonarqube-15e088d040984e033a74877b5e42babeb365ded9.zip |
SONAR-15913 Extract users from redux
Diffstat (limited to 'server/sonar-web/src/main/js/app/utils')
-rw-r--r-- | server/sonar-web/src/main/js/app/utils/getStore.ts | 9 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/app/utils/startReactApp.tsx | 158 |
2 files changed, 84 insertions, 83 deletions
diff --git a/server/sonar-web/src/main/js/app/utils/getStore.ts b/server/sonar-web/src/main/js/app/utils/getStore.ts index 63b5701d0d1..251dd073983 100644 --- a/server/sonar-web/src/main/js/app/utils/getStore.ts +++ b/server/sonar-web/src/main/js/app/utils/getStore.ts @@ -19,18 +19,13 @@ */ import { Store } from 'redux'; import rootReducer, { Store as State } from '../../store/rootReducer'; -import { receiveCurrentUser } from '../../store/users'; import configureStore from '../../store/utils/configureStore'; -import { CurrentUser } from '../../types/types'; let store: Store<State, any>; -const createStore = (currentUser?: CurrentUser) => { +const createStore = () => { store = configureStore(rootReducer); - if (currentUser) { - store.dispatch(receiveCurrentUser(currentUser)); - } return store; }; -export default (currentUser?: CurrentUser) => (store ? store : createStore(currentUser)); +export default () => (store ? store : createStore()); diff --git a/server/sonar-web/src/main/js/app/utils/startReactApp.tsx b/server/sonar-web/src/main/js/app/utils/startReactApp.tsx index 6854fa5fbb7..0c8dc2ab1d5 100644 --- a/server/sonar-web/src/main/js/app/utils/startReactApp.tsx +++ b/server/sonar-web/src/main/js/app/utils/startReactApp.tsx @@ -17,7 +17,7 @@ * 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'; @@ -61,9 +61,10 @@ import withIndexationGuard from '../../components/hoc/withIndexationGuard'; import { lazyLoadComponent } from '../../components/lazyLoadComponent'; import getHistory from '../../helpers/getHistory'; import { AppState } from '../../types/appstate'; -import { CurrentUser } from '../../types/types'; +import { CurrentUser } from '../../types/users'; import App from '../components/App'; import AppStateContextProvider from '../components/app-state/AppStateContextProvider'; +import CurrentUserContextProvider from '../components/current-user/CurrentUserContextProvider'; import GlobalContainer from '../components/GlobalContainer'; import { PageContext } from '../components/indexation/PageUnavailableDueToIndexation'; import MigrationContainer from '../components/MigrationContainer'; @@ -286,100 +287,105 @@ export default function startReactApp(lang: string, appState: AppState, currentU const el = document.getElementById('content'); const history = getHistory(); - const store = getStore(currentUser); + const store = getStore(); render( <HelmetProvider> <Provider store={store}> <AppStateContextProvider appState={appState}> - <IntlProvider defaultLocale={lang} locale={lang}> - <Router history={history} onUpdate={handleUpdate}> - {renderRedirects()} - - <Route - path="formatting/help" - component={lazyLoadComponent(() => import('../components/FormattingHelp'))} - /> + <CurrentUserContextProvider currentUser={currentUser}> + <IntlProvider defaultLocale={lang} locale={lang}> + <Router history={history} onUpdate={handleUpdate}> + {renderRedirects()} - <Route component={lazyLoadComponent(() => import('../components/SimpleContainer'))}> - <Route path="maintenance">{maintenanceRoutes}</Route> - <Route path="setup">{setupRoutes}</Route> - </Route> - - <Route component={MigrationContainer}> <Route - component={lazyLoadComponent(() => - import('../components/SimpleSessionsContainer') - )}> - <RouteWithChildRoutes path="/sessions" childRoutes={sessionsRoutes} /> + path="formatting/help" + component={lazyLoadComponent(() => import('../components/FormattingHelp'))} + /> + + <Route component={lazyLoadComponent(() => import('../components/SimpleContainer'))}> + <Route path="maintenance">{maintenanceRoutes}</Route> + <Route path="setup">{setupRoutes}</Route> </Route> - <Route path="/" component={App}> - <IndexRoute - component={lazyLoadComponent(() => import('../components/Landing'))} - /> + <Route component={MigrationContainer}> + <Route + component={lazyLoadComponent(() => + import('../components/SimpleSessionsContainer') + )}> + <RouteWithChildRoutes path="/sessions" childRoutes={sessionsRoutes} /> + </Route> - <Route component={GlobalContainer}> - <RouteWithChildRoutes path="account" childRoutes={accountRoutes} /> - <RouteWithChildRoutes path="coding_rules" childRoutes={codingRulesRoutes} /> - <RouteWithChildRoutes path="documentation" childRoutes={documentationRoutes} /> + <Route path="/" component={App}> + <IndexRoute + component={lazyLoadComponent(() => import('../components/Landing'))} + /> + + <Route component={GlobalContainer}> + <RouteWithChildRoutes path="account" childRoutes={accountRoutes} /> + <RouteWithChildRoutes path="coding_rules" childRoutes={codingRulesRoutes} /> + <RouteWithChildRoutes + path="documentation" + childRoutes={documentationRoutes} + /> + <Route + path="extension/:pluginKey/:extensionKey" + component={lazyLoadComponent(() => + import('../components/extensions/GlobalPageExtension') + )} + /> + <Route + path="issues" + component={withIndexationGuard(Issues, PageContext.Issues)} + /> + <RouteWithChildRoutes path="projects" childRoutes={projectsRoutes} /> + <RouteWithChildRoutes path="quality_gates" childRoutes={qualityGatesRoutes} /> + <Route + path="portfolios" + component={lazyLoadComponent(() => + import('../components/extensions/PortfoliosPage') + )} + /> + <RouteWithChildRoutes path="profiles" childRoutes={qualityProfilesRoutes} /> + <RouteWithChildRoutes path="web_api" childRoutes={webAPIRoutes} /> + + {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" + component={lazyLoadComponent(() => import('../components/ResetPassword'))} + /> <Route - path="extension/:pluginKey/:extensionKey" + // 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" component={lazyLoadComponent(() => - import('../components/extensions/GlobalPageExtension') + import('../../apps/change-admin-password/ChangeAdminPasswordApp') )} /> <Route - path="issues" - component={withIndexationGuard(Issues, PageContext.Issues)} + // 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" + component={lazyLoadComponent(() => import('../components/PluginRiskConsent'))} /> - <RouteWithChildRoutes path="projects" childRoutes={projectsRoutes} /> - <RouteWithChildRoutes path="quality_gates" childRoutes={qualityGatesRoutes} /> <Route - path="portfolios" - component={lazyLoadComponent(() => - import('../components/extensions/PortfoliosPage') - )} + path="not_found" + component={lazyLoadComponent(() => import('../components/NotFound'))} + /> + <Route + path="*" + component={lazyLoadComponent(() => import('../components/NotFound'))} /> - <RouteWithChildRoutes path="profiles" childRoutes={qualityProfilesRoutes} /> - <RouteWithChildRoutes path="web_api" childRoutes={webAPIRoutes} /> - - {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" - component={lazyLoadComponent(() => import('../components/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" - component={lazyLoadComponent(() => - import('../../apps/change-admin-password/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" - component={lazyLoadComponent(() => import('../components/PluginRiskConsent'))} - /> - <Route - path="not_found" - component={lazyLoadComponent(() => import('../components/NotFound'))} - /> - <Route - path="*" - component={lazyLoadComponent(() => import('../components/NotFound'))} - /> </Route> - </Route> - </Router> - </IntlProvider> + </Router> + </IntlProvider> + </CurrentUserContextProvider> </AppStateContextProvider> </Provider> </HelmetProvider>, |