aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/projectBaseline
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-web/src/main/js/apps/projectBaseline')
-rw-r--r--server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx23
-rw-r--r--server/sonar-web/src/main/js/apps/projectBaseline/components/AppContainer.ts29
-rw-r--r--server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx9
-rw-r--r--server/sonar-web/src/main/js/apps/projectBaseline/routes.ts2
4 files changed, 18 insertions, 45 deletions
diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx
index eb380cbc7b1..d515f2294e7 100644
--- a/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx
+++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx
@@ -21,6 +21,7 @@ import classNames from 'classnames';
import { debounce } from 'lodash';
import * as React from 'react';
import { getNewCodePeriod, resetNewCodePeriod, setNewCodePeriod } from '../../../api/newCodePeriod';
+import withAppStateContext from '../../../app/components/app-state/withAppStateContext';
import Suggestions from '../../../app/components/embed-docs-modal/Suggestions';
import AlertSuccessIcon from '../../../components/icons/AlertSuccessIcon';
import DeferredSpinner from '../../../components/ui/DeferredSpinner';
@@ -28,6 +29,7 @@ import { isBranch, sortBranches } from '../../../helpers/branch-like';
import { translate } from '../../../helpers/l10n';
import { Branch, BranchLike } from '../../../types/branch-like';
import {
+ AppState,
Component,
NewCodePeriod,
NewCodePeriodSettingType,
@@ -42,9 +44,8 @@ import ProjectBaselineSelector from './ProjectBaselineSelector';
interface Props {
branchLike: Branch;
branchLikes: BranchLike[];
- branchesEnabled?: boolean;
- canAdmin?: boolean;
component: Component;
+ appState: AppState;
}
interface State {
@@ -68,7 +69,7 @@ const DEFAULT_GENERAL_SETTING: { type: NewCodePeriodSettingType } = {
type: 'PREVIOUS_VERSION'
};
-export default class App extends React.PureComponent<Props, State> {
+export class App extends React.PureComponent<Props, State> {
mounted = false;
state: State = {
branchList: [],
@@ -127,14 +128,14 @@ export default class App extends React.PureComponent<Props, State> {
}
fetchLeakPeriodSetting() {
- const { branchLike, branchesEnabled, component } = this.props;
+ const { branchLike, appState, component } = this.props;
this.setState({ loading: true });
Promise.all([
getNewCodePeriod(),
getNewCodePeriod({
- branch: branchesEnabled ? undefined : branchLike.name,
+ branch: appState.branchesEnabled ? undefined : branchLike.name,
project: component.key
})
]).then(
@@ -235,7 +236,7 @@ export default class App extends React.PureComponent<Props, State> {
};
render() {
- const { branchesEnabled, canAdmin, component, branchLike } = this.props;
+ const { appState, component, branchLike } = this.props;
const {
analysis,
branchList,
@@ -255,19 +256,19 @@ export default class App extends React.PureComponent<Props, State> {
<>
<Suggestions suggestions="project_baseline" />
<div className="page page-limited">
- <AppHeader canAdmin={!!canAdmin} />
+ <AppHeader canAdmin={!!appState.canAdmin} />
{loading ? (
<DeferredSpinner />
) : (
<div className="panel-white project-baseline">
- {branchesEnabled && <h2>{translate('project_baseline.default_setting')}</h2>}
+ {appState.branchesEnabled && <h2>{translate('project_baseline.default_setting')}</h2>}
{generalSetting && overrideGeneralSetting !== undefined && (
<ProjectBaselineSelector
analysis={analysis}
branch={branchLike}
branchList={branchList}
- branchesEnabled={branchesEnabled}
+ branchesEnabled={appState.branchesEnabled}
component={component.key}
currentSetting={currentSetting}
currentSettingValue={currentSettingValue}
@@ -293,7 +294,7 @@ export default class App extends React.PureComponent<Props, State> {
{translate('settings.state.saved')}
</span>
</div>
- {generalSetting && branchesEnabled && (
+ {generalSetting && appState.branchesEnabled && (
<div className="huge-spacer-top branch-baseline-selector">
<hr />
<h2>{translate('project_baseline.configure_branches')}</h2>
@@ -318,3 +319,5 @@ export default class App extends React.PureComponent<Props, State> {
);
}
}
+
+export default withAppStateContext(App);
diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/AppContainer.ts b/server/sonar-web/src/main/js/apps/projectBaseline/components/AppContainer.ts
deleted file mode 100644
index 17120732063..00000000000
--- a/server/sonar-web/src/main/js/apps/projectBaseline/components/AppContainer.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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 { connect } from 'react-redux';
-import { getAppState, Store } from '../../../store/rootReducer';
-import App from './App';
-
-const mapStateToProps = (state: Store) => ({
- branchesEnabled: getAppState(state).branchesEnabled,
- canAdmin: getAppState(state).canAdmin
-});
-
-export default connect(mapStateToProps)(App);
diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx
index f05c9404271..e99eb125f1d 100644
--- a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx
+++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx
@@ -26,9 +26,9 @@ import {
} from '../../../../api/newCodePeriod';
import { mockBranch, mockMainBranch, mockPullRequest } from '../../../../helpers/mocks/branch-like';
import { mockComponent } from '../../../../helpers/mocks/component';
-import { mockEvent } from '../../../../helpers/testMocks';
+import { mockAppState, mockEvent } from '../../../../helpers/testMocks';
import { waitAndUpdate } from '../../../../helpers/testUtils';
-import App from '../App';
+import { App } from '../App';
jest.mock('../../../../api/newCodePeriod', () => ({
getNewCodePeriod: jest.fn().mockResolvedValue({}),
@@ -41,7 +41,7 @@ it('should render correctly', async () => {
await waitAndUpdate(wrapper);
expect(wrapper).toMatchSnapshot();
- wrapper = shallowRender({ branchesEnabled: false });
+ wrapper = shallowRender({ appState: mockAppState({ branchesEnabled: false, canAdmin: true }) });
await waitAndUpdate(wrapper);
expect(wrapper).toMatchSnapshot('without branch support');
});
@@ -109,8 +109,7 @@ function shallowRender(props: Partial<App['props']> = {}) {
<App
branchLike={mockBranch()}
branchLikes={[mockMainBranch()]}
- branchesEnabled={true}
- canAdmin={true}
+ appState={mockAppState({ branchesEnabled: true, canAdmin: true })}
component={mockComponent()}
{...props}
/>
diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/routes.ts b/server/sonar-web/src/main/js/apps/projectBaseline/routes.ts
index 16e3be4e88a..9d8f2bd42e4 100644
--- a/server/sonar-web/src/main/js/apps/projectBaseline/routes.ts
+++ b/server/sonar-web/src/main/js/apps/projectBaseline/routes.ts
@@ -21,7 +21,7 @@ import { lazyLoadComponent } from '../../components/lazyLoadComponent';
const routes = [
{
- indexRoute: { component: lazyLoadComponent(() => import('./components/AppContainer')) }
+ indexRoute: { component: lazyLoadComponent(() => import('./components/App')) }
}
];