diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2022-10-10 16:07:02 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-12 20:03:43 +0000 |
commit | 687e4c8d3830ff68fe39f60d8db18e9afe007bc6 (patch) | |
tree | 347640c307b703934a7f52e386c1f3e7904badb7 /server/sonar-web/src/main/js/apps/projectBaseline | |
parent | b7782da37057932f728f41b11553bc0592b0a141 (diff) | |
download | sonarqube-687e4c8d3830ff68fe39f60d8db18e9afe007bc6.tar.gz sonarqube-687e4c8d3830ff68fe39f60d8db18e9afe007bc6.zip |
SONAR-17118 migrate branch support flag to features/list API
Diffstat (limited to 'server/sonar-web/src/main/js/apps/projectBaseline')
-rw-r--r-- | server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx | 19 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx | 5 |
2 files changed, 15 insertions, 9 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 a9021768e71..a68bf11ed8f 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 @@ -22,6 +22,9 @@ 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 withAvailableFeatures, { + WithAvailableFeaturesProps +} from '../../../app/components/available-features/withAvailableFeatures'; import withComponentContext from '../../../app/components/componentContext/withComponentContext'; import Suggestions from '../../../components/embed-docs-modal/Suggestions'; import AlertSuccessIcon from '../../../components/icons/AlertSuccessIcon'; @@ -30,6 +33,7 @@ import { isBranch, sortBranches } from '../../../helpers/branch-like'; import { translate } from '../../../helpers/l10n'; import { AppState } from '../../../types/appstate'; import { Branch, BranchLike } from '../../../types/branch-like'; +import { Feature } from '../../../types/features'; import { Component, NewCodePeriod, @@ -42,7 +46,7 @@ import AppHeader from './AppHeader'; import BranchList from './BranchList'; import ProjectBaselineSelector from './ProjectBaselineSelector'; -interface Props { +interface Props extends WithAvailableFeaturesProps { branchLike: Branch; branchLikes: BranchLike[]; component: Component; @@ -129,14 +133,14 @@ export class App extends React.PureComponent<Props, State> { } fetchLeakPeriodSetting() { - const { branchLike, appState, component } = this.props; + const { branchLike, component } = this.props; this.setState({ loading: true }); Promise.all([ getNewCodePeriod(), getNewCodePeriod({ - branch: appState.branchesEnabled ? undefined : branchLike.name, + branch: this.props.hasFeature(Feature.BranchSupport) ? undefined : branchLike.name, project: component.key }) ]).then( @@ -252,6 +256,7 @@ export class App extends React.PureComponent<Props, State> { selected, success } = this.state; + const branchSupportEnabled = this.props.hasFeature(Feature.BranchSupport); return ( <> @@ -262,14 +267,14 @@ export class App extends React.PureComponent<Props, State> { <DeferredSpinner /> ) : ( <div className="panel-white project-baseline"> - {appState.branchesEnabled && <h2>{translate('project_baseline.default_setting')}</h2>} + {branchSupportEnabled && <h2>{translate('project_baseline.default_setting')}</h2>} {generalSetting && overrideGeneralSetting !== undefined && ( <ProjectBaselineSelector analysis={analysis} branch={branchLike} branchList={branchList} - branchesEnabled={appState.branchesEnabled} + branchesEnabled={branchSupportEnabled} component={component.key} currentSetting={currentSetting} currentSettingValue={currentSettingValue} @@ -295,7 +300,7 @@ export class App extends React.PureComponent<Props, State> { {translate('settings.state.saved')} </span> </div> - {generalSetting && appState.branchesEnabled && ( + {generalSetting && branchSupportEnabled && ( <div className="huge-spacer-top branch-baseline-selector"> <hr /> <h2>{translate('project_baseline.configure_branches')}</h2> @@ -321,4 +326,4 @@ export class App extends React.PureComponent<Props, State> { } } -export default withComponentContext(withAppStateContext(App)); +export default withComponentContext(withAvailableFeatures(withAppStateContext(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 9ceb6e3b6e3..cbf4f74058f 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 @@ -41,7 +41,7 @@ it('should render correctly', async () => { await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - wrapper = shallowRender({ appState: mockAppState({ branchesEnabled: false, canAdmin: true }) }); + wrapper = shallowRender({ appState: mockAppState({ canAdmin: true }), hasFeature: () => false }); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot('without branch support'); }); @@ -109,7 +109,8 @@ function shallowRender(props: Partial<App['props']> = {}) { <App branchLike={mockBranch()} branchLikes={[mockMainBranch()]} - appState={mockAppState({ branchesEnabled: true, canAdmin: true })} + appState={mockAppState({ canAdmin: true })} + hasFeature={jest.fn().mockReturnValue(true)} component={mockComponent()} {...props} /> |