diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-12-06 15:53:55 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-12-11 20:20:58 +0100 |
commit | ce80f2115245688992a727beeecd46ac43dca703 (patch) | |
tree | 93d7716eb310d5baad9c5b58bd84073774b3f4a2 /server/sonar-web/src/main/js/apps/coding-rules | |
parent | 0a3fef5c6baba580a558b996bd23b435dfc9e4aa (diff) | |
download | sonarqube-ce80f2115245688992a727beeecd46ac43dca703.tar.gz sonarqube-ce80f2115245688992a727beeecd46ac43dca703.zip |
remove some usages of legacy react context
Diffstat (limited to 'server/sonar-web/src/main/js/apps/coding-rules')
3 files changed, 18 insertions, 18 deletions
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx index 89d1f04d5de..7fc402e7416 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx @@ -21,7 +21,6 @@ import * as React from 'react'; import { Helmet } from 'react-helmet'; import { connect } from 'react-redux'; import { withRouter, WithRouterProps } from 'react-router'; -import * as PropTypes from 'prop-types'; import * as key from 'keymaster'; import { keyBy } from 'lodash'; import BulkChange from './BulkChange'; @@ -55,7 +54,8 @@ import { getCurrentUser, getLanguages, getMyOrganizations, - Store + Store, + getAppState } from '../../../store/rootReducer'; import { translate } from '../../../helpers/l10n'; import { RawQuery } from '../../../helpers/query'; @@ -68,6 +68,7 @@ const PAGE_SIZE = 100; const LIMIT_BEFORE_LOAD_MORE = 5; interface StateToProps { + appState: T.AppState; currentUser: T.CurrentUser; languages: T.Languages; userOrganizations: T.Organization[]; @@ -99,10 +100,6 @@ interface State { export class App extends React.PureComponent<Props, State> { mounted = false; - static contextTypes = { - organizationsEnabled: PropTypes.bool - }; - constructor(props: Props) { super(props); this.state = { @@ -528,7 +525,7 @@ export class App extends React.PureComponent<Props, State> { onFilterChange={this.handleFilterChange} openFacets={this.state.openFacets} organization={organization} - organizationsEnabled={this.context.organizationsEnabled} + organizationsEnabled={this.props.appState.organizationsEnabled} query={this.state.query} referencedProfiles={this.state.referencedProfiles} referencedRepositories={this.state.referencedRepositories} @@ -572,7 +569,7 @@ export class App extends React.PureComponent<Props, State> { <div className="layout-page-main-inner"> {this.state.openRule ? ( <RuleDetails - allowCustomRules={!this.context.organizationsEnabled} + allowCustomRules={!this.props.appState.organizationsEnabled} canWrite={this.state.canWrite} hideQualityProfiles={hideQualityProfiles} onActivate={this.handleRuleActivate} @@ -643,6 +640,7 @@ function parseFacets(rawFacets: { property: string; values: { count: number; val } const mapStateToProps = (state: Store) => ({ + appState: getAppState(state), currentUser: getCurrentUser(state), languages: getLanguages(state), userOrganizations: getMyOrganizations(state) diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsIssues.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsIssues.tsx index 8f0d290c3eb..820f62f1ec9 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsIssues.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsIssues.tsx @@ -18,7 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; -import * as PropTypes from 'prop-types'; import { Link } from 'react-router'; import DeferredSpinner from '../../../components/common/DeferredSpinner'; import Tooltip from '../../../components/controls/Tooltip'; @@ -26,8 +25,10 @@ import { getFacet } from '../../../api/issues'; import { getIssuesUrl } from '../../../helpers/urls'; import { formatMeasure } from '../../../helpers/measures'; import { translate } from '../../../helpers/l10n'; +import { withAppState } from '../../../components/withAppState'; interface Props { + appState: Pick<T.AppState, 'branchesEnabled'>; organization: string | undefined; ruleDetails: Pick<T.RuleDetails, 'key' | 'type'>; } @@ -44,13 +45,8 @@ interface State { total?: number; } -export default class RuleDetailsIssues extends React.PureComponent<Props, State> { +export class RuleDetailsIssues extends React.PureComponent<Props, State> { mounted = false; - - static contextTypes = { - branchesEnabled: PropTypes.bool - }; - state: State = { loading: true }; componentDidMount() { @@ -119,7 +115,7 @@ export default class RuleDetailsIssues extends React.PureComponent<Props, State> </span> ); - if (!this.context.branchesEnabled) { + if (!this.props.appState.branchesEnabled) { return totalItem; } @@ -173,3 +169,5 @@ export default class RuleDetailsIssues extends React.PureComponent<Props, State> ); } } + +export default withAppState(RuleDetailsIssues); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsIssues-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsIssues-test.tsx index 731cddcfeed..675e7f90d75 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsIssues-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsIssues-test.tsx @@ -19,7 +19,7 @@ */ import * as React from 'react'; import { shallow } from 'enzyme'; -import RuleDetailsIssues from '../RuleDetailsIssues'; +import { RuleDetailsIssues } from '../RuleDetailsIssues'; import { waitAndUpdate } from '../../../../helpers/testUtils'; import { getFacet } from '../../../../api/issues'; @@ -47,7 +47,11 @@ it('should handle hotspot rules', async () => { async function check(ruleType: T.RuleType, requestedTypes: T.RuleType[] | undefined) { const wrapper = shallow( - <RuleDetailsIssues organization="org" ruleDetails={{ key: 'foo', type: ruleType }} /> + <RuleDetailsIssues + appState={{ branchesEnabled: false }} + organization="org" + ruleDetails={{ key: 'foo', type: ruleType }} + /> ); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); |